The C example for the dCompass on the BrickPi seems to output random data. I can’t find values that correlate to degrees from magnetic north. What do the X, Y, Z, and H in the output represent?
The Python code gave me the same results. I can get a number close to 1 in the north direction, but any move to the right changes the H output to around 280.
So I’ve read through the data sheet and done some research to figure out that Z is the horizontal angle and how to calculate heading from X and Y, but I just can’t get good output. X and Y max out at 255 and I’ve tried different calculations but there are always holes in the heading output. I can’t get anything that resembles an accurate and stable heading. Maybe my unit is defective. I guess it’s going back.
I’m really sorry for the slow response. Clearly 20 days is way too long to respond to this. We saw the same issues as well: it would jump from 0 to 300 or so.
We’ve just updated the python code so that the compass works. Python is kind of hard for low level stuff, and it was having trouble with the two bytes coming back. We think we figured it out though, can you give it a look?
I will try to rework the C examples now as well.
And now C should be up and running here: https://github.com/DexterInd/BrickPi_C/blob/master/Sensor%20Examples/DEXTER%20INDUSTRIES%20-%20dCompass%20test.c
Same sort of problem I think. There was a math error that took a bit of fiddling to get corrected. Thanks for your patience!