Alright, i've received the shield yesterday so today i started coding. it works as i wanted so far but i get only about 16 frames/sec. does anyone have suggestions to optimize my serial interface?
the frame of 192 pixels is split in half so that each half fits in arduino rx buffer
START_TOP_FRAME is byte(254)
START_BTM_FRAME is byte(253)
FRAME_HALF_END is byte(255)
which means, i can use brightness values from 0 - 252.
the processing code woks as follows:
loop{
-send START_TOP_FRAME -> send raw 96 pixels of data -> send FRAME_HALF_END -> listen
-arduino sends back START_TOP_FRAME as ack that top half was received
-send START_BTM_FRAME -> send raw 96 pixels of data -> send FRAME_HALF_END -> listen
-arduino sends back START_BTM_FRAME as ack that bottom half was received
}
so far i have tried
- disabling the colorduino interrupt, which hasn't had any effect on the performance -> means that it's not the bottleneck
- at 57600 b/s transfer rate the framerate is pretty much the same, which excludes too slow serial
- the rxComplete function doesn't take much time either
which leaves me with the conclusion that the raw code in the loop() function needs optimizing. Or maybe another totally different approach? maybe compression of some sorts?
i'll be really glad about any advice!
#include <Colorduino.h>
unsigned char buffer[] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251,251};
int i = 0;
void setup(){
Serial.begin(115200);
Colorduino.Init(); // initialize the board
unsigned char whiteBalVal[3] = {34,63,63}; // for LEDSEE 6x6cm round matrix
Colorduino.SetWhiteBal(whiteBalVal);
}
void rxComplete(){
for(int i = 0; i<8; i++){
for(int j = 0; j<8; j++){
Colorduino.SetPixel(i, j, buffer[i*3*8+j*3+0], buffer[i*3*8+j*3+1], buffer[i*3*8+j*3+2]);
}
}
Colorduino.FlipPage();
}
#define FRAME_TOP_START 254
#define FRAME_BTM_START 253
#define FRAME_HALF_END 255
void loop(){
byte rxbyte = Serial.read();
switch(rxbyte){
// beginning of top half
case FRAME_TOP_START: {
i = 0;
//while not end of half-frame
while(Serial.peek() < FRAME_HALF_END){
while(Serial.available() < 2) delay(1);
buffer[i++] = Serial.read();
}
Serial.flush();
Serial.write(FRAME_TOP_START);
break;
}
// beginning of bottom half
case FRAME_BTM_START: {
i = 96;
//while not end of half-frame
while(Serial.peek() < FRAME_HALF_END){
while(Serial.available() < 2) delay(1);
buffer[i++] = Serial.read();
}
Serial.flush();
Serial.write(FRAME_BTM_START);
rxComplete();
break;
}
}
}