I2C not working

Hi there,

We are currently working with a few I2C devices such as the MPU 6050 but we keep getting I2C errors.
Even the I2C scanner doesn’t work for detecting our device, but our Arduino code for scanning and getting
data from the MPU works fine.

We used the i2c readerror() function and it keeps returning -2 or -6.

Here is our code:

server.log(“Just checking for I2C devices”)

i2c <- hardware.i2c89; // Set to desired I2C bus

local addr = 0x68;
i2c.write(addr, “\x6B” + “\x20”);
server.log(i2c.read(addr, “\x6B”, 2));

for (local i = 2 ; i < 256 ; i+=2) {
if (i2c.read(i, “”, 1) != null) server.log(format(“Device at address: 0x%02X”, i));

server.log(“Read Error”);


Do you have your pullup resistors on the i2c bus? What value are you using?

Can you log the result of the i2c.write and i2c.readerror after that?