32x16 LED matrix commanded by Ethernet shield - issue

Hi all,

I am not a programmer so forgive me my mistakes and errors…

I am trying to set a text to be scrolled constantly (until new one is set) on a 32x16 RGB LED matrix. I am using an Arduino Mega and an Arduino Ethernet shield to set the new text I would like to be scrolled on the LED matrix.

I can see that I am able to get the proper string of characters in the Serial monitor, but I have the feeling that the matrix loop has the string empty and does not want to update it with the new one. I am posting my code, please take a look… i will be happy on some feedback.

#include <Ethernet.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>

#define CLK 53
#define LAT A5
#define OE 9
#define A A2
#define B A3
#define C A4

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //if need to change the MAC address (Very Rare)
//byte ip[] = { 192, 168, 0, 149 }; //Manual setup only
//byte gateway[] = { 192, 168, 1, 1 }; //Manual setup only
//byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
EthernetServer server = EthernetServer(80); //port 80
char StringOne[32];
char StringTwo[32];
//char StringThree[32];
int StringPos = 0;
boolean reading = false;
int textX = matrix.width();

void setup()
{
 Serial.begin(9600);
 Ethernet.begin(mac);
 //Ethernet.begin(mac, ip, gateway, subnet); //for manual setup
 server.begin();
 Serial.println(Ethernet.localIP());
 matrix.begin();
 matrix.setTextWrap(false); // Allow text to run off right edge
 matrix.setTextSize(2);
}

void loop()
{
 EthernetClient client = server.available();
 if (client)
 {
  boolean currentLineIsBlank = true;
  StringPos = 0;
   memset( &StringOne, 0, 32 );
  while (client.connected())
  {
   if (client.available())
   {
    char c = client.read();
    if(reading && c == ' ') reading = false;
    if(c == '?') reading = true;
    if(reading)
    {
     StringOne[StringPos] = c;
     StringPos ++;
    }
    if (c == '\n' && currentLineIsBlank) break;
    if (c == '\n')
    {
     currentLineIsBlank = true;
    }
    else if (c != '\r')
    {
     currentLineIsBlank = false;
    }
   }
  }
  delay(1); // give the web browser time to receive the data
  client.stop(); // close the connection:
  String StringTwo = StringOne;
  StringTwo.replace("%20", " ");
  StringTwo.replace("?", "");
  Serial.println(StringTwo);
 }
 else
 {
  rgbmatrix();
 }
}

void rgbmatrix()
{
 int textMin = sizeof(StringTwo) * -12;
 // Set speed
 matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 0, 0));
 delay(10);
 // Draw big scrolly text on top
 matrix.setTextColor(matrix.Color333(255, 0, 0));
 matrix.setCursor(textX, 1);
 matrix.print(StringTwo);
 // Move text left (w/wrap)
 if((--textX) < textMin) textX = matrix.width();
 // Update display
 matrix.swapBuffers(false);
}

Thank you in advance!

Isn't Pin 53 one of the SPI interface pins used to talk to the Ethernet Shield? That could be a conflict if you are using it for the LED matrix.

Thanks John,

I further dug in and found that : http://shieldlist.org/arduino/ethernet-v5

Does that mean that I have to keep them separate (the Mega and the shield)? If I can keep them together (stacked) which pins I may use as CLK for the LED matrix?

Thanks.

According to https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/wiring-the-16x32-matrix the recommended wiring for the 16x32 matrix on a MEGA appears to be:
R1 goes to digital 24
G1 goes to digital 25
B1 goes to digital 26
R2 goes to digital 27
G2 goes to digital 28
B2 goes to digital 29
CLK goes to digital 11
OE goes to digital 9
A goes to analog 0
B goes to analog 1
C goes to analog 2
LAT goes to analog 3

It looks like A0 and A1 are used by the Ethernet shield so using A2, A3, A4, and A5 instead makes sense.

Even though your posts were not the answer to my original question - Thank you! (since you are the only one from many who decided to say something at least)

I played more with the structure of my code a bit and made it work. It is good enough for now and i made it work with any length strings.

Angel

Hello Angel09, Can you please post your final code that works.

Thanks