Problem with I2C?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Gunter
Posts: 1
Joined: Sat Feb 12, 2022 4:58 pm

Problem with I2C?

Post by Gunter » Sat Feb 12, 2022 6:06 pm

Hello,
I installed micropython v1.18 on a pi pico module.
Attached to the pico I connect a mcp23017.
Using the MCP23017 module from Mike Causer I wrote a small test program that every 500ms turns pin0 on and off.
This works for about 1..2 minutes and then it stops with an error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 20, in <module>
  File "mcp23017.py", line 405, in output
  File "mcp23017.py", line 85, in mode
  File "mcp23017.py", line 73, in _read
OSError: [Errno 5] EIO
Environment:
Win 11 with Thonny 3.3.13 installed
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040

Question of the day :-): what's going wrong? :-?
Is it my error?

Thanks,
Gunter

Code of test program:

Code: Select all

import time
import mcp23017
from machine import Pin, I2C

# Initialize the I2C bus:
i2c = I2C(1, scl=Pin(3), sda=Pin(2), freq = 100_000)

mcp = mcp23017.MCP23017(i2c, 0x20)  # MCP23017

mcp.pin(0, mode = 0)

pin0 = mcp[0]

# Now loop blinking the pin 0 output and reading the state of pin 1 input.
while True:
    # Blink pin 0 on and then off.
    pin0.output(0)
    time.sleep(0.5)
    pin0.output(1)
    time.sleep(0.5)

fivdi
Posts: 16
Joined: Thu Feb 03, 2022 10:28 pm
Contact:

Re: Problem with I2C?

Post by fivdi » Sun Feb 13, 2022 4:29 pm

Are the required pull-up resistors on the SCL + SDA lines?

User avatar
jcf
Posts: 60
Joined: Wed Mar 03, 2021 11:14 am

Re: Problem with I2C?

Post by jcf » Wed Feb 16, 2022 5:29 pm

Many modules have internal pullup resistors. This may work or not, as they are often too high ohm.
I just now happened to have the same problem with I2C.
A look at the circuit with the scope showed pulses deformed by capacitive load.
With additional 1k pullups everything worked fine.
Of course the length of the cables plays a role also.

By the way, I learned something from your code :-)
I didn't know that you can write 100000 as 100_000.

Post Reply