arudino中软件串口的COM端口是什么?
问题描述:
我有一个蓝牙模块连接到我接收数据的Arduino上的RX(0)引脚。
然后我使用Serial.write()
打印该数据。
这两个引脚对应我的电脑中的COM16。arudino中软件串口的COM端口是什么?
我现在能够将这些值接收到处理中,并在处理中将COM端口设置为16之后再次在处理中进行打印。
现在我想通过串行通信再次将处理的特定值发回到Arduino。我想我可以用软件序列来做到这一点。 但是,我有几个问题,如何软件串行工作:
如果我设置一个软件串行,什么是软件串行的COM端口,我可以发送值从处理到Arduino?
这是在处理中设置COM端口的命令。
String portName ="COM16";
myPort = new Serial(this, portName, 57600);
然后我用myPort.write()
一些值发回的Arduino但如何捕捉值软串行?
答
最好的办法是使用Serial Event
最少的代码:
void setup() {
Serial.begin(9600); // initialize serial
}
void loop() { // you need to define a loop function even
// if not used at all.
}
// This is an interrupt.
// Code below will only execute when something is received in the RX pin.
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read(); // get the new byte
// here you can process the received byte
}
}
如果你想处理这些检查中的链接所提供的示例,它串接的字符到之前接收几个字节字符串直到接收到\n
字节
这种方法的优点是它使用中断,所以你不需要经常检查串口是否收到某些东西。
PD:我在你的代码中看到你使用57600的波特率。只要修改上面的代码以确保你使用相同的速度,否则你将不会收到任何东西(或者更糟的是,你将收到垃圾)
谢谢。我总是依靠基于问题标签的自动着色。不知道我可以手动定义代码:) –
它适用于一些标签,例如: 'C++'和'c',但是对于* arduino *却没有。 –
我认为你在处理时误解了我的问题。我正在讨论处理图形工具。为了进一步解释我的问题。我需要从两个串口接收数据到arduino中。一个来自Processing软件。 – user88464