Since I have got my Freeduino (a cloned version of Arduino Duemilanove w/ ATmega328), I wanted to control it using my defacto programming language (Python).
I am an electronics novice / beginner. Electronics had always attracted me and continue to do so. My love towards playing with Software + Hardware is growing infinitely. They give us a physical sense, unlike Software that runs into an virtual environment.
I tried few basic examples of controlling the board using the Arduino IDE and their C like programming structure. These examples include, blinking the LED (Literally the Hello World), controlling the LED using a switch and then controlling the Color changing LEDs.
- pyserial (sudo pip install pyserial)
- Went to the Github repo.
- Cloned the repo using git.
- Connected the Freeduino board using USB interface.
- Started the Arduino IDE.
- Selected my board category and Serial Port.
- File -> Open -> (Navigate to the cloned repo and select the prototype.pde file).
- Verify and Upload this Prototype.pde sketch to the board.
Done. The device is now ready to accept instructions via Python serial interface.
Open the terminal and navigate to the cloned repository and cd into arduino directory where you will find arudino.py file. Take advantage of the python interpreter. I prefer using IPython, so I have invoked the interpreter (you can also carry this with default python interpreter). Try the below code to control the LED on pin 13 on the board.
from arduino import Arduino
b = Arduino(‘/dev/ttyUSB0’)
pin = 13 # set the pin number
b.output([pin]) # set the output on this pin number
b.setHigh(pin) # This is power on the LED
b.setLow(pin) # This is power off the LED
b.close() # closes the connection and the port.
Voila. It feels good. Really, really good. My next attempt is to understand the arduino.py file which actually uses the pyserial library to talk with the device and the prototype.pde file, which makes the device to serve python instructions.