-
Notifications
You must be signed in to change notification settings - Fork 5
adding compass example #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job using atan2() to get a heading over 360 degrees! I checked and assuming +X means east and +Y means north, the outputs would seem to match expectations. I don't have hardware to test with, though, so too cowardly to merge.
@siddacious ok wanna test? |
@FoamyGuy the numbers I got seem off, but for all I know I forgot about a huge magnet somewhere; these four chunks are rotated 90 degrees clockwise from each preceding set: tested with a LSM303AGR which includes a lis2mdl
|
@siddacious If you have a moment, and any of these other magnetometers I'd be interested to know if you get similar results from these ones in the same environment:
These are using the same formula, if it turns out that there is an issue with it then likely affecting these other examples as well. These ones I was able to test and I was getting results that were close to the readings from a compass app on an Android phone. I started these examples using the code from the old PR that is referenced in issue #2. During the process I did come across this Making Tracks Project within the LSM303 learn guide. This has arduino code instead of CircuitPython, but it does seem to be implementing the same formula as far as I understand it:
|
this example wont work in real world because the magnetometer must be calibrated. here are the calibration and normalized output sketches :) |
@FoamyGuy Limor posted calibration programs - consider implementing them for your example. |
@kattni I've made some new commits add the calibration script and use it in the compass example. I will work on updating the LSM303DLH, and LIS3MDL examples to match this as well. |
@siddacious When you get a chance, can you take another look please? Thanks! |
@FoamyGuy Works great! My only request is that you include some basic instructions in the compass example about how to use the calibration example to measure and use the hardiron offsets. |
I've added a new commit with instructions on how to run the calibrate script and copy in the values to the compass script. Thank you. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_AM2320 to 1.2.2 from 1.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_AM2320#16 from jerryneedell/jerryn_revert_pr_9 Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS2MDL to 2.1.3 from 2.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_LIS2MDL#5 from FoamyGuy/master Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 2.1.3 from 2.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#14 from adafruit/rads_fix > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#13 from adafruit/pylint-update Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 6.1.3 from 6.1.2: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#80 from dhalbert/initial-value-none
This adds the compass example referenced by issue #2. The sensor I have is actually a LIS3MDL, so I was unable to test this example specifically with the LIS2MDL. Both sensors (and some others) use the same
.magnetic
property to access the data so the example can be used by any of those sensors by using the appropriate import and sensor initialization. I believe this one should be working for the LIS2MDL.