Old Blog

Arduino 1.0 coming and compatibility

1

1 year ago
arduino1

Arduino 1.0 is coming soon. It has many new features and enhancements, however it break things as well. Many existing sketches and library won’t run in Arduino 1.0. They even changed file extension of sketch to ino. I hope that it is all for better future.

Luckily in most cases, we need to change a few commands to make it work in 1.0. I modified all libraries for 1.0 and they are available for download now for people who want to use Arduino 1.0 early. They are checked with just released Arduino 1.0 rc2.

Here are the libraries for Arduino 1.0

HPRGB Shield V1 library : Version 1 HP RGB LED shield library

HPRGB Shield V2 library : Version2 HP RGB LED Shield library

MCP4728 library : Quad channel 12bit DAC library

FFT library : Arduino port of ELM Chan’s FFT library

You can check source of the libraries from the googlecode.

The tree structure of googlecode SVN has been changed for cleaner organization which will break links in this blog. I will change links later.

Here are a few things for those who want to convert other existing libraries for Arduino 1.0.

  1. Rename “WProgram.h” to “Arduino.h”
  2. For wire library, send() to write() and receive() to read()
  3. write(0×00) to write((byte)0×00)
  4. Serial.print(BYTE) to Serial.write()

Easier and better stacking shields

0

1 year ago

One of the advantage of the HP RGB LED Shield is stackable. You can control up to 64 shields from one Arduino, if you just use PWM dimming. If you want to have analog dimming functionality along with PWM, you can stack up to 8 shields.

Some people start to use this multiple shields for their great project. A few found changing mcp4728 device id change was rather difficult. I fix a minor bug in the library and improve the device id change sketch. This should help for people with trouble.

If you just need PWM dimming, all you need to do is change PCA9658 ID by change jumpers on back of the shield. Normally 12bit PWM dimming is more than enough for most cases. You don’t need to do anything with mcp4728.

Only when you want to have analog dimming capability with PWM together, you need to change device ID of mcp4728. Now it is easier than ever. Open the sketch and change device ID as directed then upload to arduino.

Please grap lastest library from here.

changeid

If you still find difficulty with this, please email me at neuroelec@gmail.com including serial output from terminal.

Better HSB to RGB coversion

2

1 year ago
HSV_color_solid_cylinder_alpha_lowgamma

Couple of people pointed loss of precision on HSB to RGB conversion. Originally I adopted code from cyzrgb without thinking much, and found some significant loss of precision.

I improve the code for higher precision conversion with slightly faster, smaller code. Single conversion takes about 25uS. The main algorithm is from https://github.com/adafruit/RGB-matrix-Panel/blob/master/examples/plasma/plasma.pde

You can simply install new version of HP RGB LED Library to take the advantage of improved conversion code. All existing codes compatible with new library.

HPRGB_Shield_V2_Library-v1.1.zip

Beauties with the LED shield

0

1 year ago

I found that a broad range of people are using the HP RGB LED shield for scientific research to arts. I ‘d like to show two of them in here.

iphone controlled artistic cube by Nick

Nick and his group made a beautiful LED cube that is controlled by iphone. Here are a few picture and video demonstration. You can find more information from their site http://codes.nevercool.com

cube_team_assemly cube_inside 209__x_colorcube_dark1

Trial & Error, Color Cubed from Nevercool on Vimeo.

Wall lighting setup by Peter

It is still in progress. I could not resist to post about it. You can find more information including animating video from http://gallery.me.com/dangolboom#100126&bgcolor=black&view=grid

EndorStar

Color Picker–Python

2

1 year ago

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.

Color picker–Processing

2

1 year ago

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_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: // 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

1 year ago

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

High Power RGB LED Shield 2.0

15

1 year ago

HP_RGB_LED_Shield_V2_topview

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

LED Brightness to your eye, Gamma correction – No!

8

1 year ago

Human perceive brightness change non-linearly

When you want to change the brightness of LED or any light source, one thing you need to consider is how human perceive the brightness. As you see in the following chart, human perceive the brightness change non-linearly. We have better sensitivity at low luminance than high luminance. For example, when we control LED brightness using Arduino PWM, we see big brightness change between analogWrite(9,1) and analogWrite(9,2). We don’t see brightness change between analogWrite(9,244) and analogWrite(9,255). If you didn’t know, just quickly test yourself with Arduino. If you want to control LED brightness linearly to your eye, it require to have some adjustment.

Brightness_perception

Mis-understanding of Gamma Correction

In Arduino or any microcontroller, a common way to achieve linear brightness change is a lookup table that compensate or correct the value according to the curve. There are a common misunderstand or confusion regarding what curve to use. Many people use so called gamma correction table or equation which is not related with human perception of brightness. The Maxim App note describe “Gamma correction is used to correct for the nonlinear relationship between luminance and brightness” which is simply wrong. The gamma correction is used to correct nonlinear relationship between applied voltage to CRT and luminance of CRT. It is nothing to do with human perception. It is not just Maxim, I could find many implementation of gamma correction to correct luminance and brightness. The cyz_RGB also use the gamma correction.

Why people so easily confuse about it? The gamma correction is necessary for the display application. When movie or image is displayed on LED matrix like a stadium display, you want to have gamma correction since movie and image data itself is already gamma corrected data. It is also useful for LED based LCD backlight. When LED is used for lighting, however gamma correction is irrelevant. A funny thing is co-incidentally gamma correction and human perception of luminance is very similar. http://www.poynton.com/PDFs/SMPTE93_Gamma.pdf Take a look at following chart. Again it is just a co-incidence. So somehow the gamma correction is close approximation of human perception the luminance.

Correction calculation of luminance and brightness describe in CIE 1931 report then used for CIELAB color space.

L* = 116(Y/Yn)^1/3 – 16 , Y/Yn > 0.008856
L* = 903.3(Y/Yn), Y/Yn <= 0.008856

Where L* is lightness, Y/Yn is Luminance ratio.

For the correction curve, you need to inverse the equation.

CIElab_VS_Gamma

Due to the similarity between gamma correction and brightness vs luminance, there is only minor differences. If you still want to have more accurate correction, you can use following table for cyz_RGB firmware. Don’t get confused about 16bit valves, your PWM is still 8 bit. It is internally use 16 bit value for conversion.

 1:
 2: /*
 3: 16 bits to 8 bit CIE Lightness conversion
 4: L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
 5: L* = 903.3(Y/Yn), Y/Yn <= 0.008856
 6: */
 7:
 8: prog_uint16_t pwm_table[] PROGMEM = {
 9:     65535,    65508,    65479,    65451,    65422,    65394,    65365,    65337,
 10:     65308,    65280,    65251,    65223,    65195,    65166,    65138,    65109,
 11:     65081,    65052,    65024,    64995,    64967,    64938,    64909,    64878,
 12:     64847,    64815,    64781,    64747,    64711,    64675,    64637,    64599,
 13:     64559,    64518,    64476,    64433,    64389,    64344,    64297,    64249,
 14:     64200,    64150,    64099,    64046,    63992,    63937,    63880,    63822,
 15:     63763,    63702,    63640,    63577,    63512,    63446,    63379,    63310,
 16:     63239,    63167,    63094,    63019,    62943,    62865,    62785,    62704,
 17:     62621,    62537,    62451,    62364,    62275,    62184,    62092,    61998,
 18:     61902,    61804,    61705,    61604,    61501,    61397,    61290,    61182,
 19:     61072,    60961,    60847,    60732,    60614,    60495,    60374,    60251,
 20:     60126,    59999,    59870,    59739,    59606,    59471,    59334,    59195,
 21:     59053,    58910,    58765,    58618,    58468,    58316,    58163,    58007,
 22:     57848,    57688,    57525,    57361,    57194,    57024,    56853,    56679,
 23:     56503,    56324,    56143,    55960,    55774,    55586,    55396,    55203,
 24:     55008,    54810,    54610,    54408,    54203,    53995,    53785,    53572,
 25:     53357,    53140,    52919,    52696,    52471,    52243,    52012,    51778,
 26:     51542,    51304,    51062,    50818,    50571,    50321,    50069,    49813,
 27:     49555,    49295,    49031,    48764,    48495,    48223,    47948,    47670,
 28:     47389,    47105,    46818,    46529,    46236,    45940,    45641,    45340,
 29:     45035,    44727,    44416,    44102,    43785,    43465,    43142,    42815,
 30:     42486,    42153,    41817,    41478,    41135,    40790,    40441,    40089,
 31:     39733,    39375,    39013,    38647,    38279,    37907,    37531,    37153,
 32:     36770,    36385,    35996,    35603,    35207,    34808,    34405,    33999,
 33:     33589,    33175,    32758,    32338,    31913,    31486,    31054,    30619,
 34:     30181,    29738,    29292,    28843,    28389,    27932,    27471,    27007,
 35:     26539,    26066,    25590,    25111,    24627,    24140,    23649,    23153,
 36:     22654,    22152,    21645,    21134,    20619,    20101,    19578,    19051,
 37:     18521,    17986,    17447,    16905,    16358,    15807,    15252,    14693,
 38:     14129,    13562,    12990,    12415,    11835,    11251,    10662,    10070,
 39:     9473,    8872,    8266,    7657,    7043,    6424,    5802,    5175,
 40:     4543,    3908,    3267,    2623,    1974,    1320,    662,    0
 41: };

Patched cyz_RGB firmware can be found at google code download.

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

You can test linearity of LED brightness to your eye using following Arduino example code.

Just put any LED on pin 9 with current limiting resistor.

 1: /*
 2:  Change brightness of LED linearly to Human eye
 3:  32 step brightness using 8 bit PWM of Arduino
 4:  brightness step 24 should be twice bright than step 12 to your eye.
 5: */
 6:
 7: #include <avr/pgmspace.h>
 8: #define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness loopup table function
 9:
 10: /*
 11: 5 bit CIE Lightness to 8 bit PWM conversion
 12: L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
 13: L* = 903.3(Y/Yn), Y/Yn <= 0.008856
 14: */
 15:
 16: prog_uint8_t CIEL8[] PROGMEM = {
 17:     0,    1,    2,    3,    4,    5,    7,    9,    12,
 18:     15,    18,    22,    27,    32,    38,    44,    51,    58,
 19:     67,    76,    86,    96,    108,    120,    134,    148,    163,
 20:     180,    197,    216,    235,    255
 21: };
 22:
 23: int brightness = 0;    // initial brightness of LED
 24: int fadeAmount = 1;
 25:
 26: void setup()  {
 27:   // declare pin 9 to be an output:
 28:   pinMode(9, OUTPUT);
 29: }
 30:
 31: void loop()  {
 32:   // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
 33:   analogWrite(9, CIELPWM(brightness));
 34:
 35:   // change the brightness for next time through the loop:
 36:   brightness = brightness + fadeAmount;
 37:
 38:   // reverse the direction of the fading at the ends of the fade:
 39:   if (brightness == 0 || brightness == 31) {
 40:     fadeAmount = -fadeAmount ;
 41:   }
 42:   // wait for 500 milliseconds to see the bightness change
 43:   delay(500);
 44: }
Advertisements
  1. “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.”
    Are you still doing open source hardware?
    If si, I am interessted in the latest parts list, design and layout files if possible.
    Thanks!

  2. I have noticed that your blog needs some fresh posts. Writing manually
    takes a lot of time, but there is tool for this boring task, search
    for: unlimited content Wrastain’s tools

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: