Magnetometer QMC5883L problem

Status
Not open for further replies.

TelephoneBill

Well-known member
I bought a couple of magnetometer boards from eBay recently and today attempted to get them working with a Teensy 3.1. These came from China and claimed to be HMC5883L. They also have a marking "GY-273". Though not the supplier I used, here is a typical eBay advert (https://www.ebay.co.uk/itm/GY-273-H...032112?hash=item43fa699470:g:A8AAAOSw409ZyMuQ).

When some sample magnetometer code from the forum was tried, they failed to respond to I2C address = "0x1E". Some web research suggested they may be using an alternative chip called QMC5883L (https://github.com/e-Gizmo/QMC5883L-GY-271-Compass-module/blob/master/QMC5883L Datasheet 1.0 .pdf), and sure enough both boards would respond to I2C address "0x0D" (which the QMC5883L datasheet quoted). Apparently they are made under licence from Honeywell - so the data sheet claims. Note the eBay advert has markings "DA 5883 6014", which also accords with the QMC5883L data sheet. My boards have this marking style of "DB 5883 7006".

Despite many attempts all afternoon, I just could not get any sensible values to print for x,y,z. I did get some values, but they did not change correctly with board orientation.

(Question 1) Has anyone been able to get reasonable magnetometer data out of this type of board?

I also noted that when reading the data registers, they have different internal register numbering to the Honeywell HMC5883L datasheet. These QMC5883 chips start at Register "0x00" through to "0x05", which is different to the Honeywell (which starts at register address "0x03"). Also, the teensy code example reads x then z then y, but this data sheet goes x then y then z.

(Question 2) To write and read the registers, the data sheet suggests that the I2C 7 bit address is shifted one bit to the left and then the least sig bit is then set either "0" for write and "1" for read. Does the "Wire.h" automatically adjust the signal output on I2C to cater for this read/write method of addressing? (I am not that familiar with I2C protocol). Or does the user have to change the code address from "0x1A" to "0x1B" ("0x0D" shifted left with lsb 0 or 1)?

It may well be that these chips are failed devices and that is why they are not responding. But the I2C signals on the data line look sensible, so my 5K pullup resistors are working well. The Vcc I am using is from the 3v3 supply on a T3.1 board.
 
After further reading a bit of the I2C protocol, the answer to Question 2 is that this is part of the basic operation. Seven bits of address are followed by an 8th bit as "0"/"1" for write/read operations. I should have realised this - the device would not have responded to "0x0D" otherwise.
 
Some more info and progress...

I wired these magnetometer boards to Teensy 3.1 via one metre length of ribbon cable with the pullups at the Teensy end. The purpose of the ribbon cable was to remove any extraneous ferrous metal from being adjacent to the sensor (which might interfere with the earth's field being measured). Even the 5 pin header connector supplied with the board is semi-magnetic and will distort the field. Such is the sensitivity of these devices.

Looking at the SDA data line, I noticed a few glitches. So I changed the pullup values to 2K in order to counter the cable inter-capacitance. This has had a profound effect. The values read from the registers are now looking more sensible. Further tests are needed to check the values but it looks like good progress from boards that I thought were faulty.

(Question 3) Can anyone suggest what may be the maximum practical length of ribbon cable for an I2C connection between devices? With the smaller pullup values, it appears that the integrity of data being received has markedly improved.

With the QMC5883L chip, seven registers need to be read. Six are the two bytes per axis with the seventh being the data status register (containing DRDY = data ready). Also, the write command needs to address the "0x00" register before reading seven bytes. The read address will autoincrement as each "register read" is performed.
 
Status
Not open for further replies.
Back
Top