Hey all,
I've been working on and off for a loong time trying to get Jitter talking to my arduino, specifically to drive the LEDs on my TLC5940 shield.
I've just recently been able to get it working, though at horrendous frame rates. 33fps works for a little, then gives tons of quick blackouts, pulses of unlimited current, quick hangs and then an inevitable freeze. The RX light is still on however. Resetting the serial port in max restarts the process. 2fps is relatively stable, but will still blackout every now and again, then freeze.
I made a project a while ago (solely using arduino) using an accelerometer to drive functions that set the LEDs to new values in a disgustingly inefficient manner, with little difficulty, and it ran for a week non stop. Also all the code examples in the library are working of course.
I cannot for the life of me figure out what the bottleneck is. I know it's not the baud rate, and i've seen other projects using essentially the same SPI protocol as the TLC library on an atmegaXX8 to drive 16 x 16 grids. Anyway, here's my code, adapted from (http://arduino.cc/forum/index.php/topic,69403.0.html)
#include "Tlc5940.h"
#define FRAME_START 255
#define FRAME_END 254
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};
int i = 0;
void setup(){
Serial.begin(115200);
Tlc.init();
}
void rxComplete(){
//the shield is using one TLC per color (in series), 16 channels a piece.
for (int r=0; r < 16; r++){
Tlc.set(r, buffer[r]);
}
for (int g=16; g < 32; g++){
Tlc.set(g, buffer[g]);
}
for (int b=32; b < 48; b++){
Tlc.set(b, buffer[b]);
}
}
void loop(){
if(Serial.available() > 0){
byte rxbyte = Serial.read();
if(rxbyte == FRAME_START){
i = 0;
while(Serial.peek() < FRAME_END){
while(Serial.available() < 2) delayMicroseconds(1);
buffer[i++] = Serial.read();
}
Serial.flush();
rxComplete();
}
}
Tlc.update();
}
is it something to do with the serial.flush? i couldn't exactly figure it out, but should I be using the other functions of the library to deal with the XLAT? Or is the amount of utilized SRAM in the arduino bogging everything down?
oh and i'm only using 253 / 4095 steps, and ive been able to get near full brightness (4095) on all channels with cmdmessenger without causing a power draw reset.
I've looked at a lot of different protocols, my favorite being the Adavision LEDstream.pde, but I can't wrap my head around most of it. I feel like it does everything I want it to (underrun protection, checksum matching, avoiding loop) but i realize baby steps are the way to go, I don't know much about all the SPI stuff and using PORTB.
I've also had a look at grumpy_mike's projects with the 5940 but the multiplexing puts it wayy over my head. No time like the present to learn though, I'm sure it'd help a ton with scalability, which is the ultimate goal.
I've been looking for a way to do this for ages (well, a year or so), any help is greatly appreciated!
best,
z