RP2040 Pico Slave to Raspberry Pi?

Hi, over the past few months the Dallas Personal Robotics Group (DPRG) and the NZPRG (New Zealand) have been discussing use of a Raspberry Pi as a master controller, using various microcontrollers (Arduino, ItsyBitsy, Tiny, etc.) as slave or sub-processors.

In a nutshell, this would be to execute some Python code on the slave, perhaps obtaining infrared or other sensor data, producing some kind of data package, then the master polls the slave to obtain the latest values. There are a few libraries that support this kind of thing but none are really that easy to use and/or bug-free. I’ve been using the Breakout Garden IO Expander (which uses a Nuvoton MS51 to communicate with over I2C) and while this is easy to use, it’s just a set of IO pins and not directly programmable (I’ve even asked the Forum about this but yet received no answer). I’ve even gone so far as to buy a Nuvoton SBC to try programming its MS51 directly, but that’s likely too big a jump from Python for most people. Likewise, it’s possible to use an Arduino compatible but it’d be a lot simpler (particularly for students) if both master and slave were using the same programming language.

With the release of the Pico I’m quite excited to explore using one as a Pi slave, but in looking over the available documentation I don’t see anything that explicitly shows how this might be done. The MicroPython SDK shows connecting a Raspberry Pi to a Pico via USB or GPIO for REPL, but that’s not quite the same thing.

As this may be a fairly common use case (certainly in robotics), I was wondering if any of your engineers might already have some Python code available or be able to provide a downloadable example showing how a Pi might intercommunicate with a Pico. That’d be extremely handy.

Thanks very much for any information!

Can’t you do most of this over a serial connection? You set the microcontroller up to listen for serial commands, and then send it commands from the Pi. The microcontroller reads the serial command, carries out the matching function, and then returns whatever data over serial.

So for the microcontroller the pseudocode would be something like:

listen for serial data
if serial data is recieved:
    if serial value == 1:
        do function A
    if serial value == 2:
        do function B
transmit result of function back over serial