I spend the day today fiddeling with a MCP23017 port expander on the i2c.
Im not getting consistent readings all the time and I do not really know how to get any progress.
Im usingt various arduinos, and the problem is consistent. When i read a port I get to many pins low.
The results could look like this: (Serial Output).
128 - 10000000
128 - 10000000
222 - 11011110
223 - 11011111
223 - 11011111
223 - 11011111
223 - 11011111
223 - 11011111
223 - 11011111
223 - 11011111
223 - 11011111
95 - 1011111
(123 was expected)
My Code Is:
#include <Wire.h>
byte inputs=0;
void setup()
{
Serial.begin(9600);
Wire.begin(); // wake up I2C bus
Wire.write((byte)0x0c); // set all of bank B to inputs
Wire.write(0x00); //enable pullup???
}
void loop()
{
Wire.beginTransmission(0x20);
Wire.write(0x12); // set MCP23017 memory pointer to GPIOB address
Wire.endTransmission();
Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
inputs=Wire.read(); // store the incoming byte into "inputs"
Serial.print(inputs);// print as normal int
Serial.print(" - ");
Serial.println(inputs, BIN); // display the contents of the GPIOB register in binary
delay(200); //
}
If I change the dalay in last line to a shorter than 20 delay the error seems to go all beserk...
The schematich appears to be ok. A i2c scanner reports consistant connection.
Reset pin is tied to hidg, and i got pullup on the i2c.
I have tried with several arduinos and cables with the same results.
Im out of resistors so I have NUT tries to use pullups directly on the pins.
ANy sugestions or ideas on what to try?
Peter