I have a raspberry pi connected to an IO Pi Plus from AB Electronics. I have one of the two MCP23017 chips as an output only, the other as an input only. They are individually addressable by 0x20 and 0x21 respectively.
Outputting is fine, and I can easily control LEDs using the function:
wire.write([0x00, 0x00], function(err){}); //Set wire(0x20) data direction resister(0x00) to output only (0x00).
However trying to read in using wire.readByte never returns anything other than 255 (or -256 when I try inverting bits. Which is weird in it's own right). wire1 = 0x21 (input only)
wire1.readByte(function(err,res){ //Res is a buffer to hold the byte that is read
//res = ~res This returns -256 instead of 0 when enabled. Not sure why.
console.log(res); // Output res
});
});
All documentation I'm using is here https://www.npmjs.com/package/i2c and the datasheet for the chipset is http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf