Let’s look at what we want to achieve and what bits and pieces we need. First of all, we need Arduino to be able to connect to the Internet. As the Arduino board has only a USB port, we can’t plug it directly into an Internet connection, so we need to figure out how to bridge the two. Usually what people do is run an application on a computer that will connect to the Internet, process the data, and send Arduino some simple bit of distilled information.

Arduino is a simple computer with a small memory; it can’t process large files easily, and when we connect to an RSS feed, we’ll get a very verbose XML file that would require a lot more RAM. On the other hand, your laptop or desktop computer has much more RAM and is much better suited for this kind of work, so we’ll implement a proxy to simplify the XML using the Processing language to run on your computer.

PROCESSING

Processing is where Arduino came from. We love this language and use it to teach programming to beginners as well as to build beautiful code. Processing and Arduino are the perfect combination. Another advantage is that Processing is open source and runs on all the major platforms (Mac, Linux, and Windows). It can also generate standalone applications that run on those platforms. What’s more, the Processing community is lively and helpful, and you can find thousands of premade example programs.

The proxy does the following work for us: it downloads the RSS feed from http://makezine.com and extracts all the words from the resulting XML file. Then, going through all of them, it counts the number of times “peace,” “love,” and “Arduino” appear in the text. With these three numbers, we’ll calculate a colour value and send it to Arduino. The Arduino code, in turn, will send to the computer the amount of light measured by the sensor, which the Processing code will then display on the computer screen.

On the hardware side, we’ll combine the pushbutton example, the light sensor example, the PWM LED control (multiplied by 3!), and serial communication. See if you can identify each of these circuits when you build it in “Assembling the Circuit”. This is how typical projects are made.

As Arduino is a simple device, we’ll need to codify the colour in a simple way. We’ll use the standard way that colours are represented in HTML: # followed by six hexadecimal digits.

Hexadecimal numbers are handy, because each 8-bit number is stored in exactly two characters; with decimal numbers this varies from one to three characters. Predictability also makes the code simpler: we wait until we see a #, and then we read the six characters that follow into a buffer (a variable used as a temporary holding area for data). Finally, we turn each group of two characters into a byte that represents the brightness of one of the three LEDs.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *