Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

newbie Q on getting data from connected i2c device

Does anyone here know how to read data from an i2c device? I can't seem to figure it out. I'm looking at the i2c API here

And the i2c interface info for my sensor here (page 9):

and it looks easy enough, but I am unsure of the values to use for
i2cModule.readData((byte) 0x1c, (byte) 0xd, (byte) 1).onComplete(new CompletionHandler<byte[]>()

Thanks in advance for any advice and help you can provide.


  • Based on page 9 of the pdf, the device address is 1110110x where x=1 for read and x=0 for write.  You can probably use 0x0 for register address, and set numBytes to 1.
  • Thank you Eric. 1110110x in hex is 0x76, so that's what I'm using here, correct? Still banging away for now. If you have any examples, or if anyone else has connected a i2c sensor to their metawear please share! I'll do the same when I get it working (but I'm pretty slow).

    i2cModule.readData((byte) 0x76, (byte) 0x0, (byte) 1).onComplete(new CompletionHandler<byte[]>()
  • No, the spec sheet states that the device address is in the form 1110110x where x=1 for read and x=0 for write, not the address is 0x76.
  • edited February 6
    Thanks again Eric. I've got the read/write working for i2c on the board using your example code. But I do not have the same success with my i2c sensor. You don't have an i2c bus scanning util by any chance do you?

    I've also found some C and .java examples for that sensor, but based on different APIs. They write to 0xE1 to do an initial Reset (as per DS) and then read 2btyes from the Prom 0xA2, as per DS. The 7 bit device address ix 0x76, but I don't need that for metaware.

    How can I use i2cModule.writeData to write just one value?
    i2cModule.writeData((byte)0x1E) <-- I think I want this
    Here's how the other examples do it:
    // Create I2C bus
    I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);
    // Get I2C device, MS5837_30BA01 I2C address is 0x76
    I2CDevice device = Bus.getDevice(0x76);

    // Reset command

    byte[] data = new byte[2];
    // Read 12 bytes of calibration data
    // Read pressure sensitivity, data, 0, 2);
    int C1 = ((data[0] & 0xFF) * 256 + (data[1] & 0xFF));

  • We do not have a i2c scanner.

    Based on the example java code, you try using 0x76 for deviceAddr, and 0x0 for registerAddr.
Sign In or Register to comment.