First off - how do I hook them up precisely?
(I have some caps and resistors here, which are needed)
I think I can get by with the information on the website I fount though.
But then - my biggest problem is,
how do I use them in my Arduino Code?
If you could provide me with that library,
It would be a great help I think.
I was planning to use them to read button inputs.
Do I have to use pull-down / up resistors for that?
I have made a generic library for it (without the LCD interaction), I will supplied tonite.
The hooking up is quite easy. Only the RC part is 'hard'. As long as you get a frequency close to what they suggest, any combination should work.
To communicate, simply use the library, which uses the Wire library in turn. All very easy.
You will have to use pull ups for the button, as the MCP23016 does not support pull-up/down configurations.
I tried to use pull-downs for a joystick I tested, but could not get interrupts working like that. Manual reading was no issue though. But I strongly suggest pull-ups on buttons.
Unfortunately, the chip has 3 different modes of doing things. You will need to read through the data sheet to understand how it works. It is quite important.
First off - how do I hook them up precisely?
(I have some caps and resistors here, which are needed)
I think I can get by with the information on the website I fount though.
Connect SDA and SCL on the MCP to SDA and SCL on the Arduino, use pull up resistors on the lines to 5v (I hear 1.8k is the best value for this). Pin 9 has your 3.9k resistor to 5v and a 33pf cap to ground for the clock generator. Pins 1,8,19 go to ground. Pin 20 goes to 5v. Then just hook up the GPIO lines to your buttons.
Hope that helps a little. With the code from leppie, you should be set. Basically, you're just sending the data 1 item at a time and waiting for an acknowledge bit from the device (arduino hides the waiting/acknowledge part) I2C works really well, so you shouldn't have issues.
I know you commented them.
But nothing seems to change when I comment them out.
I was interested in the switch inverter code, but that does not seem to do anything...
But nothing seems to change when I comment them out.
gpio_write(sensorAddress, ddrSensor, I2CregisterConfig); // Sensor Switches
sets up the DDR (Data direction register) for the pins to be inputs. The turn on default is an input so you might not notice if this is removed. However it should be included as good practice.
gpio_write(sensorAddress, ddrSensor, I2CregisterPolarity); // invert switch inputs so 1 = detected
If this is removed then a logic zero on the input of the chip will read as a logic zero through the device, with it a logic zero on the chip will read as a logic one.
gpio_write(sensorAddress, 0x0101, I2CregisterExpander); // Fast response
This responds to signal changes faster but uses more power. With out this there will be a slight lag before the change pin goes low. You wouldn't notice this unless you were measuring it or had a time critical application.
for all of these see the data sheet for full details.