I did some quick tests. In short...
- The maximum baudrate is 115200 baud. Tests with 230400 baud always failed on the first read attempt.
- With the simple Arduino Sketch (see below) the IO-throughput is about 10kB/s.
The baudrate in the python script and the Arduino Sketch must (obviously) match to make this work
Here is the python script for testing
"""
Usage :
python st.py PORT BAUDRATE KILO_BYTES
example :
python st.py /dev/ttyATH0 115200 10
Will send and receive 10kB of data
turn on profiling:
python -m cProfile st.py /dev/ttyATH0 115200 10
"""
import serial
import sys
data='01234567012345670123456701234567'
expected='12345678123456781234567812345678'
#one packet is 32 bytes so 1kByte is 32 packets
packets=int(sys.argv[3])*32
s=serial.Serial(sys.argv[1],sys.argv[2],timeout=5)
for i in range(packets):
s.write(data)
result=s.read(32)
if result!=expected:
raise ValueError('Mismatch on run : '+str(i)+'\ndata = "'+data+'"\nresult = "'+result+'"')
print "Done!"
s.close()
On the Arduino I run this Sketch. It blinks the Led after coming out of a reset.
void setup() {
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
Serial1.begin(115200);
}
void loop() {
char c;
while (Serial1.available() > 0) {
c=Serial1.read();
c++;
Serial1.print(c);
}
}
Here is the output of the longest test I ran (4MB of data).
Takes about 7 minutes to complete!
root@YunYun:/mnt/sda1/python# python -m cProfile st.py /dev/ttyATH0 115200 4096
Done!
5392556 function calls in 431.015 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.005 0.005 0.026 0.026 __init__.py:8(<module>)
1 0.017 0.017 0.022 0.022 serialposix.py:13(<module>)
1 0.000 0.000 0.000 0.000 serialposix.py:163(Serial)
1 0.000 0.000 0.001 0.001 serialposix.py:168(open)
1 0.001 0.001 0.001 0.001 serialposix.py:192(_reconfigurePort)
1 0.000 0.000 0.000 0.000 serialposix.py:321(close)
131072 189.347 0.001 392.045 0.003 serialposix.py:340(read)
131072 11.837 0.000 25.662 0.000 serialposix.py:359(write)
1 0.001 0.001 0.001 0.001 serialutil.py:111(SerialBase)
1 0.001 0.001 0.002 0.002 serialutil.py:123(__init__)
1 0.000 0.000 0.000 0.000 serialutil.py:196(setPort)
1 0.000 0.000 0.000 0.000 serialutil.py:221(setBaudrate)
1 0.000 0.000 0.000 0.000 serialutil.py:240(setByteSize)
1 0.000 0.000 0.000 0.000 serialutil.py:253(setParity)
1 0.000 0.000 0.000 0.000 serialutil.py:266(setStopbits)
1 0.000 0.000 0.000 0.000 serialutil.py:279(setTimeout)
1 0.000 0.000 0.000 0.000 serialutil.py:298(setWriteTimeout)
1 0.000 0.000 0.000 0.000 serialutil.py:30(SerialException)
1 0.000 0.000 0.000 0.000 serialutil.py:317(setXonXoff)
1 0.000 0.000 0.000 0.000 serialutil.py:328(setRtsCts)
1 0.000 0.000 0.000 0.000 serialutil.py:339(setDsrDtr)
1 0.000 0.000 0.000 0.000 serialutil.py:35(SerialTimeoutException)
1 0.000 0.000 0.000 0.000 serialutil.py:355(setInterCharTimeout)
1 0.000 0.000 0.000 0.000 serialutil.py:40(FileLike)
1 0.003 0.003 0.004 0.004 serialutil.py:8(<module>)
1 13.242 13.242 431.015 431.015 st.py:14(<module>)
3 0.000 0.000 0.000 0.000 {_struct.pack}
2 0.000 0.000 0.000 0.000 {chr}
3 0.000 0.000 0.000 0.000 {getattr}
21 0.000 0.000 0.000 0.000 {hasattr}
131072 1.061 0.000 1.061 0.000 {isinstance}
2565176 21.640 0.000 21.640 0.000 {len}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'lower' of 'str' objects}
1 0.000 0.000 0.000 0.000 {posix.close}
1 0.000 0.000 0.000 0.000 {posix.open}
1151516 62.691 0.000 62.691 0.000 {posix.read}
131072 12.070 0.000 12.070 0.000 {posix.write}
1 0.038 0.038 0.038 0.038 {range}
1151516 119.062 0.000 119.062 0.000 {select.select}
1 0.000 0.000 0.000 0.000 {termios.tcgetattr}
1 0.000 0.000 0.000 0.000 {termios.tcsetattr}