Tuesday, December 15, 2015

Serial Port I/O in Python

From digging through Tom's code and googling stuff, it seems rather straightforward.

Need to include:
import serial

To get a module called not Serial but PySerial.

This doesn't come with most python installations, but it's quick to download installers, as demonstrated in this adafruit tutorial:
https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/installing-python-and-pyserial

Which gets the installer from here:
https://pypi.python.org/pypi/pyserial

Here are a couple of really nice forum threads containing example code:
http://stackoverflow.com/questions/676172/full-examples-of-using-pyserial-package
http://stackoverflow.com/questions/1093598/pyserial-how-to-read-the-last-line-sent-from-a-serial-device