Pages: [1]   Go Down
Author Topic: serail read problem -> Arduiono NT -> TLC5940  (Read 472 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am new to the arduino forum so firstly HELLO.

I have been experimenting with the Arduino NT Board an a TLC5940 NT chip.I am not a realy experienced user of arduino syntax and I have come up with a problem with the Serial.read() function. I have done a lot of search but couldn't find any relavant info. Maby someone can please hepl me.

I used the TLC Libary --> example "Serial". Everything works when i send DEC Numbers But then I send an ASCII Code from VVVV and tryed to read this as an integers (not char) at the arduino serial port. And now the the Arduino bord do`s nohing any more smiley-sad

these are the part`s i change:

#define SET_COMMAND      '115'             // befor `s`
#define COMMAND_ARG_DELIMITER      '44'      // befor `,`

and

void loop()
{
      if (Serial.available()) {
            if (serialBufferSize < MAX_LINE_LENGTH) {
                  int c = Serial.read();                  // befor "char"
                  Serial.print(c);
                  if (c == ' ') {
                        Serial.println();
                        doSet();
                        serialBufferSize = 0;
                  } else {
                        serialBuffer[serialBufferSize++] = c;
                  }
            } else {
                  serialBufferSize = 0;
            }
      }
}

--> I hope someone knows!!!

Here is the code.



#include <TLC5940LED.h>

#define NUM_TLCS      1

#define MAX_LINE_LENGTH      200
#define SET_COMMAND      '99'
#define COMMAND_ARG_DELIMITER      '32'

char serialBuffer[MAX_LINE_LENGTH];
uint8_t serialBufferSize = 0;

bool isNumber(char c)
{
      return c >= '0' && c <= '9';
}

uint16_t parseDec(char *cpStart, char *cpEnd)
{
      uint16_t result = 0;
      uint16_t ten = 1;
      for (char *cp = cpEnd - 1; cp >= cpStart; cp--) {
            char c = *cp;
            if (isNumber(c)) {
                  result += ((*cp) - '0') * ten;
                  ten *= 10;
            }
      }
      return result;
}

void doSet()
{
char *cp = serialBuffer;
if (*cp == SET_COMMAND)
  {
   cp++;
   char *cpEnd = cp;
   while (cpEnd < serialBuffer + serialBufferSize && *cpEnd != COMMAND_ARG_DELIMITER)
        {
      cpEnd++;
        }
        //Channels Read
      uint8_t channel = parseDec(cp, cp + 1);        //Channel --> 1 - 16
        
        //uint8_t b = (uint8_t) cpEnd*;
        //uint8_t a = (uint8_t) cp*;
        
        //End Values Read
      uint16_t Evalue_0 = parseDec(cpEnd + 1, cpEnd + 3);    //E_1
        uint16_t Evalue_1 = parseDec(cpEnd + 3, cpEnd + 5 );   //E_2
        uint16_t Evalue_2 = parseDec(cpEnd + 5, cpEnd + 7);    //E_3
        uint16_t Evalue_3 = parseDec(cpEnd + 7, cpEnd + 9);    //E_4
        uint16_t Evalue_4 = parseDec(cpEnd + 9, cpEnd + 11);   //E_5
        uint16_t Evalue_5 = parseDec(cpEnd + 11, cpEnd + 13);  //E_6
        uint16_t Evalue_6 = parseDec(cpEnd + 13, cpEnd + 15);  //E_7
        uint16_t Evalue_7 = parseDec(cpEnd + 15, cpEnd + 17);  //E_8
        uint16_t Evalue_8 = parseDec(cpEnd + 17, cpEnd + 19);  //E_9
        uint16_t Evalue_9 = parseDec(cpEnd + 19, cpEnd + 21);  //E_10
        uint16_t Evalue_10 = parseDec(cpEnd + 21, cpEnd + 23); //E_11
        uint16_t Evalue_11 = parseDec(cpEnd + 23, cpEnd + 25); //E_12
        uint16_t Evalue_12 = parseDec(cpEnd + 25, cpEnd + 27); //E_13
        uint16_t Evalue_13 = parseDec(cpEnd + 27, cpEnd + 29); //E_14
        uint16_t Evalue_14 = parseDec(cpEnd + 29, cpEnd + 31); //E_15
        uint16_t Evalue_15 = parseDec(cpEnd + 31, cpEnd + 33); //E_16
        //Start Values Read
        uint16_t Avalue_0 = parseDec(cpEnd + 33, cpEnd + 35); //A_1
        uint16_t Avalue_1 = parseDec(cpEnd + 35, cpEnd + 37); //A_2
        uint16_t Avalue_2 = parseDec(cpEnd + 37, cpEnd + 39); //A_3
        uint16_t Avalue_3 = parseDec(cpEnd + 39, cpEnd + 41); //A_4
        uint16_t Avalue_4 = parseDec(cpEnd + 41, cpEnd + 43); //A_5
        uint16_t Avalue_5 = parseDec(cpEnd + 43, cpEnd + 45); //A_6
        uint16_t Avalue_6 = parseDec(cpEnd + 45, cpEnd + 47); //A_7
        uint16_t Avalue_7 = parseDec(cpEnd + 47, cpEnd + 49); //A_8
        uint16_t Avalue_8 = parseDec(cpEnd + 49, cpEnd + 51); //A_9
        uint16_t Avalue_9 = parseDec(cpEnd + 51, cpEnd + 53); //A_10
        uint16_t Avalue_10 = parseDec(cpEnd + 53, cpEnd + 55);//A_11
        uint16_t Avalue_11 = parseDec(cpEnd + 55, cpEnd + 57);//A_12
        uint16_t Avalue_12 = parseDec(cpEnd + 57, cpEnd + 59);//A_13
        uint16_t Avalue_13 = parseDec(cpEnd + 59, cpEnd + 61);//A_14
        uint16_t Avalue_14 = parseDec(cpEnd + 61, cpEnd + 63);//A_15
        uint16_t Avalue_15 = parseDec(cpEnd + 63, cpEnd + 65);//A_16
        
        
        //Set Fades
        // Tamplet --> newFade(uint8_t channel, uint16_t duration, int16_t startValue, int16_t endValue, uint32_t startMillis)
      Tlc.newFade(channel, 3000, Avalue_0, Evalue_0, millis() + 0);  //1
        channel++;
        Tlc.newFade(channel, 3000, Avalue_1, Evalue_1, millis() + 0);  //2
        channel++;
        Tlc.newFade(channel, 3000, Avalue_2, Evalue_2, millis() + 0);  //3  
        channel++;
        Tlc.newFade(channel, 3000, Avalue_3, Evalue_3, millis() + 0);  //4
        channel++;
        Tlc.newFade(channel, 3000, Avalue_4, Evalue_4, millis() + 0);  //5
        channel++;
        Tlc.newFade(channel, 3000, Avalue_5, Evalue_5, millis() + 0);  //6  
        channel++;
        Tlc.newFade(channel, 3000, Avalue_6, Evalue_6, millis() + 0);  //7
        channel++;
        Tlc.newFade(channel, 3000, Avalue_7, Evalue_7, millis() + 0);  //8
        channel++;
        Tlc.newFade(channel, 3000, Avalue_8, Evalue_8, millis() + 0);  //9
        channel++;
        Tlc.newFade(channel, 3000, Avalue_9, Evalue_9, millis() + 0);  //10
        channel++;
        Tlc.newFade(channel, 3000, Avalue_10, Evalue_10, millis() + 0);  //11
        channel++;
        Tlc.newFade(channel, 3000, Avalue_11, Evalue_11, millis() + 0);  //12
        channel++;
        Tlc.newFade(channel, 3000, Avalue_12, Evalue_12, millis() + 0);  //13
        channel++;
        Tlc.newFade(channel, 3000, Avalue_13, Evalue_13, millis() + 0);  //14
        channel++;
        Tlc.newFade(channel, 3000, Avalue_14, Evalue_14, millis() + 0);  //15
        channel++;
        Tlc.newFade(channel, 3000, Avalue_15, Evalue_15, millis() + 0);  //16
        while (Tlc.updateFades()); // this will run until all the fades are done
        Tlc.clear();
        Tlc.update();
    }
    else if (*cp == 'c')
    {
    Tlc.clear();
    Tlc.update();      
    }
    else
    {
    Serial.println("Set syntax= s1,4095{space}");
    }

}

void setup()
{
      Serial.begin(115200);
      Serial.println("Set syntax= s1,4095{space}");
      Tlc.init(NUM_TLCS, 32); // --> more than about 40 and the ram run out of space
      Tlc.resetTimers();
}

void loop()
{
      if (Serial.available()) {
            if (serialBufferSize < MAX_LINE_LENGTH) {
                  int c = Serial.read();
                  Serial.print(c);
                  if (c == ' ') {
                        Serial.println();
                        doSet();
                        serialBufferSize = 0;
                  } else {
                        serialBuffer[serialBufferSize++] = c;
                  }
            } else {
                  serialBufferSize = 0;
            }
      }
}



Logged

Seattle, WA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 81
Arduino rocks my socks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What exactly are you trying to do with the TLC library?  The serial example wasn't really meant for full control of the TLC5940.  Have you used Firmata before?  I think I could get the TLC Library talking with Firmata.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

acleone: Did you ever get the TLC library working through Firmata?  I would be interested in seeing that.  Thanks!
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, would be interesting!
Logged

Pages: [1]   Go Up
Jump to: