RGB support w/ sparkfun backpack

2008-08-15
2013-04-26
  • Julien Bayle
    Julien Bayle
    2008-08-15

    Jordan, Owen, Ben,

    you all three know that I'm working on rgb support w/ an hijacked sparkfun backpack (serial spi + rgb led drivers interface)

    I just would like to begin a thread about that for those who are interested.

    I have this code, from Brian Durocher, that works fine:

    __________________________________________________________________________
    //Brian Durocher (c) 2008
    //This code is under the GPL use as you wish just remember to credit your sources.
    //
    //Some parts borrowed from the arduinoplayground.cc

    /**#define CHIPSELECT 13//Chip Select Line
    #define SPICLOCK 11 //Master Clock
    #define DATAOUT 10   //DataOut to DataIn on Backpack
    #define DATAIN 12    //DataIn from DataOut on Backpack

    #define 164CLK 3 //clock for LS164
    #define 164A   4 //shift in A

    #define 165CLK 5 //clock for LS165
    #define 165A   6 //
    #define 165B   7//r*/

    //simple array for data frames - you can use 0-3 for the color settings on the RG display or 0-7 for the RGB Matrixs//
    int databuffer[4][8][8] ={
     
    {{0,0,1,1,0,1,1,0},
      {0,1,0,0,1,0,0,1},
      {0,1,0,0,0,0,0,1},
      {0,1,0,0,0,0,0,1},
      {0,0,1,0,0,0,1,0},
      {0,0,0,1,0,1,0,0},
      {0,0,0,0,1,0,0,0},
      {0,0,0,0,0,0,0,0}},
     
    {{0,0,0,0,0,0,0,0},
      {0,0,0,1,0,1,0,0},
      {0,0,1,0,1,0,1,0},
      {0,0,1,0,0,0,1,0},
      {0,0,0,1,0,1,0,0},
      {0,0,0,0,1,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,1,0,1,0,0},
      {0,0,0,1,1,1,0,0},
      {0,0,0,0,1,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,1,0,1,0,0},
      {0,0,1,0,1,0,1,0},
      {0,0,1,0,0,0,1,0},
      {0,0,0,1,0,1,0,0},
      {0,0,0,0,1,0,0,0},
      {0,0,0,0,0,0,0,0},
      {0,0,0,0,0,0,0,0}}

      } ;

    int z=0;

    // SPI data load / transfer function - thanks Heather Dewey-Hagborg //
    char spi_transfer(volatile char data)
    {
      SPDR = data;                    // Start the transmission
      while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
      {
      };
    }

    void clearDisplay() {
       for (int i=0;i<8;i++) for (int j=0;j<8;j++)
        { spi_transfer( 0 ); }
        delay(50);  
    }

    void setup()
    {
      #define CHIPSELECT 13//Chip Select Line
    #define SPICLOCK 11 //Master Clock
    #define DATAOUT 10   //DataOut to DataIn on Backpack
    #define DATAIN 12    //DataIn from DataOut on Backpack

      //random number
      long randNumber;
      byte clr;
      pinMode(DATAOUT,OUTPUT);
      pinMode(SPICLOCK,OUTPUT);
      pinMode(CHIPSELECT,OUTPUT);
      digitalWrite(CHIPSELECT,HIGH); //disable device
      randomSeed(analogRead(0));

      SPCR = B01010001;             //SPI Registers
      SPSR = SPSR & B11111110;      //make sure the speed is 125KHz

      clr=SPSR;
      clr=SPDR;
      delay(10);
      clearDisplay();
    }

    void loop()           
    {
        int z=0;
        //loop though frames #4 //
        for (int z=0;z<4;z++) {
        delay(100);                   
        digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect
        delayMicroseconds(500);

           for (int i=0;i<8;i++) {
           for (int j=0;j<8;j++) {
           spi_transfer( databuffer[z][i][j] );        
           }
           }

        digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect
        delayMicroseconds(500);
       
        }
        for(int o=0 ; o<4 ; o++){
         
          for(int p=0 ; p<8 ; p++){
           
            for(int q=0 ; q<8 ; q++){
              //matrix data write
              databuffer[o][p][q] = random(0, 7);
            }
          }
         
        }
        delay(100);
    }
    __________________________________________________________________________

    I'd like to include it in 3.1.1 code.
    I have some conceptual problems.
    indeed, I want to keep performance as high as possible (as you did!!)

    Could someone help me to find the patch to follow ??
    I guess I should keep interrupt routine etc.. but I don't want to overload it.

    cheers,
    julien

     
    • Ben Southall
      Ben Southall
      2008-08-15

      Hi Julien,

      The way that the firmware works is that the interrupt routine simply gathers information from the serial port and remembers the results of the instructions that are being fed in.

      The code in the main loop function is responsible for actually updating the LEDs.  So in your case, the part that uses SPI to update the LED matrix would be called from that main loop.

       
    • Julien Bayle
      Julien Bayle
      2008-08-15

      Ok.
      I guess I have to maintain 3 tables, one for each color
      1 the serial message received, responsible on on/off of each leds, will be parsed and update the tables
      2 the loop contains the matrix update code based on the tables

      am i right?

      I just would like to implement it without alter the main structure/functions of your code for using your next release easily with mine..

      cheers

       
    • Ben Southall
      Ben Southall
      2008-08-16

      That looks about right to me.

      ben

       
    • Julien Bayle
      Julien Bayle
      2008-08-24

      Hello,

      ok to control the backpack:
      - via spi
      - with modified arduinome firmware
      - monochrome for the moment
      - 40h

      no flickering, fast & stable (it is based on the coolest code in the world: arduinome code :)

      it could be another "branch" using spi backpack hardware as rgb led driver

      TODO:
      - ledcolumn + ledrow support
      - intensity/test etc
      - rgb support (this part will be done when the protocol will be modified to be "series" compliant)

       
    • Johan Larsby
      Johan Larsby
      2008-08-24

      Awesome man.

      I've actually done some of the coding I talked about in https://sourceforge.net/forum/forum.php?thread_id=2177751&forum_id=851429 so if you care to have a look contact me.

       
      • Julien Bayle
        Julien Bayle
        2008-08-24

        I have to finish the series support.

        after that, I'll have to add a message to the protocol:
        /rgb x y n  with n = (0 to 7)
        only 8 state available in the actual baclpack sparkfun firmware (but in the future, I may dive into it too to reprogram the atmega8... not my priority)

        it is a firmware / protocol dedicated to arduinome w/ spi backpack interface to drive RGB leds :)

        we could talk about that via email if you're interested

        cheeers