Issues updating Colorduino V1.3 via I2C...

Hi There!

Recently got this Colorduino V1.3 for a 8x8 RGB LED Matrix.
95abafd736ad680d3537fece76e76451c2eecea4.jpg

11e7799af9d3fe0491a9d6bd827b0bc98875e79e.jpg

The module has

  1. pins DTR, GND, TXD, RXD, VDD, GND, SCL & SDA
  2. a reset button
  3. terminal/header selection switch, for powering the module
  4. without the onboard micro-usb (Had to use an Arduino UNO with the 328 chip removed to upload firmwares)

Uploaded this code directly to Colorduino V1.3 and this works:

#include <Colorduino.h>

typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} ColorRGB;

//a color with 3 components: h, s and v
typedef struct 
{
  unsigned char h;
  unsigned char s;
  unsigned char v;
} ColorHSV;

unsigned char plasma[ColorduinoScreenWidth][ColorduinoScreenHeight];
long paletteShift;


//Converts an HSV color to RGB color
void HSVtoRGB(void *vRGB, void *vHSV) 
{
  float r, g, b, h, s, v; //this function works with floats between 0 and 1
  float f, p, q, t;
  int i;
  ColorRGB *colorRGB=(ColorRGB *)vRGB;
  ColorHSV *colorHSV=(ColorHSV *)vHSV;

  h = (float)(colorHSV->h / 256.0);
  s = (float)(colorHSV->s / 256.0);
  v = (float)(colorHSV->v / 256.0);

  //if saturation is 0, the color is a shade of grey
  if(s == 0.0) {
    b = v;
    g = b;
    r = g;
  }
  //if saturation > 0, more complex calculations are needed
  else
  {
    h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations
    i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4
    f = h - i;//the fractional part of h

    p = (float)(v * (1.0 - s));
    q = (float)(v * (1.0 - (s * f)));
    t = (float)(v * (1.0 - (s * (1.0 - f))));

    switch(i)
    {
      case 0: r=v; g=t; b=p; break;
      case 1: r=q; g=v; b=p; break;
      case 2: r=p; g=v; b=t; break;
      case 3: r=p; g=q; b=v; break;
      case 4: r=t; g=p; b=v; break;
      case 5: r=v; g=p; b=q; break;
      default: r = g = b = 0; break;
    }
  }
  colorRGB->r = (int)(r * 255.0);
  colorRGB->g = (int)(g * 255.0);
  colorRGB->b = (int)(b * 255.0);
}

unsigned int RGBtoINT(void *vRGB)
{
  ColorRGB *colorRGB=(ColorRGB *)vRGB;

  return (((unsigned int)colorRGB->r)<<16) + (((unsigned int)colorRGB->g)<<8) + (unsigned int)colorRGB->b;
}


float
dist(float a, float b, float c, float d) 
{
  return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}


void
plasma_morph()
{
  unsigned char x,y;
  float value;
  ColorRGB colorRGB;
  ColorHSV colorHSV;

  for(y = 0; y < ColorduinoScreenHeight; y++)
    for(x = 0; x < ColorduinoScreenWidth; x++) {
      {
 value = sin(dist(x + paletteShift, y, 128.0, 128.0) / 8.0)
  + sin(dist(x, y, 64.0, 64.0) / 8.0)
  + sin(dist(x, y + paletteShift / 7, 192.0, 64) / 7.0)
  + sin(dist(x, y, 192.0, 100.0) / 8.0);
 colorHSV.h=(unsigned char)((value) * 128)&0xff;
 colorHSV.s=255; 
 colorHSV.v=255;
 HSVtoRGB(&colorRGB, &colorHSV);
 
 Colorduino.SetPixel(x, y, colorRGB.r, colorRGB.g, colorRGB.b);
      }
  }
  paletteShift++;
  Colorduino.FlipPage(); // swap screen buffers to show it
}

void ColorFill(unsigned char R,unsigned char G,unsigned char B)
{
  PixelRGB *p = Colorduino.GetPixel(0,0);
  for (unsigned char y=0;y<ColorduinoScreenWidth;y++) {
    for(unsigned char x=0;x<ColorduinoScreenHeight;x++) {
      p->r = R;
      p->g = G;
      p->b = B;
      p++;
    }
  }
  
  Colorduino.FlipPage();
}

void setup()
{
  Colorduino.Init(); // initialize the board
  unsigned char whiteBalVal[3] = {36,63,63}; // for LEDSEE 6x6cm round matrix
  Colorduino.SetWhiteBal(whiteBalVal);
  
  
  paletteShift=128000;
  unsigned char bcolor;

  for(unsigned char y = 0; y < ColorduinoScreenHeight; y++)
    for(unsigned char x = 0; x < ColorduinoScreenWidth; x++)
    {
      bcolor = (unsigned char)
      (
            128.0 + (128.0 * sin(x*8.0 / 16.0))
          + 128.0 + (128.0 * sin(y*8.0 / 16.0))
      ) / 2;
      plasma[x][y] = bcolor;
    }
}

void loop()
{
  plasma_morph();
}

So, I’m able to get the plasma pattern on the Colorduino V1.3, when written to the module directly. But while attempting to send information via I2C to be displayed, there are issues!

Now, I’m trying to send data to the Colorduino V1.3 from another microcontroller like Arduino UNO, via I2C. Tried the following code and I don’t see any activity on the Colorduino V1.3…

Arduino UNO Code (Master):

/*
  arduino I2C to Colorduino demo
   
  based on 
  -arduino firmware by michael vogt <michu@neophob.com>
  -blinkm firmware by thingM
  -"daft punk" firmware by Scott C / ThreeFN 
   
  libraries to patch:
  Wire: 
     utility/twi.h: #define TWI_FREQ 400000L (was 100000L)
                     #define TWI_BUFFER_LENGTH 70 (was 32)
    wire.h: #define BUFFER_LENGTH 70 (was 32)
 
  This DEMO is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This DEMO is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <Wire.h>

#define START_OF_DATA 0x10  //data markers
#define END_OF_DATA 0x20    //data markers
#define DEST_I2C_ADDR 0x1A  //set destination I2C address (must match firmware in Colorduino module)

#define SCREENSIZEX 8            //num of LEDs accross
#define SCREENSIZEY 8            //num of LEDs down

byte display_byte[3][64];        //display array - 64 bytes x 3 colours 

//setup for plasma
typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} ColorRGB;

//a color with 3 components: h, s and v
typedef struct 
{
  unsigned char h;
  unsigned char s;
  unsigned char v;
} ColorHSV;

unsigned char plasma[SCREENSIZEX][SCREENSIZEY];
long paletteShift;
 
void setup() 
{
  delay(3000);
  Wire.begin(6); // join i2c bus (address optional for master)  
  plasma_setup();   //plasma setup
}

void loop()
{
   plasma_morph();
}

//update display buffer using x,y,r,g,b format
void display(byte x, byte y, byte r, byte g, byte b) {
  byte p = (y*8)+x;   //convert from x,y to pixel number in array
  display_byte[0][p] = r;
  display_byte[1][p] = g;
  display_byte[2][p] = b;
}

//send display buffer to display 
void update_display(byte addr) {   
  BlinkM_sendBuffer(addr, 0, display_byte[0]);   
  BlinkM_sendBuffer(addr, 1, display_byte[1]);   
  BlinkM_sendBuffer(addr, 2, display_byte[2]);  
}

//send data via I2C to a client
static byte BlinkM_sendBuffer(byte addr, byte col, byte* disp_data) {
  Wire.beginTransmission(addr);
  Wire.write(START_OF_DATA);
  Wire.write(col);
  Wire.write(disp_data, 64);
  Wire.write(END_OF_DATA);
  return Wire.endTransmission();
}

//plasma convert
//Converts an HSV color to RGB color
void HSVtoRGB(void *vRGB, void *vHSV) 
{
  float r, g, b, h, s, v; //this function works with floats between 0 and 1
  float f, p, q, t;
  int i;
  ColorRGB *colorRGB=(ColorRGB *)vRGB;
  ColorHSV *colorHSV=(ColorHSV *)vHSV;

  h = (float)(colorHSV->h / 256.0);
  s = (float)(colorHSV->s / 256.0);
  v = (float)(colorHSV->v / 256.0);

  //if saturation is 0, the color is a shade of grey
  if(s == 0.0) {
    b = v;
    g = b;
    r = g;
  }
  //if saturation > 0, more complex calculations are needed
  else
  {
    h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations
    i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4
    f = h - i;//the fractional part of h

    p = (float)(v * (1.0 - s));
    q = (float)(v * (1.0 - (s * f)));
    t = (float)(v * (1.0 - (s * (1.0 - f))));

    switch(i)
    {
      case 0: r=v; g=t; b=p; break;
      case 1: r=q; g=v; b=p; break;
      case 2: r=p; g=v; b=t; break;
      case 3: r=p; g=q; b=v; break;
      case 4: r=t; g=p; b=v; break;
      case 5: r=v; g=p; b=q; break;
      default: r = g = b = 0; break;
    }
  }
  colorRGB->r = (int)(r * 255.0);
  colorRGB->g = (int)(g * 255.0);
  colorRGB->b = (int)(b * 255.0);
}


unsigned int RGBtoINT(void *vRGB)
{
  ColorRGB *colorRGB=(ColorRGB *)vRGB;

  return (((unsigned int)colorRGB->r)<<16) + (((unsigned int)colorRGB->g)<<8) + (unsigned int)colorRGB->b;
}


float dist(float a, float b, float c, float d) 
{
  return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}


void plasma_morph()
{
  unsigned char x,y;
  float value;
  ColorRGB colorRGB;
  ColorHSV colorHSV;

  for(x = 0; x <SCREENSIZEX; x++) {
    for(y = 0; y < SCREENSIZEY; y++)
      {
  value = sin(dist(x + paletteShift, y, 128.0, 128.0) / 8.0)
    + sin(dist(x, y, 64.0, 64.0) / 8.0)
    + sin(dist(x, y + paletteShift / 7, 192.0, 64) / 7.0)
    + sin(dist(x, y, 192.0, 100.0) / 8.0);
  colorHSV.h=(unsigned char)((value) * 128)&0xff;
  colorHSV.s=255; 
  colorHSV.v=255;
  HSVtoRGB(&colorRGB, &colorHSV);
  
  display(x, y, colorRGB.r, colorRGB.g, colorRGB.b);
      }
  }
  paletteShift++;
  update_display(DEST_I2C_ADDR);
}

 //plasma setup - start with morphing plasma, but allow going to color cycling if desired.
void plasma_setup()
{
   paletteShift=128000;
  unsigned char bcolor;

  for(unsigned char x = 0; x < SCREENSIZEX; x++)
    for(unsigned char y = 0; y < SCREENSIZEY; y++)
    {
      //the plasma buffer is a sum of sines
      bcolor = (unsigned char)
      (
            128.0 + (128.0 * sin(x*8.0 / 16.0))
          + 128.0 + (128.0 * sin(y*8.0 / 16.0))
      ) / 2;
      plasma[x][y] = bcolor;
    }
}

Colorduino V1.3 Code (Slave):

#include <Wire.h>                //wire library for I2C
#include <Colorduino.h>          //colorduino library

#define START_OF_DATA 0x10       //data markers
#define END_OF_DATA 0x20         //data markers
#define I2C_DEVICE_ADDRESS 0x1A  //I2C address for this device 

void setup()
{
  Serial.begin(57600);
  Colorduino.Init();
  // compensate for relative intensity differences in R/G/B brightness
  // array of 6-bit base values for RGB (0~63)
  // whiteBalVal[0]=red
  // whiteBalVal[1]=green
  // whiteBalVal[2]=blue
  unsigned char whiteBalVal[3] = {33,63,63}; // for LEDSEE 6x6cm round matrix
  Colorduino.SetWhiteBal(whiteBalVal);

  Wire.begin(I2C_DEVICE_ADDRESS); // join i2c bus as slave
  Wire.onReceive(receiveEvent);   // define the receive function for receiving data from master
}

/****************************************************
Main Functions zone
****************************************************/

void loop()
{ 
   
  //1 pixel = 3 bytes B00000000 B00000000 B00000000. 
  //We send R then G then B bytes as 3 separate transfers
  //This is because if we make the I2C buffer too large, we run out of SRAM for other things on our master Arduino
  
  if (Wire.available()>66) { //when buffer full, process data. 66 =  start byte + colour + 64 pixel data + end byte
   
    // error check - make sure our data starts with the right byte   
    if (Wire.read() != START_OF_DATA) {
      //else handle error by reading remaining data until end of data marker (if available)
      while (Wire.available()>0 && Wire.read()!=END_OF_DATA) {}      
      return;
    }

    byte c = Wire.read(); //read our color byte so we know if these are the R, G or B pixels.
    
    //depeding on c read pixels in as R G or B
    //read red display data
    if (c == 0){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
           PixelRGB *p = Colorduino.GetPixel(x,y);
           p->r = Wire.read();
        }
      }
    }
    
    //read green display data
    if (c == 1){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
          PixelRGB *p = Colorduino.GetPixel(x,y);
           p->g = Wire.read(); 
        }
      }
    }
    
    //read blue display data
    if (c == 2){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
           PixelRGB *p = Colorduino.GetPixel(x,y);
           p->b = Wire.read(); 
        }
      }
    }
    
    //read end of data marker
    if (Wire.read()==END_OF_DATA) {
      //if colour is blue, then update display
      if (c == 2){Colorduino.FlipPage();}
    } 
  }
}


//=============HANDLERS======================================

void receiveEvent(int numBytes) {
  //do nothing here
}

What could be wrong here?

This is a very common & widely used RGB Matrix module, and I thought almost anyone into LED's will know about this... No one?

With the Colorduino V1.3 Slave Code, there's this part that checks, if "Wire.available" returns greater than 66... And Serial Monitor shows it never returns greater than 38? Any leads from here? Anyone?

void loop() {
Serial.print("Wire Read: ");
Serial.println(Wire.read());
Serial.print("Wire Available? ");
Serial.println(Wire.available());
if (Wire.available()>66)
Serial.print("Wire available and greater than 66!");
}

Serial Debug:-

Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: -1
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 0
Wire Available? 30
Wire Read: 109
Wire Available? 29
Wire Read: 14
Wire Available? 28
Wire Read: 0
Wire Available? 27
Wire Read: 0
Wire Available? 26
Wire Read: 0
Wire Available? 25
Wire Read: 0
Wire Available? 24
Wire Read: 0
Wire Available? 23
Wire Read: 8
Wire Available? 22
Wire Read: 157
Wire Available? 21
Wire Read: 56
Wire Available? 20
Wire Read: 0
Wire Available? 19
Wire Read: 0
Wire Available? 18
Wire Read: 0
Wire Available? 17
Wire Read: 0
Wire Available? 16
Wire Read: 0
Wire Available? 15
Wire Read: 0
Wire Available? 14
Wire Read: 210
Wire Available? 13
Wire Read: 115
Wire Available? 12
Wire Read: 14
Wire Available? 11
Wire Read: 0
Wire Available? 10
Wire Read: 0
Wire Available? 9
Wire Read: 0
Wire Available? 8
Wire Read: 0
Wire Available? 7
Wire Read: 0
Wire Available? 6
Wire Read: 254
Wire Available? 5
Wire Read: 180
Wire Available? 4
Wire Read: 80
Wire Available? 3
Wire Read: 0
Wire Available? 2
Wire Read: 0
Wire Available? 1
Wire Read: 0
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 2
Wire Available? 30
Wire Read: 254
Wire Available? 29
Wire Read: 238
Wire Available? 28
Wire Read: 190
Wire Available? 27
Wire Read: 161
Wire Available? 26
Wire Read: 149
Wire Available? 25
Wire Read: 149
Wire Available? 24
Wire Read: 167
Wire Available? 23
Wire Read: 202
Wire Available? 22
Wire Read: 254
Wire Available? 21
Wire Read: 254
Wire Available? 20
Wire Read: 254
Wire Available? 19
Wire Read: 232
Wire Available? 18
Wire Read: 220
Wire Available? 17
Wire Read: 220
Wire Available? 16
Wire Read: 238
Wire Available? 15
Wire Read: 254
Wire Available? 14
Wire Read: 254
Wire Available? 13
Wire Read: 254
Wire Available? 12
Wire Read: 254
Wire Available? 11
Wire Read: 254
Wire Available? 10
Wire Read: 254
Wire Available? 9
Wire Read: 254
Wire Available? 8
Wire Read: 254
Wire Available? 7
Wire Read: 254
Wire Available? 6
Wire Read: 254
Wire Available? 5
Wire Read: 254
Wire Available? 4
Wire Read: 254
Wire Available? 3
Wire Read: 254
Wire Available? 2
Wire Read: 254
Wire Available? 1
Wire Read: 254
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 0
Wire Available? 30
Wire Read: 0
Wire Available? 29
Wire Read: 0
Wire Available? 28
Wire Read: 0
Wire Available? 27
Wire Read: 0
Wire Available? 26
Wire Read: 0
Wire Available? 25
Wire Read: 2
Wire Available? 24
Wire Read: 109
Wire Available? 23
Wire Read: 216
Wire Available? 22
Wire Read: 0
Wire Available? 21
Wire Read: 0
Wire Available? 20
Wire Read: 0
Wire Available? 19
Wire Read: 0
Wire Available? 18
Wire Read: 0
Wire Available? 17
Wire Read: 91
Wire Available? 16
Wire Read: 192
Wire Available? 15
Wire Read: 254
Wire Available? 14
Wire Read: 0
Wire Available? 13
Wire Read: 0
Wire Available? 12
Wire Read: 0
Wire Available? 11
Wire Read: 0
Wire Available? 10
Wire Read: 85
Wire Available? 9
Wire Read: 186
Wire Available? 8
Wire Read: 254
Wire Available? 7
Wire Read: 254
Wire Available? 6
Wire Read: 0
Wire Available? 5
Wire Read: 0
Wire Available? 4
Wire Read: 8
Wire Available? 3
Wire Read: 91
Wire Available? 2
Wire Read: 180
Wire Available? 1
Wire Read: 254
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 2
Wire Available? 30
Wire Read: 113
Wire Available? 29
Wire Read: 172
Wire Available? 28
Wire Read: 232
Wire Available? 27
Wire Read: 254
Wire Available? 26
Wire Read: 254
Wire Available? 25
Wire Read: 254
Wire Available? 24
Wire Read: 254
Wire Available? 23
Wire Read: 254
Wire Available? 22
Wire Read: 214
Wire Available? 21
Wire Read: 254
Wire Available? 20
Wire Read: 254
Wire Available? 19
Wire Read: 254
Wire Available? 18
Wire Read: 254
Wire Available? 17
Wire Read: 254
Wire Available? 16
Wire Read: 254
Wire Available? 15
Wire Read: 254
Wire Available? 14
Wire Read: 254
Wire Available? 13
Wire Read: 254
Wire Available? 12
Wire Read: 254
Wire Available? 11
Wire Read: 254
Wire Available? 10
Wire Read: 254
Wire Available? 9
Wire Read: 254
Wire Available? 8
Wire Read: 254
Wire Available? 7
Wire Read: 254
Wire Available? 6
Wire Read: 254
Wire Available? 5
Wire Read: 254
Wire Available? 4
Wire Read: 254
Wire Available? 3
Wire Read: 254
Wire Available? 2
Wire Read: 254
Wire Available? 1
Wire Read: 254
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 0
Wire Available? 30
Wire Read: 62
Wire Available? 29
Wire Read: 127
Wire Available? 28
Wire Read: 204
Wire Available? 27
Wire Read: 254
Wire Available? 26
Wire Read: 254
Wire Available? 25
Wire Read: 254
Wire Available? 24
Wire Read: 254
Wire Available? 23
Wire Read: 254
Wire Available? 22
Wire Read: 0
Wire Available? 21
Wire Read: 20
Wire Available? 20
Wire Read: 91
Wire Available? 19
Wire Read: 169
Wire Available? 18
Wire Read: 252
Wire Available? 17
Wire Read: 254
Wire Available? 16
Wire Read: 254
Wire Available? 15
Wire Read: 254
Wire Available? 14
Wire Read: 0
Wire Available? 13
Wire Read: 0
Wire Available? 12
Wire Read: 0
Wire Available? 11
Wire Read: 68
Wire Available? 10
Wire Read: 151
Wire Available? 9
Wire Read: 234
Wire Available? 8
Wire Read: 254
Wire Available? 7
Wire Read: 254
Wire Available? 6
Wire Read: 0
Wire Available? 5
Wire Read: 0
Wire Available? 4
Wire Read: 0
Wire Available? 3
Wire Read: 0
Wire Available? 2
Wire Read: 50
Wire Available? 1
Wire Read: 133
Wire Available? 0
Wire Read: -1
Wire Available? 0
Wire Read: 16
Wire Available? 31
Wire Read: 0
Wire Available? 30
Wire Read: 157
Wire Available? 29
Wire Read: 74
Wire Available? 28
Wire Read: 0
Wire Available? 27
Wire Read: 0
Wire Available? 26
Wire Read: 0
Wire Available? 25
Wire Read: 0
Wire Available? 24
Wire Read: 0
Wire Available? 23
Wire Read: 0
Wire Available? 22
Wire Read: 254
Wire Available? 21
Wire Read: 186
Wire Available? 20
Wire Read: 109
Wire Available? 19
Wire Read: 44
Wire Available? 18
Wire Read: 0
Wire Available? 17
Wire Read: 0
Wire Available? 16
Wire Read: 0
Wire Available? 15
Wire Read: 0
Wire Available? 14
Wire Read: 254
Wire Available? 13
Wire Read: 254
Wire Available? 12
Wire Read: 210
Wire Available? 11
Wire Read: 145
Wire Available? 10
Wire Read: 97
Wire Available? 9
Wire Read: 56
Wire Available? 8
Wire Read: 32
Wire Available? 7
Wire Read: 26
Wire Available? 6
Wire Read: 254
Wire Available? 5
Wire Read: 254
Wire Available? 4
Wire Read: 254
Wire Available? 3
Wire Read: 240
Wire Available? 2
Wire Read: 186
Wire Available? 1
Wire Read: 151
Wire Available? 32
Wire Read: 16
Wire Available? 31
Wire Read: 1
Wire Available? 30
Wire Read: 254