Skip to main content

arduinoserial.py is a Python port of Tod E. Kurt’s arduino-serial.c program for communicating with an Arduino microcontroller board over a serial port. It only uses standard Python modules (notably termios and fcntl) and does not require any special serial communications modules.

Like Tod’s program, you can use it from the command line.

Send the string “a5050” to Arduino:

$ ./arduinoserial.py -b 19200 -p /dev/tty.usbserial-A50018fz -s a5050

This would cause the pan-tilt head described in the lemonodor post “Tilt” to return to its middle position.

Recieve a line of text from Arduino, wait 1000 milliseconds, then send the string “a0000”:

$ ./arduinoserial.py -b 19200 -p /dev/tty.usbserial-A50018fz -r -d 1000 -s a0000

Complete command line usage information:

Usage: arduinoserial.py -p <serialport> [OPTIONS]
Options:
  -h, --help                   Print this help message.
  -p, --port=SERIALPORT        Serial port Arduino is on.
  -b, --baud=BAUDRATE          Baudrate (bps) of Arduino.
  -s, --send=DATA              Send data to Arduino.
  -r, --receive                Receive data from Arduino & print it out.
  -n  --num=NUM                Send a number as a single byte.
  -d  --delay=MILLIS           Delay for specified milliseconds.

Note: Order is important. Set '-b' before doing '-p'.
      Used to make series of actions:  '-d 2000 -s hello -d 100 -r'
      means 'wait 2 seconds, send 'hello', wait 100 msec, get reply'.

You can also import arduinoserial and use its SerialPort class to communicate with an Arduino from a Python program:

import arduinoserial

arduino = arduinoserial.SerialPort('/dev/ttyUSB0', 19200)
print arduino.read_until('\n')
arduino.write('a5050')

Also see the lemonodor post “arduino_serial”.

MIT License

Copyright (c) 2009 John Wiseman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release files for arduinoserial 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arduinoserial 1.0.1
File Size Uploaded
arduinoserial-1.0.1.tar.gz 5.6 kB Details

Release files / arduinoserial-1.0.1.tar.gz

Download URL arduinoserial-1.0.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4fb05ef0238b1d41250cf4b6d7811822304da0cebdc1c6621877530c46884660
BLAKE2b-256 checksum
How to use checksums
6bf4b0871155a9eb5ed68cee80f9ee496e49b9fc9bc5998e2ffe86b27a01904e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page