Strange behavior with pin 2 and 3
1412 Views - Created 02/03/2019
I have a very strange issue which I can't solve (now)
I've set up IOPi to switch 32 LEDs.
I've connected an external power supply (just in case)
For demonstrating my problem I am sending a short code snipped:
from IOPi import IOPi
bus1 = IOPi(0x20)
The last line shoud light LED #3.
But ot doesn't
When I send "bus1.write_port(0, 0x02)" LED #2 should be on. But it doesn't.
When I send "bus1.write_port(0, 0x06)" LED #2 and #3 should be on. And this works.
Strange, isn't it?
It doesn't matter if I use write_port or write:pin. Same issue
I try to set each pin indidually. For that, I use same skript as above but I use write_pin instead of write_port.
For each call of this routine one LED ist set to on. But not LED 2 or 3
Funny part: If I change my routine to:
from IOPi import IOPi
bus1 = IOPi(0x20)
LED 2 and 3 are on
Where is the solution? I Hope there is aneasy solution.
I can't see any problems with your code. Do you get the same problem if you try running the same code on the other bus, 0x21?
What is the current draw from each LED? The maximum current the MCP23017 IO controller can source is 125mA so if the LEDs are drawing more than that when they are all turned on that could cause the chip to act erratically.
I can't messure the current. But I use the same resistor for each individual LED (200R).
The strangest thing is, that if I start the routine for LED 2 and then for LED 3, both LEDs should be on. But the aren't.
When I turn on the LED 2 and 3 with the write_pin command in the SAME routine, they are both on.
My current idea is, that there must be something with the initialisation of the bus. But I don't know what.
I tried your code on an IO Pi Plus and both the write_pin and write_port methods appear to be working correctly. In the IO Pi python library when the IOPi object is initialised both ports are set as inputs with the internal pull-up resistors disabled and the ports set to be non-inverted. As you are setting the ports to be outputs at the start of your code that should rule out the initialisation as the problem.
With 200R resistors on the LEDs, assuming they have a forward voltage of around 2V, each LED would be drawing 15mA so with all 16 outputs switched on the overall current consumption would be 240mA which is more than the MCP23017 can safely supply. Ideally, you should use a resistor value of at least 430R which would allow each channel to draw 7.5mA.
As the problem with the IO Pi Plus appears to be hardware related I will send you a replacement. I have sent you an email to the address you used to register on this forum.
I am so sorry!!!
as always (or nearly) the problem is the user.
I had a cold solder joint which made the troble.
Now I fixed it and it seenms to be the solution.
Thank you to be so great to help me.
Only one thing confuses me: You wrote, that I should use a 430R resistor.
I used a 200R resistor because I read this in one of the tutorials.
" The maximum current you can draw from any of the pins on the MCP23017 is 25mA so by using the 200R resistor in series with the LED we limit the current to a safe level. "
Usualy there are only up to 10 LEDs active. But in some cases and for a short time there might be a full load (all the 32LEDs are active.
And sorry again for the confusion.
In tutorial 1 I used a 200R resistor as the tutorial used 8 LEDs so with 15mA being drawn by each LED the total with all 8 switched on would be 120mA which is just below the 125mA that the MCP23017 can safely supply.
As you are using all 16 outputs ideally you need to reduce the current on each LED down to less than 7.8mA so that if they do all get switched on at the same time it will not damage the chip. A 430R resistor would drop the current down to around 7.5mA which should be enough to light the LED while keeping the total current below the 125mA limit.
I will update the tutorials to make it clearer why I chose the 200R resistor value and how to calculate the correct values when using more than 8 LEDs.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.