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
-
@leo_sol
It depend on environment. For me it is quite precise.
But as @roadfox say and i in first post introduction about optimized library
that library is without calibration part and good as first steep.It is optimized for memory allocation but do not support full sensor features yet
-
@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.
-
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!
-
@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=30
if 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)
-
@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
-
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
i must look into it - what i have on board
i remember that file with 2 was from testing time
Thanks for pointing this
-
@livius Thanks a lot Livius.
Spotted a slight error in the example:
m = HMC5883L2.HMC5883L()
should bem = HMC5883L.HMC5883L()
-
-
@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.