【发布时间】:2021-07-24 06:12:34
【问题描述】:
我正在尝试使用 arduino ide 和 processing ide 制作一个 arduino 项目。 我开始做一个简单的测试来查看使用 arduino ide 显示数字 0,1..9 的环境,但处理 ide 由于某种原因不能正确读取它,我不知道为什么,它读取的数字很奇怪从 10、13、53 等系列开始(只有这些数字,没有任何变化)。这是我的处理代码:
import processing.serial.*;
Serial port;
void setup() {
port = new Serial(this,"/dev/ttyUSB0",9600);
}
void draw() {
if(port.available() > 0) {
int info = port.read();
println(info);
println("===");
}
}
这是我的 arduino 代码:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int deg = 0;
int data = 1;
for (deg = 0; deg < 10; deg++) {
Serial.println(deg);
delay(15);
delay(1000);
}
}
另外,板子和处理器使用相同的端口/dev/ttyUSB0。 我在 Ubuntu 20.04 上运行所有这些。我试图在谷歌上看,但似乎找不到任何东西。 在此先感谢,欢迎任何提示。
【问题讨论】:
-
除了比特率,还要配置数据、奇偶校验和停止位。 8-N-1 的东西,比如en.wikipedia.org/wiki/8-N-1
-
我不这么认为,我按照教程进行操作,他们没有问题,我认为可能是外部问题,与代码无关,因为有时如果我打开处理它说端口很忙。
-
Serial.primtln发送 ASCII 而不是二进制。 Fyi, 10, 13 数字序列是 ASCII 回车/换行符。println调用在打印参数后发送。 53 是 '5' 的十进制 ASCII。我认为您正在处理 IDE 代码中读取和打印 ASCII 值。尝试将数据读入char而不是int并打印出char值。
标签: java arduino processing processing-ide