HMC5883L Magnetometer
HMC5883L Magnetometer
Can someone help me get this compass working? I am using code from https://github.com/gvalkov/micropython- ... mc5883l.py
The main program is this (full module):
from hmc5883l import HMC5883L
sensor = HMC5883L(scl=4, sda=5)
x, y, z = sensor.read()
print(sensor.format_result(x, y, z))
The line from the hmc5883l driver that gives the error is this (including the line before):
Line 20: def __init__(self, scl=4, sda=5, address=30, gauss='1.3', declination=(0, 0)):
Line 21: self.i2c = i2c = machine.I2C(scl=machine.Pin(scl), sda=machine.Pin(sda), freq=100000)
There is the error:
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "hmc5883l.py", line 21, in __init__
TypeError: can't convert 'int' object to str implicitly
I don't see where an int is being converted to string. Can anyone help me? I hope I have included all relevant information. Thanks.
The main program is this (full module):
from hmc5883l import HMC5883L
sensor = HMC5883L(scl=4, sda=5)
x, y, z = sensor.read()
print(sensor.format_result(x, y, z))
The line from the hmc5883l driver that gives the error is this (including the line before):
Line 20: def __init__(self, scl=4, sda=5, address=30, gauss='1.3', declination=(0, 0)):
Line 21: self.i2c = i2c = machine.I2C(scl=machine.Pin(scl), sda=machine.Pin(sda), freq=100000)
There is the error:
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "hmc5883l.py", line 21, in __init__
TypeError: can't convert 'int' object to str implicitly
I don't see where an int is being converted to string. Can anyone help me? I hope I have included all relevant information. Thanks.
Re: HMC5883L Magnetometer
Which hardware module and which firmware version are you using?
Edit: I just loaded your script to an ESP8266. It does not raise the error you post. But since the sensor is not attached, it fails at Line 24.
Firmware/Module version: MicroPython v1.10-315-ge70c438c7-dirty on 2019-05-01; ESP module with ESP8266
Edit 2: When using a PyBoard, the Pin names are different, like "Y9" and "Y10" or "X9" and "X10".
Edit: I just loaded your script to an ESP8266. It does not raise the error you post. But since the sensor is not attached, it fails at Line 24.
Firmware/Module version: MicroPython v1.10-315-ge70c438c7-dirty on 2019-05-01; ESP module with ESP8266
Edit 2: When using a PyBoard, the Pin names are different, like "Y9" and "Y10" or "X9" and "X10".
Re: HMC5883L Magnetometer
It's a pyboard 1.1. The sensor is just marked hmc5883L.Roberthh wrote: ↑Fri May 03, 2019 5:45 amWhich hardware module and which firmware version are you using?
Edit: I just loaded your script to an ESP8266. It does not raise the error you post. But since the sensor is not attached, it fails at Line 24.
Firmware/Module version: MicroPython v1.10-315-ge70c438c7-dirty on 2019-05-01; ESP module with ESP8266
Edit 2: When using a PyBoard, the Pin names are different, like "Y9" and "Y10" or "X9" and "X10".
Re: HMC5883L Magnetometer
Ok. Thanks. It was a) the pins needed to be set as Y9 and Y10, and b) the address of the sensor is 13 and not 30 as most of the documentation says.
HOWEVER: the program is now only returning values X: 0.0000, Y: 0.0000, Z: 0.0000, Heading: 0° 0′
Any idea why?
HOWEVER: the program is now only returning values X: 0.0000, Y: 0.0000, Z: 0.0000, Heading: 0° 0′
Any idea why?
Re: HMC5883L Magnetometer
I have a board here, and it contained a QMC5883 with address 13, instead of a HMC5883 at address 30. Maybe that's what happens in your case too.
What confused me with my board was, that is was connected to a MPU6050 as slave device, and I had to enable that slave port first. But until then, it was not visible on the i2c bus.
What confused me with my board was, that is was connected to a MPU6050 as slave device, and I had to enable that slave port first. But until then, it was not visible on the i2c bus.
Re: HMC5883L Magnetometer
I read that the HMC code does not work with the Chinese clone QMC code. I will look for code for QMC.
Re: HMC5883L Magnetometer
If your sensor acknowledges the I2C transaction but still returns all zeros for the data, it's also possible that the sensor is damaged.
Especially with cheap modules from "no-name" sources, you can sometimes get parts from a bad batch. I've received accelerometer/gyroscope sensors which were able to communicate and read/write to their status registers, but their output registers always returned 0s. I guess it's possible that they were counterfeit rather than damaged given the provenance, but it seems more likely that they came from lots that didn't pass QA or something like that. When I tried a more expensive board from a more reputable vendor, the same code ended up working.
So if you aren't sure about where the parts came from, you might try checking whether your sensor returns valid readings if you use a different platform such as an Arduino example sketch. Or you could see if your MicroPython code works with an HMC5883L sensor from a different vendor.
Especially with cheap modules from "no-name" sources, you can sometimes get parts from a bad batch. I've received accelerometer/gyroscope sensors which were able to communicate and read/write to their status registers, but their output registers always returned 0s. I guess it's possible that they were counterfeit rather than damaged given the provenance, but it seems more likely that they came from lots that didn't pass QA or something like that. When I tried a more expensive board from a more reputable vendor, the same code ended up working.
So if you aren't sure about where the parts came from, you might try checking whether your sensor returns valid readings if you use a different platform such as an Arduino example sketch. Or you could see if your MicroPython code works with an HMC5883L sensor from a different vendor.
Remember, the "S" in "IoT" stands for "Security".
-
- Posts: 2
- Joined: Sun Oct 20, 2019 10:39 am
Re: HMC5883L Magnetometer
Hi There.
Im quite new to MicroPython but got it running on a ESP8266 D1 board. When I load the script in this thread I get a strange error
>>> sensor = HMC5883L(scl=4, sda=5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "hmc5883l.py", line 30, in __init__
OSError: [Errno 19] ENODEV
What is wrong here:-)?
Im quite new to MicroPython but got it running on a ESP8266 D1 board. When I load the script in this thread I get a strange error
>>> sensor = HMC5883L(scl=4, sda=5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "hmc5883l.py", line 30, in __init__
OSError: [Errno 19] ENODEV
What is wrong here:-)?
Re: HMC5883L Magnetometer
The code does not find the sensor. Maybe it is a problem with labeling. According to you code, you connect to GPIO4 and 5. On the Wemos D1 device these are Pins D2 (GPIO4) and D1 (GPIO5). Maybe you device has a different labeling. so please check.
-
- Posts: 2
- Joined: Sun Oct 20, 2019 10:39 am
Re: HMC5883L Magnetometer
Thanks for your reply. I found the issue. In the __init__ I2C speed was set for 10000 pbs so reducing it to 1000 it solved the problem:-)
Thanks for your support and reply
Thanks for your support and reply