Anyone have some sample code for UART or SPI, communication between two boards?
-
- Posts: 3
- Joined: Mon Jun 24, 2019 2:43 am
Anyone have some sample code for UART or SPI, communication between two boards?
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.
- 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?
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.
Index to my micropython libraries.
Re: Anyone have some sample code for UART or SPI, communication between two boards?
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.
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.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Anyone have some sample code for UART or SPI, communication between two boards?
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.
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
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode