阅读串口

时间:2016-03-23 13:12:52

标签: python arduino

我似乎没有从我的serial.write / read中获得正确的读取ID。我做错了什么? 在循环中转了一圈之后,我希望得到另一个A00输出,但是我得到了D13HIGH,如下所示。

import serial
from time import sleep
import math

port = '/dev/ttyAMA0'
baud = 9600

ser = serial.Serial(port=port, baudrate=baud)

sleep(0.2)

count = 0

while count < 20:
    ser.write('a--A00READ--')
    sleep(0.2)
    reply = ser.read(12)
    print(reply)
    adc = reply[7:]
    adc = adc.strip('-')
    adc = int(adc)
    volts = (adc / 1023.0 * 5.0)
    ser.write('a--D13HIGH--')
    count += 1

ser.close()

输出:

>>> 
a--A00+487--
a--D13HIGH--

Traceback (most recent call last):
  File "/home/pi/serialcom.py", line 21, in <module>
    adc = int(adc)
ValueError: invalid literal for int() with base 10: 'IGH'
>>> 

0 个答案:

没有答案