Posts with «howto» label

Communicate with Arduino using python

Os: linux, windows (not tested), mac osx (not tested)
Difficulty: medium
Knowledge you need: a little bit of python programming (ver 2.x) and Arduino

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)

2 Download  test software

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)

3 Let’s try

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…

Eraclitux 20 Feb 11:13

Communicate with Arduino using python

Os: linux, windows (not tested), mac osx (not tested)
Difficulty: medium
Knowledge you need: a little bit of python programming (ver 2.x) and Arduino

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)

2 Download  test software

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)

3 Let’s try

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…

Eraclitux 20 Feb 11:13