jamiej1989
Posts: 1
Joined: Sat Jan 21, 2017 3:33 pm

wrong i2c address

Sat Jan 21, 2017 4:01 pm

I have a 3-Axis Digital Compass IC HMC5883L I2C chip, I just want to use it to learn how to talk to sensors via a Matlab to raspberry-pie to I2C chip link. The set up from Matlab to the pi is straight forward and simple, the issue I'm having seems to be the address I'm being returned when scanning the I2C bus line, I get an address of '0x0D' instead of the data sheets default of '0x1E'. There are two lines of code, the creation of the pi object 'rpi', and the function to scan the bus line is simply

Code: Select all

rpi = raspi() 
scanI2CBus(rpi, 'i2c-1' ) 
the argument 'i2c-1' tells the pi which bus line to scan, it is the only bus line available. Connections to the device are simple and have been checked and double checked, so I'm straight ruling that out. There is a built in matlab class for using this device with a pi, when I change the address it uses in this class to '0x0D' it clearly talks to the device but returns the error,
Error using hmc5883l/testDevice (line 246) Error communicating with the HMC5883L sensor. The value read from ID_A, ID_B and ID_C registers do not match expected values.
If I use the default address '0x1E' I get an error informing me that there is know device on the bus with that address.

If I call the raspberry pi object it tells me that the bus rate is 0

Code: Select all

rpi = 

  raspi with properties:

         DeviceAddress: 192.168.0.31                  
                  Port: 18732                         
             BoardName: Raspberry Pi 3 Model B        
         AvailableLEDs: {'led0'}                      
  AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
  AvailableSPIChannels: {'CE0','CE1'}                 
     AvailableI2CBuses: {'i2c-1'}                     
      AvailableWebcams: {}                            
           I2CBusSpeed: 0 
Ive also tried scanning the bus line with the pi's terminal using

Code: Select all

sudo i2cdetect -y 1
Which also returns '0x0D' as the address of the device. I have purchased a new sensor and the same address is still returned so it's not a faulty device. Any ideas?

Modulemaker
Posts: 1
Joined: Sat Feb 18, 2017 9:53 am

Re: wrong i2c address

Sat Feb 18, 2017 11:02 am

Hi jamiej1989,

recently (dez. 2016) I also bought a breakout board "TOOGOO (R) GY-273 HMC5883L 3-Achsen Magnet Elektronischer Kompass 3-5V - Blau" from Sonline-HK.

I had the same problem, that the IC shows up the adress 0x0d when scanning the I2C bus.

I read the printing on the IC with a magnifier.
On the IC should be printed "L883 2230" for the HMC5883L IC.
But it is printed DA 5883 6012.

I have 4 of this break out borads. I tested them on two different Pi's and on both I2C controller of the Pi's.
They always show up on the I2C bus with the adress 0x0d.

So, I am sure the manufacturer put the wrong IC on the breakout board.

May be you have the same problem. I contacted the vendor for refunding of the breakout board. I got a rufunding.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: wrong i2c address

Thu May 18, 2017 12:12 pm

Yes I just got taken in with a fake HMC5883 board from eBay. On the fake board the chip is marked DA 5883 xxx those last four digits look like a manufacturing date code because mine said 5012.

There is a thread in German discussing this:-
http://www.forum-raspberrypi.de/Thread- ... scher-chip
Google translate confirms the discussion matches what has been said here.
This thread also gives more details but is essentially the same information, this is fake.
https://www.mikrocontroller.net/topic/417537
All the photographs of the sellers show the chip marking as L883 so the best bet is to ask the seller before you buy what is the number on the chip.

dpouw
Posts: 1
Joined: Thu May 18, 2017 7:27 pm

Re: wrong i2c address

Thu May 18, 2017 7:31 pm

I've just bought of few of these and found the '5883' IC is a QMC5883 which has different registers. The datasheet is here:
https://github.com/luckypm/commn-inform ... 1.0%20.pdf

Working Arduino code is here:
https://github.com/mechasolution/Mecha_QMC5883

JamesGeddes
Posts: 23
Joined: Fri Oct 31, 2014 12:45 am

Re: wrong i2c address

Thu May 25, 2017 7:39 pm

I have been discussing a similar question about a device I purchased on Amazon that claims to be a "GY-271 HMC5883L" but is being detected on 0d. The only output I could get from it was 0, so I thought I had bricked it and purchased another to check, but the new one has the same results.

Any ideas on if it is possible to get this potentially fake device to give me something more useful than 0? If so, how?

Thanks!

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: wrong i2c address

Thu May 25, 2017 8:24 pm

Any ideas on if it is possible to get this potentially fake device to give me something more useful than 0? If so, how?
I would go with the links posted by @dpouw
I have not had time to try it but I have downloaded the data sheet it looks like it might be the answer. The data sheet shows that it is very like the real thing but the registers are in different locations. Also the 16 bit readings are sent LSB first or little endian where as the real thing is big endian. It should be a simple enough matter to change these things around in code.

However if it is advertised as a GY-271 HMC5883L and it is not, even though it might do the same thing, then this is a false description and offense under the "Trade descriptions act" at least you should get your money back. Tell Amazon that.

kumardas
Posts: 1
Joined: Mon Aug 21, 2017 8:23 pm

Re: wrong i2c address

Mon Sep 04, 2017 2:07 pm

hey guys,

The compass with wrong I2C address are not a fake one. I solved the problem for this, its only the differences in address of resistors.
I got the response from arduino uno but the accuracy in result is not very impressive.


Anyway : fined the code for the GY-271 HMC5883L in arduino and the raspberry pi respectively.

arduino code:

#include <Wire.h> //I2C Arduino Library

#define addr 0x0D //I2C Address for The HMC5883

void setup(){

Serial.begin(9600);
Wire.begin();


Wire.beginTransmission(addr); //start talking
Wire.write(0x09); // Set the Register
Wire.write(0x1D); // Tell the HMC5883 to Continuously Measure
Wire.endTransmission();
}


void loop(){

int x,y,z; //triple axis data

//Tell the HMC what regist to begin writing data into
Wire.beginTransmission(addr);
Wire.write(0x00); //start with register 3.
Wire.endTransmission();


//Read the data.. 2 bytes for each axis.. 6 total bytes
Wire.requestFrom(addr, 6);
if(6<=Wire.available()){
x = Wire.read()<<8; //MSB x
x |= Wire.read(); //LSB x
z = Wire.read()<<8; //MSB z
z |= Wire.read(); //LSB z
y = Wire.read()<<8; //MSB y
y |= Wire.read(); //LSB y
}

// Show Values
Serial.print("X Value: ");
Serial.println(x);
Serial.print("Y Value: ");
Serial.println(y);
Serial.print("Z Value: ");
Serial.println(z);
Serial.println();

delay(500);
}

Raspberry pi code:

import smbus
import time
import math
bus = smbus.SMBus(1)
address = 0x0d

for i in range(0,50):
def read_byte(adr): #communicate with compass
return bus.read_byte_data(address, adr)

def read_word(adr):
high = bus.read_byte_data(address, adr)
low = bus.read_byte_data(address, adr+1)
val = (high<< 8) + low
return val

def read_word_2c(adr):
val = read_word(adr)
if (val>= 0x8000):
return -((65535 - val)+1)
else:
return val

def write_byte(adr,value):
bus.write_byte_data(address, adr, value)
write_byte(11, 0b01110000)
write_byte(10, 0b00100000)
write_byte(9, 0b00011101)
scale = 0.92
x_offset = -10
y_offset = 10
x_out = (read_word_2c(0)- x_offset+2) * scale #calculating x,y,z coordinates
y_out = (read_word_2c(2)- y_offset+2)* scale
z_out = read_word_2c(4) * scale
bearing = math.atan2(y_out, x_out)+.48 #0.48 is correction value
if(bearing < 0):
bearing += 2* math.pi
print "Bearing:", math.degrees(bearing)
print "x: ", x_out
print "y: ", y_out
print "z: ", z_out
time.sleep(3)

Please check the code with your digital compass and fill free to ask the question.

SamuelVergeiner
Posts: 2
Joined: Thu Feb 08, 2018 4:17 pm

Re: wrong i2c address

Thu Feb 08, 2018 4:19 pm

kumardas wrote:
Mon Sep 04, 2017 2:07 pm
hey guys,

The compass with wrong I2C address are not a fake one. I solved the problem for this, its only the differences in address of resistors.
I got the response from arduino uno but the accuracy in result is not very impressive.


Anyway : fined the code for the GY-271 HMC5883L in arduino and the raspberry pi respectively.

arduino code:

Code: Select all

#include <Wire.h> //I2C Arduino Library

#define addr 0x0D //I2C Address for The HMC5883

void setup(){
  
  Serial.begin(9600);
  Wire.begin();
  
  
  Wire.beginTransmission(addr); //start talking
  Wire.write(0x09); // Set the Register
  Wire.write(0x1D); // Tell the HMC5883 to Continuously Measure
  Wire.endTransmission();
}


void loop(){
  
  int x,y,z; //triple axis data

  //Tell the HMC what regist to begin writing data into
  Wire.beginTransmission(addr);
  Wire.write(0x00); //start with register 3.
  Wire.endTransmission();
  
 
 //Read the data.. 2 bytes for each axis.. 6 total bytes
  Wire.requestFrom(addr, 6);
  if(6<=Wire.available()){
    x = Wire.read()<<8; //MSB  x 
    x |= Wire.read(); //LSB  x
    z = Wire.read()<<8; //MSB  z
    z |= Wire.read(); //LSB z
    y = Wire.read()<<8; //MSB y
    y |= Wire.read(); //LSB y
  }
  
  // Show Values
  Serial.print("X Value: ");
  Serial.println(x);
  Serial.print("Y Value: ");
  Serial.println(y);
  Serial.print("Z Value: ");
  Serial.println(z);
  Serial.println();
  
  delay(500);
}

Raspberry pi code:

import smbus
import time
import math 
bus = smbus.SMBus(1)
address = 0x0d

for i in range(0,50):
    def read_byte(adr): #communicate with compass 
        return bus.read_byte_data(address, adr) 

    def read_word(adr): 
        high = bus.read_byte_data(address, adr) 
        low = bus.read_byte_data(address, adr+1) 
        val = (high<< 8) + low 
        return val 

    def read_word_2c(adr): 
        val = read_word(adr) 
        if (val>= 0x8000):
            return -((65535 - val)+1) 
        else: 
            return val 

    def write_byte(adr,value): 
        bus.write_byte_data(address, adr, value) 
    write_byte(11, 0b01110000) 
    write_byte(10, 0b00100000) 
    write_byte(9, 0b00011101) 
    scale = 0.92 
    x_offset = -10 
    y_offset = 10 
    x_out = (read_word_2c(0)- x_offset+2) * scale  #calculating x,y,z coordinates 
    y_out = (read_word_2c(2)- y_offset+2)* scale 
    z_out = read_word_2c(4) * scale
    bearing = math.atan2(y_out, x_out)+.48  #0.48 is correction value 
    if(bearing < 0): 
        bearing += 2* math.pi
    print "Bearing:", math.degrees(bearing)
    print "x: ", x_out
    print "y: ", y_out
    print "z: ", z_out
    time.sleep(3)
Please check the code with your digital compass and fill free to ask the question.
#

Hello, thank you for this code. It's the first thing that actually displays anything else than a bunch of zeros. Now, my problem is, that the values fluctuate by a very significant degree. (I am on the RPi by the way) I hope you can help me, I have spent the last hours searching for answers and this post is the first thing that helped me. But I am not really happy with this result, the values are unusable.

suttonnico
Posts: 1
Joined: Sat Feb 17, 2018 2:21 am

Re: wrong i2c address

Sat Feb 17, 2018 2:30 am

SamuelVergeiner wrote:
Thu Feb 08, 2018 4:19 pm
kumardas wrote:
Mon Sep 04, 2017 2:07 pm
hey guys,

The compass with wrong I2C address are not a fake one. I solved the problem for this, its only the differences in address of resistors.
I got the response from arduino uno but the accuracy in result is not very impressive.


Anyway : fined the code for the GY-271 HMC5883L in arduino and the raspberry pi respectively.

arduino code:

Code: Select all

#include <Wire.h> //I2C Arduino Library

#define addr 0x0D //I2C Address for The HMC5883

void setup(){
  
  Serial.begin(9600);
  Wire.begin();
  
  
  Wire.beginTransmission(addr); //start talking
  Wire.write(0x09); // Set the Register
  Wire.write(0x1D); // Tell the HMC5883 to Continuously Measure
  Wire.endTransmission();
}


void loop(){
  
  int x,y,z; //triple axis data

  //Tell the HMC what regist to begin writing data into
  Wire.beginTransmission(addr);
  Wire.write(0x00); //start with register 3.
  Wire.endTransmission();
  
 
 //Read the data.. 2 bytes for each axis.. 6 total bytes
  Wire.requestFrom(addr, 6);
  if(6<=Wire.available()){
    x = Wire.read()<<8; //MSB  x 
    x |= Wire.read(); //LSB  x
    z = Wire.read()<<8; //MSB  z
    z |= Wire.read(); //LSB z
    y = Wire.read()<<8; //MSB y
    y |= Wire.read(); //LSB y
  }
  
  // Show Values
  Serial.print("X Value: ");
  Serial.println(x);
  Serial.print("Y Value: ");
  Serial.println(y);
  Serial.print("Z Value: ");
  Serial.println(z);
  Serial.println();
  
  delay(500);
}

Raspberry pi code:

import smbus
import time
import math 
bus = smbus.SMBus(1)
address = 0x0d

for i in range(0,50):
    def read_byte(adr): #communicate with compass 
        return bus.read_byte_data(address, adr) 

    def read_word(adr): 
        high = bus.read_byte_data(address, adr) 
        low = bus.read_byte_data(address, adr+1) 
        val = (high<< 8) + low 
        return val 

    def read_word_2c(adr): 
        val = read_word(adr) 
        if (val>= 0x8000):
            return -((65535 - val)+1) 
        else: 
            return val 

    def write_byte(adr,value): 
        bus.write_byte_data(address, adr, value) 
    write_byte(11, 0b01110000) 
    write_byte(10, 0b00100000) 
    write_byte(9, 0b00011101) 
    scale = 0.92 
    x_offset = -10 
    y_offset = 10 
    x_out = (read_word_2c(0)- x_offset+2) * scale  #calculating x,y,z coordinates 
    y_out = (read_word_2c(2)- y_offset+2)* scale 
    z_out = read_word_2c(4) * scale
    bearing = math.atan2(y_out, x_out)+.48  #0.48 is correction value 
    if(bearing < 0): 
        bearing += 2* math.pi
    print "Bearing:", math.degrees(bearing)
    print "x: ", x_out
    print "y: ", y_out
    print "z: ", z_out
    time.sleep(3)
Please check the code with your digital compass and fill free to ask the question.
#

Hello, thank you for this code. It's the first thing that actually displays anything else than a bunch of zeros. Now, my problem is, that the values fluctuate by a very significant degree. (I am on the RPi by the way) I hope you can help me, I have spent the last hours searching for answers and this post is the first thing that helped me. But I am not really happy with this result, the values are unusable.
Hi, I've been struggling with this module for the last couple of days, the code up works but the read_word function should be changed to:

def read_word(adr):
low = bus.read_byte_data(address, adr)
high = bus.read_byte_data(address, adr+1)
val = (high<< 8) + low
return val

Also I've changed the configuration to:

write_byte(11, 0b00000001) #reset
write_byte(9, 0b00000000|0b00000000|0b00001100|0b00000001) #config

I think that should work a little bit better.
This thread has been increadibly helpful.

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: wrong i2c address

Sat Feb 17, 2018 3:18 pm

its only the differences in address of resistors.
No the registers inside the chip are at a different address and they do different things. You need to read the data sheet to see what they are.

PeersC
Posts: 30
Joined: Fri Apr 01, 2016 6:35 pm

Re: wrong i2c address

Wed Mar 14, 2018 7:16 pm

Hya All,

Realized that I have a similar issue with my DA 5883 6009 (my chip extension) got the 0x0D return - got the data sheet and pretty sure all is working does someone have some working python code so I can test. Tried the code above and had to add a load of indents and other fixes - I am using Python 3 on a Pi 3. Not sure if I got the fixes right but did get a load of zero's.

Can find a lot for Arduino but everything else on my project, servo's, ultrasonics and steppers run Python.

Anyone Help, Thanks

PeersC

sam38
Posts: 1
Joined: Fri Apr 27, 2018 4:01 am

Re: wrong i2c address

Fri Apr 27, 2018 7:28 am

Hi
@ suttonnico

can you explain this line ?
write_byte(9, 0b00000000|0b00000000|0b00001100|0b00000001) #config

Thanks a lot

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: wrong i2c address

Fri Apr 27, 2018 12:07 pm

write_byte(9, 0b00000000|0b00000000|0b00001100|0b00000001) #config

Is a rather silly line, it is the logic or of 4 bytes and could be replaced with:-
write_byte(9, 0b00001101) #config
Or even better if you replaced it with:-
write_byte(9, 0xD) #config

User avatar
Niccolo
Posts: 19
Joined: Mon Dec 14, 2015 8:45 am
Contact: Website

Re: wrong i2c address

Sun Oct 14, 2018 10:29 pm

Hi to all, I just write here because this post was one of the first I found when searching a driver for the QMC5883L on the Raspberry Pi.
The code posted here is a bit primitive (no check for data ready, no check for overflow), other software I found (also published on Pypi.org) does not work at all.
So I wrote a little driver for the QMC5883L and published it here: https://github.com/RigacciOrg/py-qmc5883l
Using it is quite simple and it gives very stable data:

Code: Select all

#!/usr/bin/python
import time
import py_qmc5883l
sensor = py_qmc5883l.QMC5883L()
while True:
    print sensor.get_magnet()
    time.sleep(0.2)

Return to “Troubleshooting”