Page 1 of 1

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

Posted: Wed Sep 01, 2021 10:51 pm
by FoolyCooly
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.

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

Posted: Thu Sep 02, 2021 6:50 am
by pythoncoder
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.

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

Posted: Fri Sep 03, 2021 4:20 pm
by dhylands
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.

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

Posted: Fri Sep 03, 2021 5:55 pm
by kevinkk525
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.