Hi
I bought a new MCP23018 IO expander. But underestimated the difficulty of what I started.
I’m able to get a connection without having any errors and detected it on address 20:
Wire.begin();
Wire.beginTransmission(20);
int error = Wire.endTransmission();
But I don’t know how to get a led to blink. (Totally useless)
It’s an Arduino Uno rev3 with 2 pull-up resistors of 10Kohm for the i2c communication.
I can’t find any clear tutorial and don’t know where to start. (The datasheet is also not self-explaining :D)
It would be nice if you could give me one working example.
Greeting from The Netherlands.
Thanks a lot for responding!
I already read those 2 posts, but by trying again because of yours motivation I am able to get a led blink. (Link 1)
But I have 2 questions.
I don’t understand the first 10 lines in the setup. Is it really needed, or is there a shorter way if I just want a led to blink. (Without libraries)
Second (less important), my led blinks very weak (with 220ohm resistor). Is there already an internal resistor and could I omit it, or is this just the maximum output current?
Again thanks!
I think there are problems with the code in the original post in link 1 thread.
The code in reply #2 of that thread may be a better starting point.
Looks like the absolute minimum you require in setup() for your application is to set the IODIRA direction register so that the pins are outputs, not inputs.
Note: you should first set the latch, then the pull-up resistor: WEIRD?? Otherwise it doesn’t work.
Something else: it’s very unstable. When I try to connect a cable just on one side to any point in the breadboard, it stops.
Connection of my led:
GPA0 (pin 20) --> led --> 220ohm resistor --> ground of Arduino
With an external pull-up resistor (10Kohm), the LED is a little bit brighter, but not as bright as connecting it directly of the 5 volt with 220ohm.
Connection of my led:
GPA0 (pin 20) --> led --> 220ohm resistor --> ground of Arduino
The MCP23018 outputs are open drain. Your LED and series resistor will work better if connected to +5V. When the output goes LOW, the LED should come on.
This will avoid the need to use the internal pull-up resistors.
THANKS THANKS THANKS!!!!
It works how you predicted the first time!! But now I also understand what went wrong. I didn’t realize that the register address changed in comparison to the state of this chip.
By the way my LED blinks like a sun!
My new working code: