我已经设法从我的arduino (Uno)到我的覆盆子Pi 3通过系列。
如果我在pi端使用相同的python脚本,在Arduino端使用相同的Sketch,则使用但使用Teensy,我无法读取来自arduino的任何输出。
根据串行通信,阿迪诺·尤诺和学校之间有什么区别吗?
Arduino素描:
void setup() {
Serial.begin(115200);
}
void loop() {
delay(1000);
Serial.println("10.7;0.7;FFFF:FFFF:FFFF:FFFF:");
}Python脚本在我的Pi上:
import serial
ser=serial.Serial("/dev/ttyACM0",115200)
while True:
print("Waiting for messages from arduino..");
read_ser=ser.readline()
print(read_ser)这段代码对我的Arduino Uno很好,但对我的Teensy不起作用。ttyACM0在这两种情况下都是正确的。
Pi上的OS是16.04。我可以在Arduino IDE中看到两个Arduino的输出。
我尝试了3种不同的泰恩,所以硬件不应该是问题。
有什么建议吗?
** ser.isOpen()是真的
bytesToRead = ser.inWaiting() print(ser.read(bytesToRead))没有什么区别。
会不会有什么不同,因为teensy是用微usb连接到pi上的,而UNO是用A到B USB连接的。
发布于 2017-11-08 10:06:33
Teensy是ACM设备?是的!
在和散出 ENDPOINTS(Interrupt_dev = 0,CDC_dev=1)中得到了附加的大容量

您的Teensy代码非常糟糕(为什么不需要计算和发送数据?)!
对于这样的测试程序:
unsigned long s = 0;
void setup(){
Serial.begin(0);//Not important !(speed 12Mb/s)
}
void loop(){
if(Serial.available() > 0){
while(Serial.available() > 0){//Buffer memory must always be clean !
char read = Serial.read();
delay(1);//wait until next_char
}
Serial.print("TEST : ");
Serial.println(s, DEC);
s++;
}
}Python代码:
import thread
import time
time.sleep(20)
#Don't fight with the Kernel, wait some seconds for prepare device
class _CDC :
def __init__(self):
self.dev = "/dev/ttyACM0"
self.query = ""
def read(self,_passarg):
with open("/dev/ttyACM0","r") as readBuff:
while True :
ans = readBuff.readline()
if ans:
print ans[:-2]#Ignore "\r\n" parts !
#time sleep for save cpu clocks
time.sleep(0.001)
def write(self,_passarg):
with open("/dev/ttyACM0","a") as writeBuff:
while True :
if self.query != "" :
writeBuff.write(self.query+"\n")
self.query = ""
#time sleep for save cpu clocks
time.sleep(0.001)
CDC = _CDC()
thread.start_new_thread(CDC.read,(None,))
thread.start_new_thread(CDC.write,(None,))
for i in range(30):
q = "SEND-TEST%02d"%i
CDC.query = q+((64-len(q))*"\x00")
time.sleep(0.1)如果设备是ACM,可以读写(就像文件对象)。打开带有"r“和"a”模式的设备,用于读取最后一行。
https://stackoverflow.com/questions/47101062
复制相似问题