How to access a serial port using Python

Started by pete_l, January 09, 2014, 05:28:36 PM

Previous topic - Next topic

pete_l

I'm using an A20 running the
a20_debian_kernel_3_4_LAN_USBx2_Cards_LCD_HDMI_SATA_TS_X_GPIO_OTG_MIC_release4.img
software.
I have developed a cute little board with a 16F887 PIC, that measures, reports and controls all sorts of peripherals: digital I/O, analog inputs, temperature, frequency, millisecond intervals etc. It talks to pretty much anything via a 38400 Baud serial connection.

I have this wired into ttyS1 on my A20 (UEXT1 pins 3 & 4) and can communicate with the board using the screen command from a ssh session. The next step is to write a software interface. I would prefer to dio this in Python, using a method like people do for controlling GPIO pins:

import A20_GPIO as GPIO

x - connector name
y - pin number

#init module
GPIO.init()

.. code goes here


Is there any sort of packaged interface for the serial ports, like there is for GPIOs and like the software available for RPI's?
So far I've found nothing.

If the worst comes to the worst, I can throw together something in C or maybe Perl if there's a library for it.

What would you suggest?

Mouchon

Hi,
You can may be try pyserial module http://pyserial.sourceforge.net/shortintro.html
with

ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) (uart6)
or

ser = serial.Serial('/dev/ttyS2', 19200, timeout=1) (uart7)

kr