element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sensors
  • Technologies
  • More
Sensors
Sensor Forum Help with 5883L crazyness.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Sensors to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 16 replies
  • Answers 1 answer
  • Subscribers 342 subscribers
  • Views 3877 views
  • Users 0 members are here
  • 5883l
Related

Help with 5883L crazyness.

screamingtiger
screamingtiger over 10 years ago

shabaz

jw0752

 

I have collected data and cannot get it to point to the correct heading.  Its off quite a bit and I cannot adjust as the amount it is off is non-linear.  For example, at 0 degrees it shows 100 degrees.  But at 45 degrees it shows 170 degrees.  Z axis is level and remain constant for the most part.

 


Here is the data I collected, does it makes sense?  I used a compass on my phone and compared to the readings I am getting.

 

 

 

0 degrees North
X 0
Y 155
Z -530

 

Calculated heading: 100

 

 

90 degrees east

 

X -165
Y 100 (shouldn't this read 0 since it is pointing in same direction X was just at?)
Z -530
Calculated Heading: 224

 


180 degress South
X: 0
Y: -290
Z: -540

 

Calculating Heading: 286

 

 

 

270 degrees West

 

X: 250
Y: -100
Z: -550
Calculated Heading: 252

 


One thing I am thinking is odd, if at 0 degrees north X axis reads 0, if I rotate 90 degrees to right, would Y axis now read 0?

 

I am not sure what the axis is measuring, I thought it was force and it I point x axis in one direction, then Y axis in same direction, they would show the same reading...

 

X and Y are 90 degrees in parallel plane.
I ordered another magnometer hoping a different brand will help.  Its still 5883L but different maker of breakout.

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 10 years ago in reply to screamingtiger +2
    Hi Joey, I took your code and added ALG_TEST stuff to it and modifying the declinationAngle variable: //#include "heading.h" #include <stdio.h> #include <iostream> //#include <wiringPi.h> //#include…
  • jw0752
    jw0752 over 10 years ago +1
    Hi Joey, This may be off base but if I treat your X and Y data as vectors and calculate Result = Sqrt( X^2 + Y^2) I get a Result that is at least in the ball park for the headings that you listed. Like…
  • jw0752
    jw0752 over 10 years ago +1
    Ok now you can see I really don't grasp it quickly as that is exactly what you were doing. No wonder my calculations matched yours. I will put my thinking cap back on and let you know if something better…
Parents
  • shabaz
    0 shabaz over 10 years ago

    Hi Joey,

     

    This is how I'd try to troubleshoot this - unfortunately I've not used this sensor before, but there is a typical process I would use for sensors:

    Basically, try to find known values (e.g. a worked example in the datasheet), and then plug those values into your code so that the data from the sensor

    is overwritten with your known values, so you can see if the rest of the coded algorithm behaves as expected. I do it something like this:

     

    #define ALG_TEST 0
    ... code...
    i2c_read(buf); // read into buffer the actual sensor data
    if (ALG_TEST)
      {
       buf[0]=0x11;
        buf[2]=0x22;
        buf[3]=0x33;
      }
    ... data processing ..
    ... remainder of your code ..

     

    Basically at any point during your code development you can set ALG_TEST to 1 to quickly confirm the algorithm is not broken, and set it back to 0 to go back to normal operation.

     

    The problem is finding some known values and the correct computed value. To do this, perhaps use this arduino compass web page which (about half-way down)

    has a screenshot of captured raw values, and the computed results. You could plug the raw values into your code, and check if the result matches.

    Another way I frequently use is to come up with some raw values and the expected result by checking if the datasheet has a worked example (in your case unfortunately

    the datasheet doesn't have this) or by inventing some sensor values, and writing some formula to generate the output, using (say) Excel.

    Then, at any point during testing, I can plug the raw sensor values into the spreadsheet and see what value I expect. This really helps to confirm the coded algorithm is

    working well. I do this a lot with virtually any IC. For example, here is my 555 spreadsheet:

    image

    I can plug in values into the green cells, and the red cells show the expected output for the 555. I'd suggest a similar thing

    with the IC you're using. It takes a while to create, but worth it in the long run.

    Also, with the two modules you have, do they both give similar values that match each other?

    How are they connected to the RPI - short(ish) wires? What resistors are you using for pull-ups for the I2C -

    are these already on the board, or external? Could you attach a photo of the set-up if possible?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • shabaz
    0 shabaz over 10 years ago

    Hi Joey,

     

    This is how I'd try to troubleshoot this - unfortunately I've not used this sensor before, but there is a typical process I would use for sensors:

    Basically, try to find known values (e.g. a worked example in the datasheet), and then plug those values into your code so that the data from the sensor

    is overwritten with your known values, so you can see if the rest of the coded algorithm behaves as expected. I do it something like this:

     

    #define ALG_TEST 0
    ... code...
    i2c_read(buf); // read into buffer the actual sensor data
    if (ALG_TEST)
      {
       buf[0]=0x11;
        buf[2]=0x22;
        buf[3]=0x33;
      }
    ... data processing ..
    ... remainder of your code ..

     

    Basically at any point during your code development you can set ALG_TEST to 1 to quickly confirm the algorithm is not broken, and set it back to 0 to go back to normal operation.

     

    The problem is finding some known values and the correct computed value. To do this, perhaps use this arduino compass web page which (about half-way down)

    has a screenshot of captured raw values, and the computed results. You could plug the raw values into your code, and check if the result matches.

    Another way I frequently use is to come up with some raw values and the expected result by checking if the datasheet has a worked example (in your case unfortunately

    the datasheet doesn't have this) or by inventing some sensor values, and writing some formula to generate the output, using (say) Excel.

    Then, at any point during testing, I can plug the raw sensor values into the spreadsheet and see what value I expect. This really helps to confirm the coded algorithm is

    working well. I do this a lot with virtually any IC. For example, here is my 555 spreadsheet:

    image

    I can plug in values into the green cells, and the red cells show the expected output for the 555. I'd suggest a similar thing

    with the IC you're using. It takes a while to create, but worth it in the long run.

    Also, with the two modules you have, do they both give similar values that match each other?

    How are they connected to the RPI - short(ish) wires? What resistors are you using for pull-ups for the I2C -

    are these already on the board, or external? Could you attach a photo of the set-up if possible?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube