Raspberry Pico and MCP23017 randomly not working #12480
Replies: 5 comments 9 replies
-
Not really enough information to help you so this is just a shot in the dark. Have you connected all the address pins to either ground or vcc? Thet are not internally pulled. I forgot them on one pcb design, four of the five cards still worked. |
Beta Was this translation helpful? Give feedback.
-
Hi, I assume you are referring to this: mcauser/micropython-mcp23017#16 OSError 5 means your Pico can't find / communicate with the MCP. All of my testing was on an ESP32 board, using I2C defaults. Yes, the 3x address select pins need to be pulled to either VCC/GND, which gives you an I2C address in the range 0x20-0x27 (32-39). |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks both for your answers. I fixed the issue buy using a very simple function that checks if the connection between the MCP23017 and the Raspberry works OK and just re-tries to connect if it doesn't:
However, I would still like to understand why the MCP23017 is failing at random intervals of time. Please find next answers to your questions and more information on the setup:
None of that solved the problem. It seems the MCP23017 stops working for very short periods of time (I would guess in the us range) every 1-10 minutes. Any ideas on what might be causing this issue? Thanks again! |
Beta Was this translation helpful? Give feedback.
-
The code above looks wrong. If you want it to keep trying the last two lines should be deleted: def IO_expander_update(self):
self.IO_expander_updated = False
while (self.IO_expander_updated == False):
try:
# Read the buttons state.
self.button_UP = self.IO_expander.pin(0)
self.button_DOWN = self.IO_expander.pin(1)
self.button_MODE = self.IO_expander.pin(2)
self.button_PULSE = self.IO_expander.pin(3)
self.button_DIS_ARM = self.IO_expander.pin(4)
self.IO_expander_updated = True
except OSError as e:
print("Error communicating with MCP23018. Re-trying.") I can't think of a reason for the failure. It might be instructive to try a different platform e.g. ESP32. |
Beta Was this translation helpful? Give feedback.
-
Does using SoftI2C instead of I2C make any difference? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I am using a Raspberry Pi Pico, programmed in MicroPython with Thonny and connected via I2C to an MCP23017 IO expander. It works OK, but every 3-5 minutes, it randomly stops working, with the following error:
Traceback (most recent call last):
File "", line 42, in
File "mcp23017_new.py", line 80, in value
File "mcp23017_new.py", line 43, in bit
File "mcp23017_new.py", line 26, in read
OSError: [Errno 5] EIO
I made a new circuit in a breadboard, with just the Raspberry Pi Pico and the MCP23017, and a very simple script, as shown next:
from machine import I2C, Pin, RTC, ADC, SPI, UART
import mcp23017_new
Set-up the I2C bus.
i2c_bus = I2C(1,
scl = Pin(19, pull=Pin.PULL_UP),
sda = Pin(18, pull=Pin.PULL_UP),
freq = 10_000)
Set-up the MCP23017 I/O expander.
IO_expander = mcp23017_new.MCP23017(i2c_bus, 0x20)
while (True):
button_UP = IO_expander.pin(0).value()
print(" ")
print(str(button_UP))
And the problem persists. I already tried lowering the I2C frequency, using a different driver, setting the I2C pins with pull-up resistors and placing physical 3.3 kOhm pull-up resistors in the breadboard. None of this solved the issue.
Could you pleas tell me where the problem might be?
Thanks!
Best,
Diego
Beta Was this translation helpful? Give feedback.
All reactions