3
votes

I've written a class for Arduino that reads the compass data of the HiTechnic LEGO Mindstorms compass sensor.

Using the Wire-library, I can very well fetch the data from the respective registers. In my library for Arduino I address the sensor by 0x01 which someone has done already on the Arduino forums. But everywhere else on the web (RobotC-forums for LEGO Mindstorms or in the code example at the very bottom of this document) it says, the I2C address of that sensor was 0x02.

So why do I have to use the address 0x01 in order to communicate with my sensor while it seems to be 0x02 for other programming languages?

1

1 Answers

4
votes

There are different formats of I2C addresses - 7 or 8 bits. Arduino uses the 7-bit format, so to convert an 8-bit address to 7-bits, you just shift it right by one. That's how the 0x02 8-bit address is converted to the 0x01 7-bit address.

Source: http://arduino.cc/en/reference/wire

"Note: There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127."