Am I doing this right in code? I2C Help

So I am struggling with I2C…

I have a perf board all soldered up and can’t get the particle to talk with an MCP23017. I did test it in the Bus Pirate and can get the LEDs to turn on. I did use some pull resistors (4.7k) on the lines and described in the Docs. Here’s my code:

void setup(){
Serial.begin(9600);
Serial.println(String(“Initiated”));
Wire.setSpeed(CLOCK_SPEED_400KHZ);
Wire.begin(byte(0x20));
Wire.beginTransmission(byte(0x20));
Wire.write(byte(0x00));
Wire.write(byte(0x00));
Wire.endTransmission();
delay(500);
Wire.beginTransmission(byte(0x20));
Wire.write(byte(0x01));
Wire.write(0x00);
Wire.endTransmission();
}

void loop(){
Wire.beginTransmission(byte(0x20));
Wire.write(0x13);
Wire.write(0xF0);
Wire.endTransmission();
delay(1000);
Wire.beginTransmission(0x20);
Wire.write(0x13);
Wire.write(0x00);
Wire.endTransmission();
delay(1000);
}

You need to use the version of Wire.begin() that does not take a parameter. The version with a parameter sets up I2C as slave mode. You need to be in master mode to communicate with a device on the I2C bus.

1 Like

Well believe it or not I made (being a newbie) a newbie mistake! I was using 4.7Ohm resistors. :triumph: Once I figured that out is was gold!