RP2040 Pico and i2c problem

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
fapplin
Posts: 3
Joined: Fri Jan 29, 2021 9:10 pm

RP2040 Pico and i2c problem

Post by fapplin » Fri Jan 29, 2021 9:27 pm

I'm using a DS1307 RTC board and I'm just trying to get the time.

I'm using Thonny to just do a very simple test (MicroPython v1.13-290-g556ae7914 on 2021-01-21; Raspberry Pi Pico with RP2040).

Code: Select all

from machine import I2C, Pin
i2c = I2C(1, sda=Pin(6), scl=Pin(7))
buf = i2c.readfrom_mem(0x68, 0, 7)
print(buf)
This is the error I get (which isn't very helpful). It is on the readfrom_mem() function.

Traceback (most recent call last):
File "<stdin>", line 3, in <module>
OSError: 5

I'm using

Code: Select all

https://github.com/mcauser/micropython-tinyrtc-i2c/blob/master/ds1307.py
for where I'm getting my information from.

Any ideas why I'm getting the error?

Frank

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: RP2040 Pico and i2c problem

Post by pythoncoder » Sat Jan 30, 2021 9:50 am

Have you got pullup resistors on the I2C lines? Have you tried I2C.scan()?
Peter Hinch
Index to my micropython libraries.

fapplin
Posts: 3
Joined: Fri Jan 29, 2021 9:10 pm

Re: RP2040 Pico and i2c problem

Post by fapplin » Sat Jan 30, 2021 2:36 pm

I'ĺl try it, but I've been having issues with tcs34725 sensor, too. I got an accelerometer to work, though. Is it some sensor have pull up resistors and some don't? I'm a very long time programmer but still fairly new to embedded stuff.

Thanks for the help.

fapplin
Posts: 3
Joined: Fri Jan 29, 2021 9:10 pm

Re: RP2040 Pico and i2c problem

Post by fapplin » Sat Jan 30, 2021 7:41 pm

Dumb programmer error - I had it connected to 3.3V and not 5V. All is working!

Frank

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: RP2040 Pico and i2c problem

Post by tannewt » Thu Feb 04, 2021 1:38 am

Be careful with 5v. The Pico's pins aren't 5v tolerant.

danhalbert
Posts: 18
Joined: Mon Jan 16, 2017 3:58 am

Re: RP2040 Pico and i2c problem

Post by danhalbert » Thu Mar 04, 2021 2:55 pm

fapplin wrote:
Sat Jan 30, 2021 2:36 pm
I've been having issues with tcs34725 sensor, too.
Did you get the TCS34725 to work? I've been working on the I2C support for CircuitPython. We do the same workarounds MicroPython does: short I2C writes need to be bitbang'd because the hw won't do them. Most sensors now work, but the TCS34725 still has issues. It works fine if we use software-bitbang I2C.

DirkHartkopf
Posts: 7
Joined: Mon Mar 22, 2021 7:32 pm

Re: RP2040 Pico and i2c problem

Post by DirkHartkopf » Tue Mar 23, 2021 7:32 pm

Hi Dan,
for the TCS34725 I found the library https://github.com/adafruit/micropython ... t-tcs34725, which is depreciated, but it runs on micropython.
My small test program
import utime
from machine import Pin,I2C
import tcs34725

sda = Pin(16)
scl = Pin(17)
i2c = I2C(0,sda=sda,scl=scl,freq=400000)

sensor = tcs34725.TCS34725(i2c)
print(sensor.read())
stops at the first read statement
return self.i2c.readfrom_mem(self.address, register, 1)[0]
in function _register8 with OSError: 5
Is this error associated to the issue you mentioned?

Do you have any suitable code for the Pico to get this bitbanging running (I'm a newbie in this)
Thanks, Dirk

danhalbert
Posts: 18
Joined: Mon Jan 16, 2017 3:58 am

Re: RP2040 Pico and i2c problem

Post by danhalbert » Tue Mar 23, 2021 8:04 pm

DirkHartkopf wrote:
Tue Mar 23, 2021 7:32 pm
Do you have any suitable code for the Pico to get this bitbanging running (I'm a newbie in this)
I believe you should be able to use SoftI2C. But a MicroPython user would know more.

Code: Select all

import utime
from machine import Pin,SoftI2C
import tcs34725

sda = Pin(16)
scl = Pin(17)
i2c = SoftI2C(0,sda=sda,scl=scl,freq=400000)

sensor = tcs34725.TCS34725(i2c)
print(sensor.read())

DirkHartkopf
Posts: 7
Joined: Mon Mar 22, 2021 7:32 pm

Re: RP2040 Pico and i2c problem

Post by DirkHartkopf » Wed Mar 24, 2021 7:17 am

Hello Dan,
thanks for your hint, it works!

I had only to switch from I2C to SoftI2C, that's all.

Cheers Dirk

Post Reply