we've a new website! visit MechDesign.xyz
ελληνικά
 
UAVs blog
 
blog about DIY robots and UAVs

Arduino and Processing
by IKE 07-Mar-2010 15:04


What you see above is a bar chart that shows the variation in brightness on the screen of a mobile phone playing a video clip.It is also my first successful attempt to visualize data streaming from an Arduino board in real time. The graph is made with Processing, a very powerful and easy multimedia programming environment. Read below for more details and the actual scripts.---

In my previous blog post I mentioned Arduino and my first experience with the board and its programming environment. After reading M.Banzi's book "Getting Started with Arduino" and practice with the actual board most of its examples, I discovered Processing which formed the foundation for the development of Arduino and Wiring (a similar concept).

Processing is a programming environment created by MIT Media labs and it is fully open source. It uses Java and it provides a quite simple frame for people with almost no programming experience to create powerful and rich graphics easy. You can find more in the Processing website here: http://www.processing.org/. There are also many books on this subject. Processing is very easy to install, you just download the software package from here and run it. There are integrated examples in the IDE so you can easily play with the code.



For my first application I used the simple circuit above. It has a Light-dependent resistor (LDR), a component that varies its electric resistance in proportion to the light it absorbs. Simply put, it measures brightness. The goal is to program the Arduino to print the brightness value to the serial port and a Processing script will read these values and plot the chart in real time.

As a base I used the script from the Example 07 from here for the Arduino script and the embedded 'Simple Read' example from the Serial library of the Processing IDE. My first attempts were unsuccessful because I haven't correctly formatted in the code the serial port values. After a lot of searching and failed attempts I found this post from the Arduino forum that worked perfectly.



After many small tweaks with the code the result was ok. I also included a small script that print the odd bars in a different color than the even ones for a better looking graph.



You can download both scripts (or sketches as they called in Arduino/Processing) from the following links.

Test01_Arduino.txt
Test01_Processing.txt

There are comments inside the code for easier understanding of the program.



more :
000

Visit DIY Drones





All rights reserved. Texts, images, drawings and schematics are intellectual property of robotpig.net unless mentioned otherwise.
For any kind of use, written permission is required. © robotpig.net