Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Strange behavior with pin 2 and 3

1412 Views - Created 02/03/2019

02/03/2019

Posted by:
Arnulf

Arnulf Avatar

Hi!

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:

------------

#!/usr/bin/env python
from IOPi import IOPi

bus1 = IOPi(0x20)
bus1.set_port_direction(0, 0x00)
bus1.set_port_direction(1, 0x00)
bus1.write_port(0, 0x04)

-------------

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

Next test:
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:

---------

#!/usr/bin/env python
from IOPi import IOPi

bus1 = IOPi(0x20)
bus1.set_port_direction(0, 0x00)
bus1.set_port_direction(1, 0x00)

bus1.write_pin(2, 1)
bus1.write_pin(3, 1)

-------

LED 2 and 3 are on



Where is the solution? I Hope there is aneasy solution.

02/03/2019

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hi

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.

03/03/2019

Posted by:
Arnulf

Arnulf Avatar

No. Only on this bus. Bus 0x21 is working fine

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.

03/03/2019

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

If the same code works fine on 0x21 then that would suggest a hardware problem with the chip on 0x20.

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.

03/03/2019

Posted by:
Arnulf

Arnulf Avatar

OMG
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. "

https://www.abelectronics.co.uk/kb/article/17/io-pi-tutorial-1---the-blinking-led

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.

03/03/2019

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

I'm glad you managed to fix the problem.

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.

Sign in to post your reply

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.