Oct 232006
 

There’s been some confusion as to whether or not the DIY RGB orb presented in the last post was actually connected to a computer and receving color data from it. Here’s a video that more accurately depicts what’s going on and all the code used to create it.

Hardware

The hardware is just an Arduino board connected via USB to a laptop. The Arduino appears as a serial device to the computer. On the Arduino board, three LEDs (red,green,blue) are mounted directly to the Arduino board using a prototyping shield like this DIY one. The schematic is quite simple:
rgb_led_schematic.png

Arduino code

The code sketch running on the Arduino board is a slightly modified version of the one presented in the last Spooky Arduino class. Instead of parsing single color values over the serial port, it expects a full RGB color value in standard web format of “#RRGGBB” (white is “#ffffff”, blue is “#0000ff”, and so on). The sketch parses that seven character string into three bytes: one each for the brightness values of the red, green and blue LEDs.

Arduino code: serial_rgb_led_too.pde

Processing code

To bridge between the Arduino and the Net, a small Processing sketch was created that uses the standard Java HTTPURLConnection class to fetch a web page (really, a text file on a web server) containing a line with a color value in the format “#RRGGBB”. The sketch parses the color value, sends the value out to the Arduino orb using the Processing Serial library, and then sets its own background color to match. Because I’ve set the framerate of the sketch to 1 fps, it takes a second for the background to match the orb. I did this on purpose so I could get a sense of the color as the orb reproduces it before seeing it as it truly is. I was surprised how well the two tended to match!

Processing code: http_rgb_led.pde

 Posted by at 9:21 pm

  73 Responses to “DIY Ambient Orb with Arduino, update”

  1. Loading and altering “http_rgb_led” from this example was my introduction to Processing.

    For anyone that’s having trouble getting the example to run, you’ll need to create a font file to use as the argument for loadFont().

    Use the “tools>>create font” option in Processing, then use the name of the font file you created as the argument for loadFont.

    Hope this acts as a guidepost for future newbs passing through…

  2. Oops! You’re right Scott. Apologies to anyone who was having problems with that. And you can use any font your system has installed; I just happened to like Futura.

  3. I have some PHP code that I wrote to display glanceable weather info on a Chumby. I’m trying to replicate the behavior of my Ambient Weather Beacon. Thought y’all might like to experiment with it in conjunction with this project.

    The code grabs today’s temp using Yahoo’s APIs and maps the temp to an RGB color. After 3pm, it should display tomorrow’s temp (you may need to localize it).

    I haven’t really implemented the pulse that Ambient’s devices do to show precipitation chances, but the beginning of the code is there if you want to experiment.

    It was a simply thing to interface this with todbot’s Processing/Arduino example.

    The code’s a bit messy, I’m not great with PHP. The specific colors chosen for each temp could probably use a bit of work, too. But, hey – it’s a start for you to work from if you’re interested. I’ve only partially-implemented the pulse by mapping some of Yahoo’s weather codes to it (chance of showers == 1).

    It’s going to output something like:
    #0000fe
    pulse:1

    (pulse is from 0-3, 0 being no chance of rain, 3 being “extreme weather”)

    Ambient Orb Weather Predictor

    Hope you find this useful. You’ll need PHP5 (I used simplexml).

  4. […] Todbot featured a cool project that let you grab a color from a Web page and display it as a color using LEDs connected to an Arduino. I built a similar Orb using Tod’s (via ThingM) BlinkMs. The BlinkMs (as seen on BoingBoing) are “smart LEDs” that allow you to output a color based on RGB or HSB color input. My prototype currently uses 2 BlinkMs and it’s reasonably bright. […]

  5. I’m mucking up todbot’s code to include a ‘pulse’ variable so that my kludged orb can pulse when there’s precipitation forecast. A quick ‘throb’ for high rainfall, a slight pulse for light rain and a solid color for no rain.

    Anyone have thoughts on the best way to handle the pulsing? I was thinking of writing a function that would write a pattern to BlinkM, then have my code adjust BlinkMs playback timeline and fade rate to offload that process to BlinkM.

    In practice, this is looking to be a bit more work than I’d anticipated – calculating a nice fade from and arbitrary color (I’m using RGB color space). Are the ‘flash’ in-built BlinkM ‘flash’ scripts using HSB and simply adjusting the B(rightness)?

    I guess I could handle this all on the Arduino, but it just seems less… elegant. Any thoughts on this?

  6. Hogging the comments! Sorry!

    When I try to compile BlinkMScriptWriter, I get:

    error: too many arguments to function ‘uint8_t readSerialString()

    looks like the line just inside of the loop() should read:

    if( readSerialString() ) {

    (remove the serInStr argument)

  7. Oh thanks for catching that bug. I’ll update the BlinkM examples zip to include the fix. And if you “hog up” the comments with improvements to my code, hog away! :-)

  8. Can you point me back to the original notes on this project. I don’t understand the Processing portion, it just sits there on red. How does it get colors of the web? Do I need to edit the text, have another software program running? Thanks.

  9. Hi Matt,
    This post is basically the entire set of notes for this project. The Processing code does three things:
    1. Fetch a text file from a URL denoted by the variable “urlstr” (it’s set to “http://todbot.com/tst/color.txt” right now)
    2. Parse that text file for the first line that starts with “#” and contains 6 numbers.
    3. Send the parsed RGB color down the serial port to Arduino.

    You’ll want to change “urlstr” to a file on a server you control. Then whenever you edit that file and change the color, the Arduino will follow suit. You might be able to use “file://” URLs to access a local file, but I’ve not tried that.

  10. Hi ,
    we are very interested in finding a someone to custom make orbs for us , would you be interested?
    Nick

  11. This is the error I get from the processing. Can you help?

    2008-05-30 14:18:01.194 java[1987] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x11403, name = ‘java.ServiceProvider’
    See /usr/include/servers/bootstrap_defs.h for the error codes.
    2008-05-30 14:18:01.212 java[1987] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)
    java.lang.NullPointerException
    at java.io.DataInputStream.readInt(DataInputStream.java:353)
    at processing.core.PFont.(PFont.java:125)
    at processing.core.PApplet.loadFont(PApplet.java:4020)
    at Temporary_833_314.setup(Temporary_833_314.java:17)

    java.lang.RuntimeException: Could not load font Futura-MediumItalic-48.vlw. Make sure that the font has been copied to the data folder of your sketch.
    at processing.core.PApplet.die(PApplet.java:2499)
    at processing.core.PApplet.die(PApplet.java:2517)
    at processing.core.PApplet.loadFont(PApplet.java:4023)
    at Temporary_833_314.setup(Temporary_833_314.java:17)
    at processing.core.PApplet.handleDisplay(PApplet.java:1390)
    at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
    at processing.core.PApplet.run(PApplet.java:1562)
    at java.lang.Thread.run(Thread.java:613)

  12. Hi Harry,
    The useful bit of the error is buried in that mess, but what it’s saying is that the font file “Futura-MediumItalic-48.vlw” doesn’t exist. If you notice in the Processing sketch, there’s the line:

      font = loadFont("Futura-MediumItalic-48.vlw");
    

    To create this font file, go to the “Tools” menu and choose “Create Font…”. Pick whatever font you want (I picked 48-point italic Futura). Note the filename and click “OK”. Then go to that “loadFont()” line and change the filename to match your choice.

    If you want the exact font file I used, you can download it here:
    http://todbot.com/processing/http_rgb_led/data/Futura-MediumItalic-48.vlw
    This font file goes in the “data” directory of your sketch. When you use “Create Font…” it sticks the font files in the “data” dir for you.

    For more information on fonts in Processing, see:
    http://processing.org/reference/PFont.html

  13. Had some fun with your ambient orb idea and got one working really well in automatic fashion. My daughter has an “egg” toy that cycles through red, green and blue but doesn’t mix colors well enough to do the entire rainbow. With an RGB LED and some mods to your code, I was able to make one that hits all of the colors.

    This was my first foray into Arduino and I just wanted to say thanks for getting me started. Can’t wait to see what else I can do with this thing.

  14. hello everyone,

    i am a production LX a who is trying to find or make a whole lot of color changing orbs which could all be controled remotley and what is on this page looks like the kind of thing i am looking for. if they could be DMX controlled it would be great but they dont have to be. the only thing is that the orbs have to be able to give at least 50-60 watt equivalent. if anyone has any ideas of how to help me out it would be great

  15. […] – bookmarked by 5 members originally found by elucify on 2008-08-20 todbot blog " Blog Archive " DIY Ambient Orb with Arduino, update http://todbot.com/blog/2006/10/23/diy-ambient-orb-with-arduino-update/ – bookmarked by 3 members […]

  16. Hey Tod,

    Loving the project. I’m making use of the Orb as part of a project which involves IR sensors, piezos and the LED orb.

    Basically the project is as follows:

    – There will be two orbs set up at opposite, diagonal corners of a square space. Two IR sensors will be set-up to detect the user’s proximity from the orb(s).
    – As the user approaches the orb(s), the LEDs trigger intermittently; the closer the user to the orb, the less delay will be between (LED) flashes. The IR controls the strength of the LEDs and will also trigger synchronised sound.
    – When the user is within a certain range, the sound/light will turn from intermittent to static.
    – At this point, the user will be within touching range and piezos will be attached to the orb. Touching the orb will trigger additional sounds and possibly random LED value changes.
    – The Colour of the LED’s will only change upon touch.

    My question is will the Arduino be able to handle 2 analog IR inputs, 4 analog piezo inputs and 6 digital LED outputs, 2 loudspeaker outputs, all doing the above, hopefully, through Max?!

    I think the only way of working an orb in the opposite corner is running a series of long cables from a second, slave breadboard to the master breadboard/arduino?

    Any thoughts or tips? Anything that I’ve missed potentially?

    (I plan on programming using Maxuino)
    LED’s = 2.5v/4v fwd, 5v Rev
    IR = Sharp 2YOA21
    Piezo = Piezo transducer 35mm/28kHz/Max. 30V. input p-p.

  17. P.s. the LED’s have max. current ranges from 25-100mA

  18. Hi quikstiks,
    Short answer to your main question: yes, I think an Arduino could handle your 6 analog inputs and 6 LED outputs. The two speaker outputs are emitting sounds computed by a Max/MSP patch on a computer? If so, the Arduino isn’t really involved in that, but it would be sending data from its inputs to Max.

    I tend to think in terms of input->output flows. It sounds like there are two major flows. First, there’s the immediate “autonomous” response of triggering the LEDs based on the various inputs. This is a totally stand-alone Arduino sketch that could run by itself. And it might be a good starting point for getting everything all together and working.

    Then there’s the “Arduino-as-input-device” flow where the Arduino reads the inputs, sends them to Max/MSP over its serial/USB port, and Max outputs sound to speakers. I assume the Max patch is doing some sort of algorithmic generation of sound. If you’re happy with just triggering lofi samples instead, you could add a Waveshield on top of the Arduino and have it play the sounds directly.

    But if you don’t do that, you’ve got two cables running from the computer to each Orb: a USB cable and a speaker cable.

    This project sounds really cool. Send me some links when you get it up and running!

  19. Hi tod
    this a great tutorial, thanks for this sharing,
    I have a question regarding the amount of LEDs in pwm channels , My arduino board has only 6 pwm pins, wich makes 2 RGB Leds, ( the megas has more pwm ) but any way
    I need to controll several leds ( from sparkfun )
    and I am wondering if 2 LEDs per channel will be handle well and have good light, what resistor would you recommend (OHMS) for each Led . thank you looking forward to read your post. balam

  20. Has anyone come up with any cool websites i.e. giving users access to a set of sliders to determine the color of the light?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)