Python serial link

Questions on UARTs, and serial communication
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Python serial link

Post by YahooArchive »

I'm trying to read serial data from my ARMmite from Python...
I use BASICtools to load the led.BAS (below)

Sample test prog :
for i=1 to 3
print i
io(15)=i and 1 ' toggle the LED
wait (1000)
next i

I then run test.py (below) from a DOS box, and I get the following:

E:\Program Files\Coridium\Python>python test.py
0 à
1
2 à
3 à à à
4 à
5 à à
6 à
7 à à
8
9 à à à à à ààààà à àà ààààà àààà àààà ààà à
à à à à à à à à à à à à à à à à ààààà à àà ààààà àààà àààà ààà à

81 'bytes'


So, what am I doing wrong, or need to set?
I looked over TclTerm.tcl, and thought I had some idea, but apparently not.
If the baud is 57600 I only get 71 bytes, anything over returns 81.
Interestingly, I can set the baud up to 2**27-2 before it refuses open().

I'd also like to send control chars to the ARMmite to toggle GPIOs etc., so I'll
need to send as well...

-Ray


# test.py
import serial
import time

## Open the port. Specify baudrate and handshake.
## a running program BASIC will stop
#ser = serial.Serial(port,baudrate=rate,timeout=0,xonxoff=1)
ser = serial.Serial('COM5',
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=0,
xonxoff=0,
rtscts=0,
interCharTimeout=None)

## Enable the ARMmite.
## Deassert Request to Send, which enables Data Carrier Detect
## which alerts the ARMmite of a serial connection.
## RTS is used to control C loading vs BASIC load/run.
## It should always be high for a BASIC program, low for pyserial control
ser.setRTS(0)

## Deassert Data Terminal Ready which deasserts reset.
## DTR is used to reset the ARMmite (reset= 1, running = 0)
ser.setDTR(0) ## run loaded code

"""
ser.write('%s' % (str(arg)))

"""
i = 0
s = ''
while time.clock()<5:
buf = ser.read(ser.inWaiting())
if buf!='':
print i, buf
s += buf
i += 1
print s
print "%d 'bytes'" % len(s)

## Toggle the ARMmite reset. The program will stop.
ser.setDTR(1)

## Close the serial port. The program will resume!
ser.close()



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Python serial link

Post by YahooArchive »

> ser = serial.Serial('COM5',
> baudrate=115200,


try 19200

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Python serial link

Post by YahooArchive »

--- In ARMexpress@yahoogroups.com, "basicnode" wrote:
> > ser = serial.Serial('COM5',
> > baudrate=115200,
>
> try 19200

OK, that works :-)

I also got serial input to ARM:


print "Echo chamber:";
DO
debugin a
IF a MOD 2 THEN
io(15) = 1
ELSE
io(15) = 0
ENDIF
wait (500)
LOOP



import serial
import time

ser = serial.Serial('COM5', baudrate=19200, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
timeout=0, xonxoff=0, rtscts=0, interCharTimeout=None)
ser.setDTR(1)
ser.setRTS(0)
ser.setDTR(0) ## run loaded code
i = 0
while time.clock()<1:
buf = ser.read(ser.inWaiting())
if len(buf)>9:
## ECHO p to DOS command line, wait for input
inp = raw_input(buf)
ser.write('%s\n' % (str(inp))) ## write to ARM, toggle LED
while time.clock()<5:
buf = ser.read(ser.inWaiting())
if buf:
print "%s" % (buf), ## DEBUGIN echos back the char
i += 1
inp = raw_input(">>")
ser.write('%s\n' % (str(inp)))
else:
time.sleep(.0001)

ser.setDTR(1)
ser.close()


I also wrote an FFT and an RFT for ARMBASIC, if anyone's interested...
If you touch AD0 you can see the power jump in the nearest bin.

Anjin
Posts: 2
Joined: Wed Jun 04, 2014 7:30 am

Re: Python serial link

Post by Anjin »

Am interested in FFT code in Basic...

Thanks
Anjin

Post Reply