paniclemur
Member
I'm working on a project with OctoWS2811 and a Teensy 4.1. I have a LED matrix running using 32 separate pins as outputs, each with a strip length of 300 LEDs.
I'm sending packets of data over USB to the Teensy from a Python script on a Raspberry Pi in the following format:
{led number low byte, led number high byte, red, green, blue}
I'm using the follow to display the packets received:
Each frame is 5 * 32 * 260 bytes, so around 42kb (at 30 fps aroud 1248kb per second).
The problem I'm having is that the serial receiving element of the system always seems to hang after some amount of time. I.e. the loop() continues to run, but no longer receives any data. On the Python script, the sending serial port will no longer accept any data, and just hangs when trying to write to it.
So I'm assuming some sort of low level crash where a buffer somewhere is being overwhelmed. Here's what I've tried without success:
Splitting each packet in two on the sending end
Sending each 5 byte group individually (too slow)
Introducing delays between sending packets (these end up slowing everything down too much)
Getting the Teensy to send a serial confirmation after every frame, and the Python script waiting for this to continue (this made everything incredibly slow)
Trying different BUFFER_LEN ranging from 100 to 50000
Increasing CDC_RX_SIZE_480 to 1024 in packages\teensy\hardware\avr\1.59.0\cores\teensy4\usb_desc.h
Different USB ports on Raspberry Pi
Different USB cables
I'm not really sure what else to try apart from just finding a way to reset the Teensy when the serial stops working (e.g. using GPIO pin, watchdog or cycling power to Teensy). Or whether this is just a totally unrealistic data rate to expect over USB and I should consider some other way of getting the data to the Teensy.
I'm sending packets of data over USB to the Teensy from a Python script on a Raspberry Pi in the following format:
{led number low byte, led number high byte, red, green, blue}
I'm using the follow to display the packets received:
Code:
#include <OctoWS2811.h>
#define BUFFER_LEN 50000
#define NUM_LEDS 300
char packetBuffer[BUFFER_LEN];
const int numPins = 32;
byte pinList[numPins] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 24, 25, 26, 27, 28, 22, 21, 20, 19, 18, 17, 16, 15, 41, 40, 39, 38, 37, 36, 35, 34 };
const int ledsPerStrip = NUM_LEDS;
const int bytesPerLED = 3; // change to 4 if using RGBW
DMAMEM int displayMemory[ledsPerStrip * numPins * bytesPerLED / 4];
int drawingMemory[ledsPerStrip * numPins * bytesPerLED / 4];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config, numPins, pinList);
int totalLeds = 0;
long lastTime;
bool ledOn;
uint16_t N = 0;
bool l = true;
int frame = 0;
void setup() {
Serial.begin(9600);
leds.begin();
leds.show();
pinMode(13, OUTPUT);
totalLeds = ledsPerStrip * numPins;
}
void loop() {
if (Serial.available() > 0) {
int len = Serial.readBytes(packetBuffer, BUFFER_LEN);
for (int i = 0; i < len; i += 5) {
packetBuffer[len] = 0;
N = ((packetBuffer[i] << 8) + packetBuffer[i + 1]);
if (N < totalLeds) {
leds.setPixel(N, (uint8_t)packetBuffer[i + 2], (uint8_t)packetBuffer[i + 3], (uint8_t)packetBuffer[i + 4]);
}
if (N == 0) {
leds.show();
frame++;
if (frame == 30) {
digitalWrite(13, l);
l = !l;
frame = 0;
}
}
}
}
}
Each frame is 5 * 32 * 260 bytes, so around 42kb (at 30 fps aroud 1248kb per second).
The problem I'm having is that the serial receiving element of the system always seems to hang after some amount of time. I.e. the loop() continues to run, but no longer receives any data. On the Python script, the sending serial port will no longer accept any data, and just hangs when trying to write to it.
So I'm assuming some sort of low level crash where a buffer somewhere is being overwhelmed. Here's what I've tried without success:
Splitting each packet in two on the sending end
Sending each 5 byte group individually (too slow)
Introducing delays between sending packets (these end up slowing everything down too much)
Getting the Teensy to send a serial confirmation after every frame, and the Python script waiting for this to continue (this made everything incredibly slow)
Trying different BUFFER_LEN ranging from 100 to 50000
Increasing CDC_RX_SIZE_480 to 1024 in packages\teensy\hardware\avr\1.59.0\cores\teensy4\usb_desc.h
Different USB ports on Raspberry Pi
Different USB cables
I'm not really sure what else to try apart from just finding a way to reset the Teensy when the serial stops working (e.g. using GPIO pin, watchdog or cycling power to Teensy). Or whether this is just a totally unrealistic data rate to expect over USB and I should consider some other way of getting the data to the Teensy.