Sending Serial Data to Led Matrix

Hi Everyone,

I’m stuck in my program, I want to display a fixed text on a adafruit LED matrix (16x32) except if send something over the serial1. Then I have to see the data over the serial1. (I also resend it to the serial just to verify)
This works flowless except that my data over the serial is not remembered, it fills the buffer and then immediately removes the buffer, is there a way to keep the buffer for about 5 seconds or keep the serial available for more than the fraction of time.

#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

// Similar to F(), but for PROGMEM string pointers rather than literals
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 11  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2


char inByte[11];
int running1;

// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:

const char string[] PROGMEM = "1-WWW-WWW";
int    textX   = matrix.width(),
       textMin = sizeof(string) * -10,
       hue     = 0;

 
void setup() {
  Serial1.begin(9600);
  Serial.begin(9600);  
  matrix.begin();    
  matrix.setTextWrap(false); // Allow text to run off right edge  
}



void loop() {  
 // witte achtergrond
 //matrix.fillScreen(0xffff);
 // Clear background
 // matrix.fillScreen(0);
  
  // read from port 1
  if (Serial1.available() > 0 ) {
  Serial1.readBytesUntil('\n',inByte, 10);
  Serial.write(inByte);
  running1=1;
  }
  else{
  running1=0;
  }

  if (running1 > 0) { 
  matrix.fillScreen(0xffff);
  matrix.setTextSize(2);   
  matrix.setCursor(textX, 1);   // start at top left, with one pixel of spacing
  matrix.setTextColor(matrix.Color333(7,0,0));
  matrix.print(inByte);
  delay(35);
  }
  
  if (running1 <=0) {
   // Clear background
  matrix.fillScreen(0);  
  matrix.setTextSize(1); 
  matrix.setCursor(textX, 0);   // start at top left, with one pixel of spacing
  matrix.setTextColor(matrix.Color333(7,0,7));
  matrix.print("  WELCOME");
  matrix.setCursor(textX, 8);
  matrix.setTextColor(matrix.Color333(7,0,0));
  //  matrix.print(F2(string));
  matrix.print("DRIVETROUGH");
  delay(35);  
  }  

  // Move text left (w/wrap)
  if((--textX) < textMin) textX = matrix.width();
  matrix.swapBuffers(false);

}

If you want to keep ot, don't just send it and thow it away. Save it in a string (array of char). Once you have what you need to send, send it from the string.

lar3ry: If you want to keep ot, don't just send it and thow it away. Save it in a string (array of char). Once you have what you need to send, send it from the string.

Hi,

I understand that but how do I do that? At this point I already save the string into a "char" but it removes after I received it on the display.

Pc_Repair:

lar3ry: If you want to keep ot, don't just send it and thow it away. Save it in a string (array of char). Once you have what you need to send, send it from the string.

I understand that but how do I do that? At this point I already save the string into a "char" but it removes after I received it on the display.

  1. You don't save the stringg into a char. You save it into char[], which is am array of char.
  2. "it" doesn't remove anything. You are telling it to overwrite inbyte[] on the next iteration of loop()

When you gather your string, save it to another variable -another char[], using strcpy-, or wait until you don't need inbyte[] any more. It is then safe to overwrite inbyte[].