[英]Arduino to RPi serial communication
I am trying to send data from an arduino to an RPi and than to a database. 我试图将数据从arduino发送到RPi而不是数据库。 But when i run my Python code:
但是当我运行我的Python代码时:
import serial
import time
import MySQLdb as mdb
arduino = serial.Serial("/dev/ttyACM0")
arduino.baudrate=9600
data=arduino.readLine()
time.sleep()
data = arduino.readLine()
blah blah blah...
IT GIVES ME AN ERROR 它给我带来了一个错误
AttributeError: 'Serial' object has no attribute 'readLine'
AttributeError:'Serial'对象没有属性'readLine'
How can I fix this? 我怎样才能解决这个问题?
Serial doesn't implement readLine
. Serial不实现
readLine
。 Try read
instead. 请尝试
read
。 You probably need to open
it first also. 您可能还需要先
open
它。
https://pythonhosted.org/pyserial/pyserial_api.html#classes https://pythonhosted.org/pyserial/pyserial_api.html#classes
The correct function is: 正确的功能是:
arduino.readline()
(only lowercase letters in "readline") (“readline”中只有小写字母)
Iterations of readings is better to put in loop eg.: 读数的迭代最好放在循环中,例如:
while True:
data=arduino.readLine()
time.sleep(1)
for x in range(0, 100):
data=arduino.readLine()
time.sleep(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.