Hello folks. In an effort to introduce myself to I2C, I wired a MCP23008 port expander to an Arduino Uno and some leds. Seemed pretty simple but I can't get it to work. Below is a image of the connections.
I've tried the two sketches below:
#include <Wire.h>
void setup() {
Wire.begin(); // initialise the wire library and hardware
Wire.beginTransmission(0x20); // start talking to the device
Wire.write(0x00); // select the IODIR register
Wire.write(0xff); // set register value-all high, sets all pins as outputs on MCP23008
Wire.endTransmission(); // stop talking to the devicevice
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(0x20); // start talking to the device
Wire.write(0x09); // select the GPIO register
Wire.write(0xff); // set register value-all high
Wire.endTransmission(); // stop talking to the device
Serial.println ("on");
delay(500); // wait for 1/2 a second
Wire.beginTransmission(0x20); // start talking to the device
Wire.write(0x09); // select the GPIO register
Wire.write(0x00); // set register value-all low
Wire.endTransmission(); // stop talking to the device
Serial.println ("off");
delay(500); // wait for 1/2 a second
}
#include <Wire.h>
byte i2cAddr=B0100000;//device ID
void setup(){
Wire.begin();
}
void loop(){
Wire.beginTransmission(i2cAddr);
Wire.write(0x09);//select GPIO register
Wire.write(B11111111);//set register value-all high
Wire.endTransmission();
delay(500);
Wire.write(0x09);//select GPIO register
Wire.write(B00000000);//set register value-all low
Wire.endTransmission();
delay(500);
}
I think they are essentially the same.
Either sketch, the leds remain unlit all the time.
I ran I2C_Scanner and it came back with an address of 0x20.
When the first sketch was ran, it did print alternately 'on', 'off' every half second to the serial monitor.
I switched the data and clock signals to A5 and A4 and I reversed polarity on an led but the results were the same.
I keep thinking it's gotta be something simple but I can't spot it. Help Please. - Scotty