I’m working on making an LED matrix display, using a 576 LED strip (18x32), and eventually I will want to use serial communication in order to get weather information to show on the display. I’m learning how serial communication works at the moment, and came across Serial Input Basics - updated which was very helpful. I believe I have the basic concept down, but when I take the third example and use it in my own code, I can only get the Arduino to return the string if I send it one character at a time. For instance, sending “” gives me nothing, but if I send that same thing one letter at a time, it returns properly.
I’ve narrowed this down to running the led_Strip.write() during the loop of my sketch. Because of this, I believe that my issue is because of the arduino taking too long to write 576 LED lights and not being available for the entire string. That doesn’t make too much sense to me though, because as I understand it the arduino has a buffer to hold the information sent over serial, which would then still be available for the arduino when it is finished with the led_Strip.write().
I’ve included the relevant code. I did not write the recWithStartEnd() or the printNewData() functions, I took them straight from the page linked above.
#include <PololuLedStrip.h>
PololuLedStrip<12> ledStrip;
#define LED_COUNT 576
rgb_color colors[LED_COUNT];
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Doing something");
}
void loop() {
// put your main code here, to run repeatedly:
ledStrip.write(colors, LED_COUNT); //If this line is commented out, the program runs as expected
recvWithStartEndMarkers();
printNewData();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void printNewData(){
if (newData == true){
Serial.println("This just in: ");
Serial.println(receivedChars);
newData = false;
}
}
Since I think I have found the problem, can anyone say why the buffer is not saving the information until the arduino is ready for it? Is there any way to have the arduino get the information from serial while it is writing to the LED strip? I’m not overly concerned about the refresh rate on the LEDs, but I would like it to update at least a few times per second. Thank you for any help, and if there’s any questions I can answer to make it easier to help me, please let me know.
I’m using an Arduino Due, WS2812b LED strips, and nothing else at the moment. I’m connecting to the programming USB port on the arduino, and I’m running Linux mint on my computer, if any of that helps.