Python meets arduino
A nice talk by Peter Kropf at PyCon 2012 on using Python to control external devices through an Arduino.
[Via: peterkropf.com]
A nice talk by Peter Kropf at PyCon 2012 on using Python to control external devices through an Arduino.
[Via: peterkropf.com]
“Social things” have replaced traditional ways of communication like sms and mails. One day i needed a new, fast, mobile and snappy way of communication. So i made Comunikino.
It consists of two main parts, a script in python that runs on the PC and a box that goes on desktop connected through an USB cable used for data and power (no external power needed if you use a 500mA capable usb port!). You need to create a mailbox for Comunikino with pop access, i raccomend to use gmail as many providers don’t offer pop access for free mailboxes.
Using Comunikino is simple, just send a mail to its mailbox and the subject will be printed to its LCD (max 16 chars). Who reads the message can use one of three Comunikino’s buttons to send a mail back to the address setted in python script to say yes, no or readed (this button can also to be used to say: “hey! I’m thinking of you”). Simple, isn’t it?
Schematics
You will need:
Amount | Part Type | Properties |
---|---|---|
1 | Arduino | I’ve used a 2009 |
1 | Basic Servo | |
1 | LCD screen | I’ve used a 16×2 LCD based on SPLC780D chip which is totally compatible with Arduino LCD library that is made for HD44780 chip. Its voltage must be 5V! |
3 | Push-button | Momentary normally open push button |
1 | Rotary Potentiometer | Rotary Shaft Potentiometer; see datasheet for maximum resistance |
1 | Metal or plastic box | I used a 13,5×7,5×5,5 cm metal box but you can use anything similar. |
First of all the box. You should cut it as images below.
LCD mounting:
Now fix arduino and buttons like this:
Putting things together (you can note a recycled hard disk flat cable used to connect LCD, ricycling is good!):
The flag can be made by wood, mdf, or cardboard:
Setting up software
Now download Comunikino's software (122) (Linux and windows version inside) and configure python script with the data of the mailbox you have created for Comunikino (gmail is highly recommended). You can do this just editing the script with a text editor. At the beginning you will find variables that you have to change, read comments for explanation! You need also to download and burn into Arduino the sketch into the zip (no modification needed here). Remember, before launching python script you have to connect Comunikino to PC or it will quit with an error. I advice you to leave Comunikino linked to the computer and make the script run on start up. Comunikino will inform you that it is ready to communicate with a mail every time computer is turned on.
Comunikino is ready!
“Social things” have replaced traditional ways of communication like sms and mails. One day i needed a new, fast, mobile and snappy way of communication. So i made Comunikino.
http://www.youtube.com/watch?v=Y9fqseT9PI0
It consists of two main parts, a script in python that runs on the PC and a box that goes on desktop connected through an USB cable used for data and power (no external power needed if you use a 500mA capable usb port!). You need to create a mailbox for Comunikino with pop access, i raccomend to use gmail as many providers don’t offer pop access for free mailboxes.
Using Comunikino is simple, just send a mail to its mailbox and the subject will be printed to its LCD (max 16 chars). Who reads the message can use one of three Comunikino’s buttons to send a mail back to the address setted in python script to say yes, no or readed (this button can also to be used to say: “hey! I’m thinking of you”). Simple, isn’t it?
Schematics
You will need:
Amount | Part Type | Properties |
---|---|---|
1 | Arduino | I’ve used a 2009 |
1 | Basic Servo | |
1 | LCD screen | I’ve used a 16×2 LCD based on SPLC780D chip which is totally compatible with Arduino LCD library that is made for HD44780 chip. Its voltage must be 5V! |
3 | Push-button | Momentary normally open push button |
1 | Rotary Potentiometer | Rotary Shaft Potentiometer; see datasheet for maximum resistance |
1 | Metal or plastic box | I used a 13,5×7,5×5,5 cm metal box but you can use anything similar. |
First of all the box. You should cut it as images below.
LCD mounting:
Now fix arduino and buttons like this:
Putting things together (you can note a recycled hard disk flat cable used to connect LCD, ricycling is good!):
The flag can be made by wood, mdf, or cardboard:
Setting up software
Now download Comunikino's software (430) (Linux and windows version inside) and configure python script with the data of the mailbox you have created for Comunikino (gmail is highly recommended). You can do this just editing the script with a text editor. At the beginning you will find variables that you have to change, read comments for explanation! You need also to download and burn into Arduino the sketch into the zip (no modification needed here). Remember, before launching python script you have to connect Comunikino to PC or it will quit with an error. I advice you to leave Comunikino linked to the computer and make the script run on start up. Comunikino will inform you that it is ready to communicate with a mail every time computer is turned on.
Comunikino is ready!
I want to upgrade this device with advanced features. I want to create a better software with GUI and a nice looking box. Help me!
Let’s see how easy it is to communicate with an Arduino 2009 board and the pySerial python’s module. What we will do is to use python to send characters serially to an Arduino 2009 which will send them back. Obviously, everything has a demonstration purposes only, since the code proposed here has no specific function but you can easily modify it to get something usable for your projects. What you describe has been tested on Ubuntu 10.04 but should work on other distributions as on various Windows and Mac OSX. If you have problems let me know!
1 Install pySerial
[Linux] Use your favorite packet manager to install python-serial or from command line type the famous command (on Ubuntu &co.):
sudo apt-get install python-serial
Type administration password and you are done!
[Windows] Download ed install pySerial (the file should be pyserial-2.5.win32.exe)
Program Arduino with this sketch Serial echo test program (84) and download the python code Python to Arduino test program (98). Open it with a text editor and see if at line 23 in place of ’/ dev/ttyUSB0′ what you find the editor of the Arduino sketch below themenu Tools -> Serial Port -> xxxxxxx. Remeber, do not forget the single quotes!
conn = serial.Serial('/dev/ttyUSB0', timeout=1)
With Arduino programmed with the sketch above and connected to the computer launch communication.py, if it works the board will send back all the ASCII characters that you type on the keyboard. You can verify that the communication is actually taking place looking at the flashing LED TX and RX on the board. Now you can to modify these examples to suit your needs.
Ah! The python’s way…
Let’s see how easy it is to communicate with an Arduino 2009 board and the pySerial python’s module. What we will do is to use python to send characters serially to an Arduino 2009 which will send them back. Obviously, everything has a demonstration purposes only, since the code proposed here has no specific function but you can easily modify it to get something usable for your projects. What you describe has been tested on Ubuntu 10.04 but should work on other distributions as on various Windows and Mac OSX. If you have problems let me know!
1 Install pySerial
[Linux] Use your favorite packet manager to install python-serial or from command line type the famous command (on Ubuntu &co.):
sudo apt-get install python-serial
Type administration password and you are done!
[Windows] Download ed install pySerial (the file should be pyserial-2.5.win32.exe)
Program Arduino with this sketch Serial echo test program (403) and download the python code Python to Arduino test program (385). Open it with a text editor and see if at line 23 in place of ’/ dev/ttyUSB0′ what you find the editor of the Arduino sketch below themenu Tools -> Serial Port -> xxxxxxx. Remeber, do not forget the single quotes!
conn = serial.Serial('/dev/ttyUSB0', timeout=1)
With Arduino programmed with the sketch above and connected to the computer launch communication.py, if it works the board will send back all the ASCII characters that you type on the keyboard. You can verify that the communication is actually taking place looking at the flashing LED TX and RX on the board. Now you can to modify these examples to suit your needs.
Ah! The python’s way…