Pages: [1]   Go Down
Author Topic: Demo of PC-Arduino comms using Python  (Read 1796 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Faraday Member
**
Karma: 101
Posts: 6195
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't been able to find a piece of example code (both the Python and the Arduino stuff) that can reliably send and receive text and/or binary data between a PC and an Arduino. So I have written a pair of demo programs - one in Python and one for the Arduino -  in the hope that they might be useful to newcomers.

I have written the programs on a Linux PC. It would be great if someone could let me know if they work on Windows and Mac systems.

I originally wrote the Python program in JRuby as I am more familiar with that. I can provide the JRuby version if anyone is interested.

Comments are very welcome.

...R

PS. I first mentioned my interest in this thread http://forum.arduino.cc/index.php?topic=224091.0

* ComArduino.py (7.79 KB - downloaded 120 times.)
* ArduinoPC.ino (4.67 KB - downloaded 127 times.)
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I originally wrote the Python program in JRuby as I am more familiar with that. I can provide the JRuby version if anyone is interested.

I'm a JRuby developer, I'm interested.  Here is a project I did.

(HTTPS on Raspberry Pi in JRuby) <-> Arduino

https://github.com/CootCraig/pi_arduino_io_1
Logged

UK
Offline Offline
Faraday Member
**
Karma: 101
Posts: 6195
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attached below is the JRuby code. You will also need to have the JSSC jar (Google JSSC).

I'm assuming you have JRuby installed and know where to put the jar / how to make the program find it.

...R

* ComArduino.rb (4.84 KB - downloaded 14 times.)
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm assuming you have JRuby installed and know where to put the jar / how to make the program find it.

Yes and thank you.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 101
Posts: 6195
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought it may be useful to produce a slightly simpler version of the Python - Arduino example which only uses printable characters. That means that the Arduino program can be worked from the Serial Monitor as well as with the Python program.

The new version also contains elements of the code from this Thread to illustrate how to parse the data and use it to control LEDs and a servo.

The Arduino code assumes there are LEDS connected to pins 12 an 13 and a servo connected to pin 8.

If you send <LED1, 200, 0.5> to the Arduino it will set the flash interval for LED1 to 200 millisecs and will move the servo to 50% of its range.

As before there is also a JRuby version of the PC program for anyone that may be interested.

...R

* ArduinoPC2.ino (4.07 KB - downloaded 14 times.)
* ComArduino2.py (4.55 KB - downloaded 8 times.)
* ComArduino2.rb (2.95 KB - downloaded 1 times.)
« Last Edit: July 19, 2014, 03:24:13 pm by Robin2 » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


did some playing with python here - http://playground.arduino.cc//Main/IEEE754tools -to get 64 bit double to Arduino and pack it as 32 bit float and back. Might be useful.

it misses start/stop bytes and CRC's in communication to be reliable.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: