我通过USB端口将Arduino板连接到Raspberry . 使用处理代码我想读取arduino发出的70个字节 . 如果我在我的PC窗口上使用这个程序它可以工作,但是使用Raspberry我从Processing获得的数据与arduino发出的数据不同 . 这是读取串口的Processing代码:
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:
>>> import serial
>>> ser = serial.Serial('/dev/ttyUSB0', 9600)
>>> while True:
... print ser.readline()
同样在python中也有同样的错误 . 我也尝试用相同的结果改变波特率(115200) .
1 回答
拔掉你的Arduino,用
ls /dev/tty*
搜索并插入 .如果您现在再次使用
ls /dev/tty*
搜索,您将看到一个新设备,例如/dev/ttyACM0
. 此外,您需要arduino驱动程序来模拟COM-Portsudo apt-get update && sudo apt-get install arduino
.Arduino代码
Raspberry Pi Code-Snippet
试试这个页面上的python示例:How to attach an Arduino?