Page 2 of 2

Re: Problem getting HMC5883L to work

Posted: Sat Mar 21, 2020 6:07 pm
by laukejas
Hey, Roberth, sorry to bother you again, but I still get some problems running that code for QMC5883 that you wrote. The device worked fine for a few days, and now suddenly it freezes on function read_raw. For example, if I run it via the normal way, calling

Code: Select all

x, y, z, temp = qmc5883.read_scaled()
then the console freezes, and if I abort with ctrl+c, it prints:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "QMC5883.py", line 156, in read_scaled
  File "QMC5883.py", line 144, in read_raw
KeyboardInterrupt: 
I haven't touched the hardware since when this setup worked. Neither changed anything in the code. i2c.scan() still recognizes the device properly. Do you have any ideas what could be causing this?

EDIT: I assume the hanging happens when the read_raw() calls ready(). So when I called print(qmc5883.ready()), and it prints 0. I'm not exactly sure what that means.

EDIT 2: I added 4.7K resistors to SDA and SCL pins, and one one boot I got the ENODEV error again. Unpluged USB, plugged it back again, opened serial, ran the code - no ENODEV this time, but the code hangs again on the read_raw() function. It all feels so very random, but I can't point my finger at it. Even when I make absolutely no changes to hardware, and repeat exact same steps, I sometimes get random results - sometimes it works, sometimes it hangs, sometimes it's the ENODEV error... How do I debug such a thing?

Re: Problem getting HMC5883L to work

Posted: Sat Mar 21, 2020 7:51 pm
by Roberthh
qmc5883.ready() returning 0 means, that not data is available for reading. Are you sure that you did not change anything?
What is the result of calling:

qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 6)

or

qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 14)

Re: Problem getting HMC5883L to work

Posted: Sat Mar 21, 2020 8:00 pm
by laukejas
Calling qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 6) returns:

Code: Select all

b'\x00\x00\x00\x00\x00\x00'
And calling qmc5883.i2c.readfrom_mem(QMC5883.ADDR, QMC5883.X_LSB, 14) returns:

Code: Select all

b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Please also see my edits in the previous reply... Something really weird is going on here.

Re: Problem getting HMC5883L to work

Posted: Sat Mar 21, 2020 9:11 pm
by Roberthh
Replace the wires to your breakout board. If that does not help, the chip may be broken.

Re: Problem getting HMC5883L to work

Posted: Sat Mar 21, 2020 9:23 pm
by laukejas
Replaced them... I had cheap Chinese jumpers there, now I replaced with proper quality wires. But I'm still getting random things happening. I did three attempts to read. First attempt: ENODEV error. Second read: command hung up and had to be aborted. Third attempt: reading was successful, but x, y and z are all zero.

If the chip was broken, shouldn't the errors be consistent? And how can it be broken when it worked fine just a few days ago? I power it from 3.3V rail from my NodeMCU. Never had any higher voltage anywhere near it. Perhaps it needs some decoupling capacitors or something? I mean, I now have three qmc5883 chips, one of them says ETIMEDOUT all the time, second one says ENODEV all the time, and third one is totally random. This can't be a coincidence...

Re: Problem getting HMC5883L to work

Posted: Mon Oct 10, 2022 12:50 pm
by masckalajos
Hello Forumers,
It is something wrong. With me?
In mentioned above code, you use 16-bit to display negative values of B. So, You can count the magnetic field from on 2 power 15(-32768 -- +32768), but our HC5883l has a 12-bit AD comparator, so it can generate values from on 2 power 15 (-2048-- +2047).
I want to change 'gain' according to the value of the magnetic field. To achieve it, I want to take read out 'x','y','z' ,in limits (-2048-- +2047). Is it a good way?
Thank for advice!