# Timeline for Why does my LSM303 magnetometer reading not change in a while loop?

### Current License: CC BY-SA 3.0

14 events
when toggle format what by license comment
Jul 1 '13 at 12:37 comment You CAN (and are actually encouraged) to post your own answer. You can also accept it. See blog.stackoverflow.com/2009/01/accept-your-own-answers
Jun 27 '13 at 2:24 comment You could always debug this in 2 parts: First, write the compass.heading value directly to the serial port and verify that it changes. Second, set the value of mag based on a timer: desired heading for 1 second, 90 degrees offset for the following second, then repeat. The first test will validate the compass, the second test will validate that the compiler is handling variables in the way that you expect.
Jun 26 '13 at 22:20 answer timeline score: 1
Jun 5 '13 at 18:57 history migrated
May 31 '13 at 22:38 comment Post your solution, it may help other people.
May 31 '13 at 0:35 comment mark mcmurray Yes, can I mark this as solved? or close it? There is no answer for me to mark as correct
May 28 '13 at 20:17 comment Did you solve your problem?
May 3 '13 at 0:17 comment mark mcmurray Angle is the desired angle and mag is the actual angle yes. And I must look into if it perhaps needs a delay that may be the problem. thanks.
May 3 '13 at 0:16 comment mark mcmurray "I am confused here, if mag changes when robot turns, it should change inside the while loop since the robot is rotating constantly?" That's what I thought, I doubted myself and thought perhaps I really didn't understand the fundamentals of while loops as much as I thought.
May 2 '13 at 22:54 comment Another thought... Do you need some time delay between readings? I am not familiar with your compass, but the documentation should indicate any constraints that you need to pay attention to.
May 2 '13 at 22:48 comment I am confused here, if mag changes when robot turns, it should change inside the while loop since the robot is rotating constantly? question: is angle the desired angle and mag the actual angle? Have you had a print inside the while loop?
May 2 '13 at 21:43 comment mark mcmurray Yes - sorry probably should have mentioned, if I run mag = compass.heading((LSM303::vector){0,-1,0});; by itself and then move the compass and run it again it performs correctly and the heading changes as expected.
May 2 '13 at 19:01 comment if mag is not changing, then compass.heading(...) should be investigated to see if your i2c implementation is correct. Did you test the compass for working condition at any time?
May 2 '13 at 16:37 history asked mark mcmurray