Anyone have some sample code for UART or SPI, communication between two boards?

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
FoolyCooly
Posts: 3
Joined: Mon Jun 24, 2019 2:43 am

Anyone have some sample code for UART or SPI, communication between two boards?

Post by FoolyCooly » Wed Sep 01, 2021 10:51 pm

Sorry new, but I was curious if anyone had some sample code using two RP2040 boards. I'm trying to learn some basics and had a project in mind. One board just takes basic switch inputs and the other board just does basic outputs to turn on/off LEDs. It would be a short distance (2 meters or about 6 feet), I was hoping to reduce the amount of wiring needed in my DIY project. I just have no experience with either SPI or UART, anything would help.

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

Re: Anyone have some sample code for UART or SPI, communication between two boards?

Post by pythoncoder » Thu Sep 02, 2021 6:50 am

I would strongly recommend using UARTs. You need to ensure that the boards share a common gnd connection. Link the tx of one board to the rx of the other (and vice-versa if you want 2-way communication). The docs give a pointer as to how to initialise, send and receive.
Peter Hinch
Index to my micropython libraries.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Anyone have some sample code for UART or SPI, communication between two boards?

Post by dhylands » Fri Sep 03, 2021 4:20 pm

I've written a JSON IPC library which can modified quite easily to work over serial. You can find it here: https://github.com/dhylands/json-ipc

Currently it only has code for using the VCP (USB) interface on the stm, but it's pretty easy to add a uart version. The UART variant would need the same 3 functions, but the constructor can take different arguments.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Anyone have some sample code for UART or SPI, communication between two boards?

Post by kevinkk525 » Fri Sep 03, 2021 5:55 pm

In my unfinished project for providing wlan to a rpi pico I'm using a UART communication with CRC verification of the messages. The project might be unfinished but the uart communication is completed and works. But since you're new, I don't know your level of programming experience, so maybe just take a look and see if it is easy enough for you to adapt: https://github.com/kevinkk525/micropyth ... _link_libs

It completely relies on the host->client principle but that seems to be enough for your project for now since one board is only taking orders to toggle LEDs.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply