我把一块Arduino板通过USB接口连接到Raspberry。我想用一个处理代码来读取arduino发送的70个字节。如果我在我的电脑视窗上使用这个程序,它可以工作,但是用树莓,我从处理得到的数据不同于arduino发送的数据。这是读取串行端口的处理代码:
import processing.serial.*;
Serial uart;
byte[] codice= new byte[70];
void setup() {
uart= new Serial(this, Serial.list()[1], 9600);
}
void draw() {
if (uart.available()>0) {
codice=uart.readBytes();
println(codice);
}
}
在我的例子中,串行端口是“dev/ttyUSB0”。我也尝试用python的方法:
^{pr2}$在python中也有同样的错误。我还试图改变波特率(115200)与相同的结果。在
拔下你的Arduino,用
ls /dev/tty*
搜索并插入。如果现在使用
ls /dev/tty*
再次搜索,您将看到一个新设备,例如/dev/ttyACM0
。另外,您需要arduino驱动程序来模拟COM端口sudo apt-get update && sudo apt-get install arduino
。Arduino代码
树莓派代码片段
^{pr2}$试试这个页面上的python示例:How to attach an Arduino?
相关问题 更多 >
编程相关推荐