Sunday, April 03, 2011

More Applications on the Nanode - RGB LED lamp

Today I have been sorting out some application code for the Pachube Hackathon, and have got a simple RGB LED lamp to be controlled from one Nanode instructed from another Nanode via Pachube. I see the passing of data from one Nanode to another via Pachube as a fundamental application, and today's tests proved what it can do, and some of its limitations.

As you may know, Pachube can handle comma separated variables (CSV) as one of its low level data exchange formats in its API. Simple, resource limited microcontrollers can readily produce CSV data using print statements and manipulate the data within them using string functions and string ennumeration such as the atoi (ASCII to Integer) function.


First some background. Last summer, I had the task of designing a test harness interface for a light-box I was building at work. Conveniently I was controlling the ultra-bright white LEDs in the light box with an Arduino Nano, so it was a useful exercise to come up with a simple serial protocol and command interpreter, written for the Arduino which could be used on other projects.


I wanted a semi-human readable format, so commands would start with an alphabetic character to make them easy to remember, followed by a short series of numerical parameters. For example, to control the brightness of the lamps you would use B (for brightness) followed by the value desired: B,100 would set the brightness to 100, from a maximum of 255. It was then and easy extension to modify thes commands to include more parameters - for example a RGB LED lamp might have the command L,55,130,75 - L for LEDs, and 55,130 and 75 being the valuse for the R,G and B PWM channels.


Having stumbled on this simple serial command method, it occurred to me that it could be passed down any serial communication channel, but more excitingly, Pachube could pass this command data by way of one of its feeds from one web connected node to another, and thus the project which was to become the Nanode was born.


As stated above, I use a very simple serial protocol, and have two terminal windows open, one for the Publisher (Putter) and the other for the Subscriber (Getter). Typing r128 in the Putter window, sends a command up to Pachube, and shortly afterwards the command appears in the Getter window and the red led changes to mid brightness.


A concatenated commamd of l, 255,0,255 is interpreted as l for lamp, and 255,0,255 turns red and blue full on and green off - resulting in a nice glowing mauve.


In terms of overall command latency, i.e. the time taken from entering the command to the Nanode at the far end acting upon it the mean time is about 5 or 6 seconds. Once the Publishing Nanode has set the post to Pachube, the lamp controlling Nanode responds in about 3 seconds. It's not lightening quick, but some control tasks, such as central heating or remote appliance switching don't need to be lightning fast. Fast enough to control relays and actuators.


The sample code for the Pachube Putter and Getter is available from my Thingiverse site.

1 comment:

Anonymous said...

This one is very grate light lamp.I like this highly suggested LED light lamp.It is so bright lamp.The LED light used less electricity and give high energy.

light grow