Skip to content

Add a compass example #2

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

Closed
siddacious opened this issue Oct 24, 2019 · 7 comments
Closed

Add a compass example #2

siddacious opened this issue Oct 24, 2019 · 7 comments

Comments

@siddacious
Copy link
Contributor

This PR in an older lib had the good idea to add a compass example:
https://github.com/adafruit/Adafruit_Python_LSM303/pull/4/files

We should add similar code to this lib

@siddacious siddacious added the Hacktoberfest Beginner friendly issues for Hacktoberfest event label Oct 24, 2019
@adafruit-adabot adafruit-adabot removed the Hacktoberfest Beginner friendly issues for Hacktoberfest event label Nov 2, 2019
@FoamyGuy
Copy link
Contributor

I've got an order that includes these sensors on the way to me now. Once they arrive I will work on bringing these examples into the new libraries

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Feb 2, 2020

I've started an example script for this here: https://github.com/FoamyGuy/CircuitPython_Compass_Example/blob/master/code.py I've tried it with LIS3MDL and LSMDLH and I do get varying 0-360 heading values depending on how I hold and point the sensor. However I'm not certain exactly how to use it to match up the heading values with cardinal directions.

@ladyada
Copy link
Member

ladyada commented Feb 2, 2020

find north - try pointing the X arrow on the board to north, then Y and then Z, you should see a spike in the numbers

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Feb 2, 2020

Thank you! I was able to get both sensors coordinating pretty closely to a compass app on a phone. Starting with the X arrow pointing north I adjusted slightly the tilt until it matched 0 heading, then I could hold the sensor steady and rotate and see headings in the same range as the ones reported by the phone.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Feb 5, 2020

Looking over this again today I notice a slight difference that I am curious about. In the old PR code we have this inside of the get_heading() function:

magnet_axis_data = self.lsm303_sensor.read_magnetometer()
return self.vector_2_degrees(magnet_axis_data[0], magnet_axis_data[2])

It seems like this would be using x and z values from the magnetometer. Whereas in the arduino code from here we have it like this:

float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;

Using x and y values from the magnetometer.

Do I understand it correctly that either of these would work, the difference would be that you need to hold the sensor in a different position (on a different axis?) when you get your compass heading readings?

If so is there any preference for which is used for the new example code?

@ladyada
Copy link
Member

ladyada commented Feb 5, 2020

x and y are the most common

@kattni
Copy link
Contributor

kattni commented Apr 30, 2020

This was completed.

@kattni kattni closed this as completed Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants