I am having an issue with missing serial data whilst using this code:
void loop()
{
while (Serial.available()) {
buffChar = Serial.read();
Serial.print(int(buffChar));
Serial.print(",");
//if it's not a newline then add to buffer
if (buffChar != byte(255)) {
buff[buffPos%sizeof(buff)] = buffChar;
buffPos++;
}
else {
//detect newline to end update
//clear leds
memset(leds, 0, sizeof(leds));
//overwrite leds with buffer
memcpy(leds, buff, sizeof(leds));
//clear buffer and reset position
memset(buff, 0, sizeof(buff));
Serial.println(buffPos);
buffPos = 0;
FastLED.show();
}
}
}
It works fine most of the time but every 20 or 30 “packets” it gets confused and “ends” the packet early.
I’m using this to send the serial:
import serial, time
ser = serial.Serial('/dev/tty.usbmodem000001', 115200)
for x in range(0,24):
for b in range(0, 64):
packet = bytearray()
for led in range(0, 4):
packet.append(b)
packet.append(b)
packet.append(b)
packet.append(64)
packet.append(32)
packet.append(32)
packet.append(255)
for p in packet: print(p, ",", end="")
print("packet length: ", len(packet))
ser.write(packet)
time.sleep(0.05)
ser.close()
Just look in 