I have an LED display connected to a Teensy microcontroller using the FastLED library, which is connected to a Raspberry Pi Zero running Python via a USB hub.
I am looking for an existing library that handles the serial communication so that I can run commands in Python that trigger equivalent commands in FastLED on the Teensy efficiently and while respecting frame rate.
I've tried googling numerous times and searched the FastLED docs to see if there is something there. While there are many examples of code to drive LED displays via serial communication, I have not found a general library or package to do this.
E.g. What I'm looking for is something like this (simplified):
On the RPi:
dis = Display()
dis.connect()
for i in range(10):
dis.setLED(i, (64, 0, 0))
Would cause the Teensy to execute:
leds[i].r = data[i];
leds[i].g = data[i + 1];
leds[i].b = data[i + 2];
I would expect other convenient functionality such as:
leds = [11, 15, 19]
data = [
(32, 64, 96),
(64, 32, 96)
(96, 32, 64)
]
dis.setLEDs(leds, data)
data = ...
dis.setAllLEDs(data)
dis.clear()
That kind of thing.
Obviously, I can go ahead and write a library to do this myself but I can't believe it doesn't exist already so hoping someone will point me to something.
-
There was a similar question on Reddit 4 years ago: Is there a FastLED equivalent module for Python?. One answer includes a Micropython library.Bill– Bill02/03/2025 01:40:19Commented Feb 3 at 1:40
-
On the Python (RPi) side use PySerial to send structured LED data. On the Teensy (FastLED) side read from serial and update FastLED accordingly.liaifat85– liaifat8502/19/2025 17:57:30Commented Feb 19 at 17:57
-
@liaifat85 thanks for explaining how to do it. As I said, I could do this myself but I was hoping there was already a library for it.Bill– Bill02/19/2025 20:41:58Commented Feb 19 at 20:41
-
Just found this library for handling Arduino serial communication, Serial_Packets, which can be paired with this Python library, serial-packets.Bill– Bill04/23/2025 04:14:28Commented Apr 23 at 4:14
1 Answer 1
This isn't a perfect answer but it's the best I could find.
Robin2 on the Arduino Forum has written a good article on serial comms best practices and a demo of how to do communication between an Arduino and another computer running Python:
- Serial Input Basics - updated ( Apr 2016)
- Demo of PC-Arduino comms using Python (Mar 2014)
While not specific to operating LEDs, I found these resources very useful in writing my own code.
-
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.03/23/2025 00:47:17Commented Mar 23 at 0:47
-
@CommunityBot This answer provides two links to material that partially answers the question and a link to the author. I don't know any other way to cite web resources other than the URL, the author, and the date.Bill– Bill03/23/2025 00:52:22Commented Mar 23 at 0:52
-
For anyone interested, I've now written updated Python 2 and 3+ versions of these scripts and published them here: github.com/billtubbs/pyserial-examples/tree/main/robin2_demoBill– Bill04/05/2025 21:00:42Commented Apr 5 at 21:00