Arduino read txt file and display to LED matrix

Hello,
I need my Arduino to read strings from a text file (stored in my computer) which will then be displayed on an LED matrix.
This is a part of a larger application in which Processing saves strings into a text file from a user's input.

This is the code I'm currently working on—adapted from the scrolltext demo for Adafruit RGBmatrixPanel library.
I want to replace the pre-assigned text—as in const char str[] PROGMEM = "text to be displayed"; —with strings from a .txt file.

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

#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 8 
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);

const char str[] PROGMEM = "text goes here";
int    textX   = matrix.width(),
       textMin = sizeof(str) * -12,
       hue     = 0;

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

void loop() {
  byte i;

  matrix.fillScreen(0);
  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(F2(str));
  
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  matrix.swapBuffers(false);
}

Strings from a *.txt file on the computer, not a *.txt file on a SD card on the Arduino. Right ?

You can use the serial port for that. Have you tried sending messages with the serial port ?

I have but what I want to do is a real-time interaction.
Here's I want to do:

  1. A phrase is typed onto a Processing program, which saves it into a .txt file
  2. The Arduino reads the phrase from the .txt file (Arduino is hooked up to my computer via USB, which is where the file is stored.)
  3. Arduino displays the phrase onto the LED matrix

Since the contents of the .txt file are constantly being updated (a new phrase replaces the previous one), saving it into an SD card or hard-coding the strings would not help.

I'm quite a beginner in this and I cannot seem to get my head around it.
After setting up the serial communication, how do I make Arduino read from this specific file?
I've read the String, Read and Serial documentation but can't seem to find the answer.

Any guidance will be greatly appreciated!

Hi, The Arduino cannot open a file on the pc and read from it. Your Processing code needs to do that, and send the string to the Arduino through the serial line. The Arduino would need to detect that a new string is being sent very fequently so that the first character is not missed. It must do this while continuing to multiplex the display.

Right now, the string being displayed cannot be changed except when a sketch is uploaded. This is because it is declared "const" and the keyword "PROGMEM" indicates it is to be stored in the Arduino's flash memory. This all needs to change so that the the string is stored in the Arduino's RAM. Make it the largest size of any message you might need to display, but remember that Arduino's ram is very limited and we don't know how much the Adafruit library uses.

In loop(), your sketch needs to check if a new string is being sent by the pc using Serial.available(). It would then read the new string into the variable in RAM, one character at a time, and record its length.

Paul