Archive for May, 2011

py-ColorPicker.jpg

Color Picker–Python

2

A essentially same one as previous but with python.

If you are familiar with python or want to use different kind of color picker GUI, this will be useful. It can be useful for initial testing and color matching again.

What you need

  • Arduino (any version)
  • High Power RGB LED shield
  • RGB LED

Arduino Libraries

Python Application

py-ColorPicker

 

pyGTK-ColorPicker

 

Jkm3141 posted a python front-end for the RGB LED color picker. You need python 2.x, PySerial, pyGTK to run the python code. There are two different GUIs (arduino-rgb and gtk-color-picker). In both, you need to change COM port to your port properly.

You can grab the code from the original post or my google code.

 

Circuit & Setup

No special circuit here. Just setup Arduino + HP RGB Shield + LED, then connect to a computer.

colorpicker_thumb2

Arduino Code

The couple of lines of arduino code has been modified to make it work with HP RGB Shield.

It is essentially just changing “analogWrite” to “goToRGB”. For version 1 shield users, change shield library include to “#include <HPRGB.h>”.

Code download

   1: #include <Wire.h>

   2: #include <HPRGB2.h>

   3:  

   4: HPRGB ledShield; // default mcp4728 id(0) and default PCA9685 id(0)

   5:  

   6: int colorRGB[3];

   7: int delayVal = 50;

   8: int blnFade = 0;

   9: int h_int;

  10: float h;

  11: int r=0, g=0, b=0;

  12:  

  13: void h2rgb(float h, int &R, int &G, int &B);

  14: void colorFade();

  15:  

  16: void setup() {

  17:   

  18:   Serial.begin(57600); 

  19:   ledShield.begin();

  20:  

  21: }

  22:  

  23: void loop() {

  24:   

  25:   if(Serial.available() >= 2){

  26:     

  27:     switch( byte( Serial.read() )) {

  28:       case 'r':

  29:         colorRGB[0] = Serial.read();

  30:         blnFade = 0;

  31:         break;

  32:       case 'g':

  33:         colorRGB[1] = Serial.read();

  34:         blnFade = 0;

  35:         break;   

  36:       case 'b':

  37:         colorRGB[2] = Serial.read();

  38:         blnFade = 0;

  39:         break;

  40:       case 'c':

  41:         Serial.flush();

  42:         blnFade = 0;

  43:         break;

  44:       case 'f':

  45:         delayVal = Serial.read();

  46:         Serial.flush();

  47:         colorFade();

  48:         blnFade = 1;

  49:       }

  50:    }

  51:    ledShield.goToRGB(colorRGB[0],colorRGB[1],colorRGB[2]);

  52:    delay(20);

  53: }

  54:  

  55: void colorFade() {

  56:  

  57:  while (blnFade == 1) {

  58:  if(Serial.available() ){

  59:    blnFade = 0;

  60:    break; 

  61:  }   

  62:  for(int fadeValue = 0 ; fadeValue <= 1024; fadeValue +=5) {

  63:     h = ((float)fadeValue)/1024;

  64:     h_int = (int) 360*h;

  65:     h2rgb(h,r,g,b);

  66:     if(Serial.available() ){

  67:       blnFade = 0;

  68:       break; 

  69:     } 

  70:     ledShield.goToRGB(r,g,b);

  71:     delay(delayVal);

  72:   }

  73:  }

  74: }

  75:  

  76: void h2rgb(float H, int& R, int& G, int& B) {

  77:   int var_i;

  78:   float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  79:   if ( S == 0 ) {

  80:     R = V * 255;

  81:     G = V * 255;

  82:     B = V * 255;

  83:   } else {

  84:     var_h = H * 6;

  85:     if ( var_h == 6 ) var_h = 0;

  86:     var_i = int( var_h ) ;

  87:     var_1 = V * ( 1 - S );

  88:     var_2 = V * ( 1 - S * ( var_h - var_i ) );

  89:     var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

  90:  

  91:     if ( var_i == 0 ) {

  92:       var_r = V     ;

  93:       var_g = var_3 ;

  94:       var_b = var_1 ;

  95:     } else if ( var_i == 1 ) {

  96:       var_r = var_2 ;

  97:       var_g = V     ;

  98:       var_b = var_1 ;

  99:     } else if ( var_i == 2 ) {

 100:       var_r = var_1 ;

 101:       var_g = V     ;

 102:       var_b = var_3 ;

 103:     } else if ( var_i == 3 ) {

 104:       var_r = var_1 ;

 105:       var_g = var_2 ;

 106:       var_b = V     ;

 107:     } else if ( var_i == 4 ) {

 108:       var_r = var_3 ;

 109:       var_g = var_1 ;

 110:       var_b = V     ;

 111:     } else {

 112:       var_r = V     ;

 113:       var_g = var_1 ;

 114:       var_b = var_2 ;

 115:     }

 116:     R = (1-var_r) * 255;

 117:     G = (1-var_g) * 255;

 118:     B = (1-var_b) * 255;

 119:   }

 120: }

 121:  

 

Video

Demonstration of setup and code

- Will be added soon.

ledcolorpicker.jpg

Color picker–Processing

2

Here is another project with High Power RGB LED Shield and Arduino.

This is rather simple way of communicated with the computer and can be useful for initial testing and color matching.

What you need

  • Arduino (any version)
  • High Power RGB LED shield
  • RGB LED

 

Arduino Libraries

 

Processing Application

 

ledcolorpicker

 

Rapplogic made nice color picker application with Processing. You don’t need to modify any code in here. If you have trouble running the application, make sure to put path and changing com port in ledcolorpicker.cmd (windows) or ledcolorpicker.sh (mac osx and linux)

 

   1: # this script requires java 1.5 in your path

   2: path C:\Program Files\Java\jre6\bin

   3: # replace the last argument with the COM port of your Arduino

   4: java -classpath lib\colorpicker.jar;lib\log4j.jar;lib\RXTXcomm.jar;ledcolorpicker.jar -Djava.library.path=. com.rapplogic.ledcolorpicker.LedColorPicker COM6

 

Circuit & Setup

No special circuit here. Just setup Arduino + HP RGB Shield + LED, then connect to a computer.

 

colorpicker

 

Arduino Code

The couple of lines of arduino code has been modified to make it work with HP RGB Shield.

It is essentially just changing “analogWrite” to “goToRGB”. For version 1 shield users, change shield library include to “#include <HPRGB.h>”.

Code download

   1: #include <Wire.h>

   2: #include <HPRGB2.h>

   3:  

   4: HPRGB ledShield; // default mcp4728 id(0) and default PCA9685 id(0)

   5:  

   6: // Indicates what color we are reading next; 0 = red, 1 = green, 2 = blue

   7: int pos = 0;

   8:  

   9: // red PWM value

  10: int red = 0;

  11: // green PWM value

  12: int green = 0;

  13: // blue PWM value

  14: int blue = 0;

  15:  

  16: // indicates if next byte should be unescaped

  17: boolean escape = false;

  18:  

  19: void setup() {

  20:   Serial.begin(9600);

  21:   ledShield.begin();

  22: }

  23:  

  24: void loop () {

  25:     

  26:     while (Serial.available()) {

  27:       int rgb = Serial.read();

  28:       

  29:       if (rgb == 1) {

  30:         // end of RGB sequence byte

  31:         // reset pos

  32:         pos = 0;

  33:     

  34:         // process this color

  35:         ledShield.goToRGB(red,green,blue);

  36:     

  37:         // Send ACK byte so Java app can send the next color

  38:         Serial.print("k");

  39:         Serial.flush();

  40:         

  41:         // get next byte

  42:         continue;

  43:       } else if (rgb == 2) {

  44:         // escape byte

  45:         escape = true;

  46:         // discard byte and read next byte

  47:         continue;

  48:       }

  49:       

  50:       if (escape) {

  51:         // unescape byte

  52:         rgb = 0x20 ^ rgb;

  53:         // reset escape

  54:         escape = false;  

  55:       }

  56:       

  57:       switch (pos++) {

  58:         case 0:

  59:           red = rgb;

  60:           break;

  61:         case 1:

  62:           green = rgb;

  63:           break;

  64:         case 2:

  65:           blue = rgb;

  66:           break;

  67:       }

  68:     }

  69: }

Video

Demonstration of setup and code

- Will be added soon.

Buying Guide is available

0

I got many questions what/where to buy for LED, heatsink, power supplies. I posted a guide page for what/where to get them. They are mostly USA sellers. If you find any good places for the stuffs, please let me know. I will add them in the guide.

Buying Guide

DSC06682-2.png

High Power RGB LED Shield 2.0

15

 

DSC06682-2

 

Here is a second revision of the shield. High Power RGB LED Shield version 2.0 has some improvements. A major change from version 1 is a new I2C PWM converter. The version 1 shield use ATTINY85 with cyzRGB firmware as a I2C PWM converter. Additionally it has couple of smart features like the writable sequence. However smart features was not that useful and it even confused users. I decide to abandon ATTINY with a better alternative, NXP PCA9685, a dedicated hardware I2C PWM converter. PCA9685 provide more muscle than brain. Instead of a few extra commands which was not popular, the shield now have more powerful PWM capability. All demo project codes that are posted are compatible with version 2 shield. It require Arduino or any microcontroller with I2C support for operation.

Overall design of the shield has not been changed except PCA9685. Price of the shield goes up little for the better quality product.

 

More Muscle than brain

 

PCA9685

 

  • NXP PCA9685 for I2C PWM

        The PCA9685 support high speed I2C communication up to 1MHz (Now, all chips including mcp4728, tmp421 support high speed I2C). Arduino can support 400KHz I2C communication (default is 100KHz). Total 62 I2C address is supported, so 62 shields can be stacked or controlled from a Arduino.

  • 12bit PWM resolution

        12bit hardware PWM (4096 steps) is supported. 1: 4000 dimming ratio is achieved just with PWM. 12bit PWM allow smooth correction of brightness curve to human eyes at 8 bit.

  • Adjustable PWM frequency – 40-1000KHz

        PWM frequency can be adjustable with default 200Hz. Version 1 shield use fixed 120Hz PWM. While >100Hz PWM is good enough most applications, in some cases you may find high frequency PWM useful. http://neuroelec.com/2011/03/high-pwm-frequency-for-led-good-or-bad/

 

Better Quality PCB

 

pcb

 

  • Smooth and clean edge by tab routing all around
  • Blue silk screen, gold finish
  • 2oz (70um) copper for better heat dissipation
  • Official OSHW (open source hardware) logo , Maybe first Arduino shield with OSHW logo

 

Schematics and design files

As I do support open source hardware, all schematics and design files are available. If you need any eagle library for the parts, just let me know.

http://code.google.com/p/neuroelec/source/browse/#svn%2Ftrunk%2FHP_RGB_LED_Shield_V2

 

Manual

http://neuroelec.com/hp-rgb-led-shield/ver-2-0-manual/

 

Library

Arduino library for the shield V2.0 is available for download

http://code.google.com/p/neuroelec/downloads/list

 

Availability & Price

Limited quantity of the shield available NOW from the store.

High Power RGB LED Shield – $40

High Power RGB LED Shield + Stackable pins – $41.5

High Power RGB LED Shield + Stackable pins + Temperature sensor (TMP421, 5 remote sensors) – $45

Go to Top