HMC5883L(GY-271) driver for 3-Axis Digital Compass IC
-
Hi,
if someone is interested i have created driver for HMC5883L 3-Axis Digital Compass.
https://github.com/pycom/pycom-libraries/pull/8/fileswithout compensation, self test and calibration but good point to start.
Strongly optimized form memory allocation point of view in every m.readAxes()UPDATE
HMC5883L is in GY-271 module.
Use caseimport HMC5883L import gc import time m = HMC5883L.HMC5883L() while True: m.readAxes() m.heading() print(m) time.sleep_ms(1000) gc.collect()sample output from above
X: 391.0, Y: -341.32, Z: 73.6 - Heading: 318.8809, Declination: (0, 0) X: 390.08, Y: -339.48, Z: 77.28 - Heading: 318.9675, Declination: (0, 0)but better (from memory point of view) is replace
print(m)
byprint(m.x,m.y,m.z,m.h,m.headingDeg)and if you do not need m.heading() - you can simply do not call it
-
@livius said in HMC5883L(GY-271) driver for 3-Axis Digital Compass IC:
HMC5883L is in GY-271 module.
Where can I find this module please? Thank you.
-
-
@livius Thanks a lot Livius.
Spotted a slight error in the example:
m = HMC5883L2.HMC5883L()should bem = HMC5883L.HMC5883L() -
@RobTuDelft
i must look into it - what i have on board
i remember that file with 2 was from testing time
Thanks for pointing this -
Works here, on LoPy and pycom expansion board, can read data.
I'm using this module: http://hobby-elektronik.ch/Module-Sensoren/Bewegung-Distanz/3-Achsen-Kompass-GY-271-HMC5883L-Magnetometer-Sensor-I2C::127.htmlNow to figure out whoch way to mount the module to get usabel heading values...
thanks allot
-
@RobTuDelft said in HMC5883L(GY-271) driver for 3-Axis Digital Compass IC:
HMC5883L2
I have tried the code with this device and I get the following error
OSError: I2C bus error
Do I need to connect the DRDY pin to the LoPy and can anyone confirm which pin numbers on the breakout board the SCL and SDA pins are on, there is nothing in documentation to explain this.
Thanks
-
@simonjcarr
How do you init it? Do you use defaultm = HMC5883L.HMC5883L()
or you pass some parameters?
Without parameters `HMC5883L()'
it default use this i2c initI2C(0, I2C.MASTER, baudrate=100000)you can change this by e.g.
bus = I2C(0, I2C.MASTER, baudrate=100000, pins=(SDA, SCL))e.g. if you connect i2c to pins SDA=P9, and SCL=P10
simply dobus = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9', 'P10')) m = HMC5883L.HMC5883L(bus)and check address of you sensor
default issensor_address=30if you have different address e.g. 50 change it in the init
bus = I2C(0, I2C.MASTER, baudrate=100000, pins=('P9', 'P10')) m = HMC5883L.HMC5883L(busI2C=bus,sensor_address=50) -
The libary works fine (except for missing check in heading() for x and y to not be None) but the sensor is not useable.
You can not trust the results - is is more like gambling and extremly depending on your surrounding. Dont buy it, if you need reliable data!
-
@leo_sol I think this Module only works properly with calibration, and the library lacks some calibration functionality so i agree with you in the current situation the module is useless.
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login