Step 3: Software

So whats going on. basically we've set the arduino up to respond to a particular message. this message consists of a header (the letter "C") a dud byte (some strange serial problems caused this to be implemented) and the bytes of data (R G B respectively)

All processing is doing is generating these messages based on a pixel in an image, when we click the mose location is recorded and the message is built and sent to the audrino over a serial connection.

See the attached files for the software for this project, hitting run in processing should bring up a screen like the one below, although it will depend on what image you choose to load.

ColourMap goes in processing

RGB_LED_arduino_code goes in (you guessed it) arduino.

Make sure you load this onto the arduino before you run the processing file or it wont do anything.

if you having trouble check the following:

Is the arduino plugged in
is the arduino power light on
have you wired the led correctly
have you chosen the correct serial port in processing

if your still having trouble post a comment below and I'll do my best to answer it.
<p>what if we use codeblocks rather than arduino for the arduino program?is the processing code that was used here still works?</p>
<p>hello sir, can you tell me if this <a href="http://www.ebay.com/itm/330833693803?_trksid=p2060778.m2749.l2648&ssPageName=STRK%3AMEBIDX%3AIT" rel="nofollow">item </a>is a common cathode or anode please. thank you !!</p>
<p>Common anode. There's a &quot;+&quot; sign on the third photo on the product page</p>
<p>yes i figured it out as well, and actually got my order too. check it out; <a href="http://www.instructables.com/id/Glow-a-Pot/" rel="nofollow">http://www.instructables.com/id/Glow-a-Pot/</a> thank you </p>
<p>hi. the sketch isnt working for me for some reason. :( . im a noob, but i think ive followed everything. my circuit is definitely connected right. but nothing seems to be working. </p><p>could it be a problem with this? - </p><p>//the [0] may be [another number] on your computer</p><p> myPort = new Serial(this, Serial.list()[0], 9600);</p><p>when you say 'another number' what does that mean? how do i figure out the another number on my computer?</p><p>thanks</p>
<p>ok! problem solved! i just changed the [0] to [2]. worked for me!</p><p>thanks for the sketch!</p>
Can I use a Bluetooth Arduino with this? (I'm new to this)
Sure... =) <br>Just have to add some changes to the code (kind more complez) but yes, its possible!
Great ible! Got myself one fully running! <br>Congratulations! <br> <br>P.S.: SInce you are using pins 9~11 as PWM (Analog Out), you don't have to declare &quot;pinMode(redPin, OUTPUT);&quot; understand? It's not necessary. Gotta save you a couple KBs... ;D
I know I'm really late to this, but why is the red part of the colour map blocked off?
I'm getting the following NullPointerException error:<br> <br> <em>&quot;The file &quot;RGBR.png&quot; is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.&quot;</em><br> <br> <br> It breaks at&nbsp;<br> <br> <em>image(img,0,0);</em><br> <br> Anyone had this problem, before? Thank you!
Also should have mentioned, Mac OSX. Thanks!
A useful ible, but I'm worried that you don't use any resistor.<br /> <br /> If you apply the maximum power to the LEDs, with 5V output, I'm afraid they won't live long.<br /> <br /> You'll have to determine the proper resistor for each colour, as each LED type has it's own workiing voltage.<br /> <br /> <br />
LEDs work on current, not voltage. Each type of LED has a forward current &quot;knee&quot; that corresponds to a narrow range of forward voltages. The supply voltage needs to be higher than the knee voltage, but once the knee voltage is exceeded, the forward current rises extremely rapidly in the absence of a current limiting resistor.<br><br>Running an LED without a current limiting resistor only works if the die has a built-in constant current source. Some blinking LEDs are built that way, although the three-color LED apparently is not.
&nbsp;yes this is true. personally mine is one for about a minuet at a time so its pretty safe. i'll add the resistor values now, thanks for reading.
I have problem to run the file. I appreciate if anyone help me to resolve the problem. when i run the first code which map the picture, the error &quot; import does not name a type&quot; appear. it is my first experience with Arduino. I believe something wrong with my library. how can i resolve this problem.<br>Thank you,
Version without use of Processing (constantly changes color):<br> <a href="https://gist.github.com/1521148" rel="nofollow">https://gist.github.com/1521148</a><br>
Thank you so much :)
dude im having problem with the color map &nbsp;, &nbsp;please help me with that &nbsp;and dude this is a n awesome project<br> <br>
Could you do an instructable with both an xBee and RGB LEDs? I'm interested to see it work, especially controlling the LEDs separately and wirelessly at the same time :D
Finally got it to work! My computer says my Arduino is in COM7 but I needed to put in &quot;[3]&quot; for the myPort!.
works well if you change your serial ports<br>arduino's serial port will be whatever your COM port for uploading the file will be<br>on processings side the index will changed based on your OS and how many things you have plugged in<br><br>on OSX you will get many com ports (usually between 5 and 8 depending on whats plugged in) look for the first one that has TTY in it's property<br><br>on PC they will show up as COM1, COM4...<br><br>good starting project on communications between software and hardware.
it doesnt work.....I cant find the image for processing and I keep getting a &quot;Null pointer exception&quot; what is that ? I think your code is bad or something...please respond....
great example thanks - having problems with getting the right colour from processing to arduino but it is a matter of patience, I guess
I've had no problem with calibrating or uploading the image. However, i'm getting this error when I try to run the file:<br><br>&quot;error: 'import' does not name a type In function 'void setup()':<br> In function 'void draw()':<br> In function 'void mousePressed()':&quot;<br><br>Anyone know this means? Thanks for any help!
I am confused. How do I get Processing to open up the picture? Basically where do I put the image and the code at?
this is pretty sweet, thanks for sharing!
what do you mean by processing<br />
Processing is a multi-platform programming IDE based on Java. It's at processing.org. It's pretty simple to learn and has great support via their forums and the web in general. Terrible name though since it's such a generic word!
The software wont work!! Help! It downlaids a a .tmp file and processing and arduino doesnt recognize it!
left click the file and press rename, then select tmp and enter pde when the open menu asks &quot; if the file extension is modified the file might become unusable..,&quot; press yes. do this with both files and i am pretty shure the one ending in 2K is arduino c code, the other is for prossessing.
Thank you! I how have it working!!! How do I calibrate the color?
You need to make a another background file and import it into processing, or if your asking to change the LED's colour, just run the program and click on the colour you want to change the led into.
I apologize for not being very clear on my last question! I was curious about calibrating the color of the led. When I click a color on the screen it changes the led to a different color than I clicked on. Any suggestions?
try turning on any single colour(red, green, or blue), then disconect all and put each pin of led into the arduino pins, once you get a matching colour leave it connected, do the same procedure for the next colour.
check the pure RGB values (red blue green) if they seem correct then you know the pins are correct. if they seem a bit off check if you have a common anode of cathode LED. that will change the code if its common anode attach the common anode to VCC and wherever there is an analog out replace its value with 255- that value eg analogOut(X) to analogOut(255-X) if that still doesnt fix it check you resistor values with an online calc to ensure they're in the right range as it may be letting to much power through to the LEDs. Hope that helps. Smitec :D
first I wanted to thank you a lot for the tutorial.. it was a lot of help..<br /> <br /> second I played a little with your code and the code found <a href="http://blog.blprnt.com/blog/blprnt/quick-tutorial-twitter-processing" rel="nofollow">here</a> to add some twitter to the mix.. now I can use twitter to change the color of my lamp!<br /> <br /> just tweet: @colormelamp &lt;color of you choice&gt;<br /> supported colors: red, green, blue, cyan, yellow, magenta &amp; white.<br /> (actually it doesn't matter what's in the message as long as it contains &quot;@colormelamp&quot; and a color)<br /> <br /> my code is pretty cruel but it works. the code on the arduino is the same, you'll just have to set the usb port.. the rest should work.. if your gonna try it you could use the same twitter account I used that way our lamps would have the same color!<br /> <br /> <a href="http://tiranandkiwi.webs.com/random/RGB-LED-twitter.txt" rel="nofollow">processing code here</a><br /> (you can leave the password and username as they are, there not needed)<br /> <br /> tell me what you think!<br /> <br /> ps. this was my first Processing and third Arduino project so sorry if it doesn't make sense.. :P<br />
where s the picture file and your code didn't work
&nbsp;myPort is the first com port the one the arduino is attached to yours may not be the same.<br /> <br /> go to processing.org it is a program named processing<br /> <br /> place the image in a folder named 'data' in the same directory as your processing file.<br />
for the serial part<br /> &nbsp;myPort = new Serial(this, Serial.list()[0], 9600);<br /> is that your com port<br />
&nbsp;Is this tutorial possible with a single anode rbg led?
yes but:<br /> &nbsp;&nbsp; -anode should be connected to a voltage supply not ground<br /> &nbsp;&nbsp; -and, your analog outs in the arduino code should be 255-(what they are now)
what kind of a program, that is beside the (arduino). With the big P on it
Processing avaliable from processing.org<br /> <br /> thanks for reading

About This Instructable


83 favorites


Bio: Undergraduate Electrical Engineer and Electronics/Programming enthusiast.
More by smitec08: Controlling an RGB Led with Arduino and Processing
Add instructable to: