I tried to use two Wiring boards. First one is connected to Xport and the second is connected to RGB Led matrixes.
First one receives data perfectly and prints it through the serial port. Second receives data perfectly if I comment out the writeMatrix() function.
So the problem is, writeMatrix() function in the RGB Led Matrix code doesn't let the board to get consistent data from the serial connection.
Any ideas to solve this?I modified the RGB Led Matrix code so it is lighter now. Here is the code:
Code:#include <String.h>
String buffer = String(""); // buffer to read data from xport
String buff = String("");
char toShow[768];
int m = 0;
int ready = 1; // used to mark when we have a complete string to process
int val; // use to read a byte from the serial
int newline = 1;
// RGB Matrix pins
int clock = 9;
int data = 8;
int cs[12] = {
15,14,37,36,31,30,29,28,27,26,25,24};
// RGB Matrix variables
int bits[8] = {
128, 64, 32, 16, 8, 4, 2, 1 };
// Diagnostics
void setup() {
Serial1.begin(9600);
//RGB Matrix setup
matrixInit();
// Diagnostics
Serial.begin(9600);
Serial.println("Setup");
//arrayDiagnostic();
}
void loop() {
lookForData();
// RGB Matrix loop
//arrayRandom();
//writeMatrix();
}
/*
Read the results sent by the server until you get a < character.
*/
void lookForData() {
while(Serial1.available() > 0) { // if data vailable from the weather board
val = Serial1.read(); // read it
//Serial.print(val);
if((val != '\n' && ready == 1)) { // if no end of line
toShow[m] = char(val);
Serial.print(toShow[m]);
m++;
//buffer.append(char(val));
//Serial.println("test");
//Serial.print(buffer);
}
else { // if end of line reached, ready to parse the buffer
ready = 1;
m = 0;
break;
}
} /*
if(ready == 4) {
Serial.println("test1");
toShow = buffer.toCharArray();
buffer = String("");
ready = 1;
}*/
//writeMatrix();
}
// --------------------
// RGB Matrix Functions
void matrixInit()
{
pinMode(clock, OUTPUT); // sets the digital pin as output
pinMode(data, OUTPUT);
for(int display = 0;display <12;display++) //Running through each display (0 and 1)
{
pinMode(cs[display], OUTPUT);
}
}
void writeByte(byte myByte, int display) //prints out bytes. Each colour is printed out.
{
for (int b = 0; b < 8; b++) { //converting it to binary from colour code.
digitalWrite(clock, LOW);
if ((myByte & bits[b]) > 0)
{
digitalWrite(data, HIGH);
}
else
{
digitalWrite(data, LOW);
}
digitalWrite(clock, HIGH);
delayMicroseconds(10);
digitalWrite(clock, LOW);
}
}
void writeMatrix()
{
for(int d = 0;d <12;d++)
{
digitalWrite(clock, LOW); //sets the clock for each display, running through 0 then 1
digitalWrite(data, LOW); //ditto for data.
delayMicroseconds(10);
digitalWrite(cs[d], LOW); //ditto for cs.
delayMicroseconds(10);
for(int x = 0; x < 8;x++)
{
for (int y = 0 ; y < 8;y++)
{
writeByte(toShow[(d*64)+(x*8)+y], d); //Drawing the grid. x across then down to next y then x across.
delayMicroseconds(10);
}
}
delayMicroseconds(10);
digitalWrite(cs[d], HIGH);
}
}