Using Pico as an i2c peripheral?

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
directive0
Posts: 2
Joined: Fri Feb 05, 2021 4:13 pm

Using Pico as an i2c peripheral?

Post by directive0 » Fri Feb 05, 2021 4:19 pm

Hi all.

So I want to use my little pico as secondary element in a setup where it handles some auxillary sensors and indicators, but talks to a raspberry pi. I was hoping to use i2c as I've been enjoying learning more about it and I was wondering if that was a possibility.

I see that there is some support in pyb for using a pyboard as an i2c device controlled by another device on the bus. I also noticed that CircuitPython has an i2c peripheral class in their main branch, though it is not yet in Circuitpython for pico (and they tell me probably wont be for some time)

But I've been enjoying learning more about micropython, I'm just wondering if anyone knows if that kind of support will be coming to micropython for the Pico. It makes me think maybe its a hardware limitation and I'd have to bitbang a solution, but I wondered if some easy solution existed and thought I'd ask here! Thanks for any insight you can offer.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Using Pico as an i2c peripheral?

Post by jimmo » Sat Feb 06, 2021 5:08 am

directive0 wrote:
Fri Feb 05, 2021 4:19 pm
But I've been enjoying learning more about micropython, I'm just wondering if anyone knows if that kind of support will be coming to micropython for the Pico.
The RP2040 hardware does support I2C peripheral.

At a simple level, supporting it from MicroPython isn't too difficult (the SDK already has methods for it, and in gneral the machine API is just a wrapper around the SDK functionality).

However, the hard bit with I2C peripheral is coming up with a good API -- the main issue is that the IRQ handling needs to be very fast. I think there was some talk about supporting something higher level than the current pyb API (and try and support this on all platforms), i.e. something emulating a set of registers. You can set the value of registers and get notified when they change, but the actual handling of the I2C IRQs is done for you.

In the meantime though, I'd suggest using a UART instead to talk between devices.

directive0
Posts: 2
Joined: Fri Feb 05, 2021 4:13 pm

Re: Using Pico as an i2c peripheral?

Post by directive0 » Sat Feb 06, 2021 1:51 pm

Okay thank you for the advice. I will look into uart.

Post Reply