5

I want my Raspberry Pi to control my Raspberry Pico. I'm trying to send bytes of data to the pico and then read the data on the pico so that I can take different actions depending on the data sent (e.g. turn different lights on or off).

I'm new to the world of Pi and I have not managed to find a simple example which points me in the right direction. However, it looks like I should be able to use I2C to achieve what I want.

Is it possible to set the Pico up as an I2C slave with any existing python libraries?

I've tried the following micropython code on the pico, but it doesn't show up as a slave on the Pi.

from machine import I2C, Pin
my_pico = IC2(0, scl=Pin(1), sda=Pin(0))

The Pico SDK docs mentions i2c_set_slave_mode, so I guess I'm looking for some way to use that via python.

2
  • 2
    Could you explain the end goal? There may be much easier ways to achieve what you are triyng to do, e.g. my picod module abyz.me.uk/picod
    – joan
    May 28, 2021 at 11:55
  • 1
    @joan End goal is mostly about understanding communication between processors. I just want a basic event loop on the pico which listens for 'commands' from the pi and processes them. I've recently been learning python, so want to stick with that for now. I've read a bit about SPI and UART, but I2C sounded the easiest (until I tried it). Looking at your link to picod, I think the pico daemon sounds pretty similar to the event loop I'm trying to create. I'd just rather have it as a simple micropython program on the pico if that's possible.
    – pcoates
    May 28, 2021 at 12:23

1 Answer 1

4

I googled and find this Pico I2C Slave class in microPython: i2cSlave.py.

Use Pico as an I2C slave? - danjperron, rpi.org.forums, 2021feb20

2
  • 2
    thanks - I didn't see it when I looked. It sounds promising, so I'll give it a try.
    – pcoates
    May 28, 2021 at 14:10
  • 1
    the example from danjperron in the linked forum post works for me. Thanks for pointing it out.
    – pcoates
    May 28, 2021 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.