Arduino, first contact
Two days ago I went to Santiago to attend the Artropocode Meeting, an event for people from both the Open/Free Software and Art/Design/Multimedia worlds to meet, talk and share ideas, experiences and knowledge.
First reason for me to be there was the fact that a friend of mine was involved in the event organization, second reason was that the first day was focused mainly in the arduino project.
For those of you who don't know about it, Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments (extracted from their website, http://arduino.cc).
First time I heard about arduino was during europython2010, when Ian Ozsvald showed us his headroid, a face-tracking robot. I thought it was totally awesome and I added a reminder for myself to check about that arduino thing later.
Since then I've read some stuff about the project and I've seen a lot of amazing things people do with arduino hardware, but I never had the chance to play with it by myself.
So, this was the perfect opportunity!
The meeting started with a talk by Filipe Valpereiro from the spacebits project. If you don't know the spacebits project, you should take a look at their website (http://spacebits.eu) and see the amazing things they are capable of.
Basically, they were able to send a hand-made shuttle up to near 40Km from the ground. Within that shuttle there were some cameras that were recording the whole thing. Just go check their website and play some videos, you will get truly amazed.
Filipe told us about the idea behind their project, how they started working on it, how they did what they do and we watched some amazing videos.
When the talk was over, Filipe sets a workshop so we all could play with some arduino boards and learn a lot.
Filipe gave us some kind of a starter pack:
- An arduino uno board
- An USB cable (to connect the arduino board to the computer, using a USB-to-Serial connection)
- A set of resistors
- Some LEDs
- Some sensors (including temperature and light measurement sensors)
- Some potentiometers
- Some buzzers (we did some really funny things with those ;P)
- Lots of cables and connectors
- A breadboard (where we will connect all the other stuff easily)
One last thing we needed before starting to work was to download the latest piece of software from the arduino website. This application makes communication with the board easier, you only have to write the code to interact with it and the app will take care of checking your code, validating it and uploading it to the board internal memory.
You can write your source code using your tool of choice, you only need a way to upload it later to the device. Of course, the debugging/console utilities bundled in their application help a lot too, so I recommend you to use it at least for your first experiences with arduino.
The blinking LED
Good, after setting everything up and some theoric introduction (which took place while everyone downloads the app, putting the wifi router into fire) we started with a really easy example, the blinking LED.
The idea was quite simple, we had to design a circuit so a LED got some electricity (to light it on) and then we had to add some code to the arduino board so it was able to light the LED on and off.
Designing the circuit was hard (last time I did anything with a breadboard was around 1998) but the code for the board was quite easy (less than 10 lines of code). The language you've to use to communicate with the arduino board is quite similar to C, so it wasn't difficult to get used to it. It was even easier because of the online reference, where you can find all you would need about the language.
This is a screenshot of my computer after uploading the code to the board:
The window you can see on the right side of the shot is the editor, where you can write your code. As you can see it even has syntax highlighting (as well as auto-indent). The window on the left side of the shot is the debugger/monitor window, which is showing the answers the board is sending you back through the serial connection (in this example, some print statements I added to my code).
Freestyle and some more work with leds and potentiometers
Once the blinking LED was actually blinking (so we could be sure it worked) we started playing with the circuit and the code, first changing the code so it blinked faster or slower, then changing it a little bit more so the LED wasn't blinking at the same pace all the time... it was fun.
After a while, we added potentiometers to the equation. We modified the circuit to add a potentiometer that allowed us to adjust the ammount of volts one of the inputs of the arduino board was receiving. Then we modified our code so it was able to adjust some values on demand. What does it mean? Easy, using a simple switch we were able to adjust how fast the LED was blinking. I know, I know, it sounds nothing like launching a missile against your archenemy, but I was learning dammit!
At that point people started to explore some own ideas, and there was a really nice atmosphere of learning, collaboration and sharing:
One more thing we did with potentiometers was to use them to adjust the intensity of the light the LED was emitting. This was really easy to do, in fact we didn't have to change the circuit at all, we only had to adjust our code a bit.
Playing with sensors
In the next step we added some sensors to our circuit. First we modified it to add a light-aware sensor. The idea was to replace the potentiometer with the sensor and see how the LED was going to change the light intensity based on the ammount of light detected by the sensor. That is, if there were no light, the LED would shine at full power, while in the case of too much light, the LED would be emitting almost no light at all.
At this point our circuit was getting somehow complicated (as we were adding more and more stuff, without removing the previous work, as Filipe was recommending) but I was impressed about how easy it was to apply big changes to the cirtuit behaviour with just small changes in our code.
Once the light sensor example was working fine, we added a temperature sensor too.
The RGB LED
For the last example involving LEDs we had to build a circuit with three potentiometers and one LED. The idea was that, using manual switches, we had to be able to adjust the color of the light emitted by the LED. Each potentiometer could be used to adjust the value of each one of the colors from the RGB color model (Red, Green, Blue), from 0 to 255, being 0 the lowest value (black) and 255 the highest value (white).
This is a picture of the whole RGB LED setup, ready for rumble:
This is a closer look at the board, after manipulating the potentiometers switches a bit, to get a bright green color on the LED:
The Buzzer
For our final example, we used a buzzer, an audio signaling device that can be used to make 8-bit sounds (and music!).
At first we just added the buzzer to the breadboard and we modified our circuit and code so it sounds, using a well-known tone:
After some experiments, we used the existing circuit from the RGB example (including the three potentiometers) to create some kind of a mixer board, that is, one of the potentiometers could be used to set the tone, another one could be used to adjust the frequency and the third one could be used to adjusting timing/delay.
This is the result:
The source code that allow us to do that was amazingly simple, take a look at the window on the left side of this screenshot (the one on the right side is the code used in the RGB example):
The Jam Session
After playing for a while with the buzzers example (there was even a proposal to see if anyone was able to get the classic Super Mario Bros tune ;P) Filipe and some other guys tried to set up all the equipment needed to perform a Jam Session using one arduino board and a circuit very similar to that one you've seen in the videos (+ some professional DJ stuff). In the end it didn't work as expected, there was some trouble with the connections, but we used 2 powerful speakers to do some performance while waiting for the pizzas to arrive.
Conclusions
I had a great time with Filipe and the others. The talk about the spacebits project was really interesting, you should take a look at their website, seriously, it shows perfectly the kind of things we would be able to do if we don't stay all day seating in front of a TV, a video console or the social networks.
The arduino workshop was amazing, all I'd expected and more. Even if we did no real or complicated stuff, I had tons of fun. Filipe was a good teacher and he had patience and explained everything, every detail, we would need to know.
Just to finish this post, I'd like to give you some interesting links about arduino and the things you can do with it (yep, they are related to python... O:)) :
- http://blog.aicookbook.com/2010/06/building-a-face-tracking-robot-headroid1-with-python-in-an-afternoon/
- http://arduino.cc/blog/category/languages/python/
- http://blog.datasingularity.com/?p=148
- http://principialabs.com/arduino-python-4-axis-servo-control/
- http://www.arduino.cc/playground/Interfacing/Python
- http://www.stealthcopter.com/blog/2010/02/python-interfacing-with-an-arduino/
