2023-03-23
12kg舵机的驱动,
● bug 1线串口复用了Tx和Rx,
debug 使用 2线串口转1线串口的转接板。
● bug 舵机 I/O 和Pc I/O,复用了arduino 的串口
debug,使用虚拟串口
#include <SoftwareSerial.h>
SoftwareSerial roboSerial(10, 11); //定义虚拟串口名为serial,rx为10号端口,tx为11号端口
2kg,3kg舵机的驱动,
12kg舵机的转接板和虚拟串口驱动 能够很好的运行,但是2kg,3kg舵机不能运行
● bug 2线串口转1线串口的转接板 的频宽不够,劣化了信号
debug 购买新的转接板,或更换旧板上的芯片?? 电容?? 电阻??
● bug 舵机 I/O 和Pc I/O,复用了arduino 的虚拟串口,虚拟串口的频宽不够,劣化了信号
debug,使用 Arduino Leonardo板,有2个串口。USB--Serial。pin0(RX)和pin1(TX)--Serial1
例如:
void setup() {
Serial.begin(9600); //设置PC串口 通信波特率
Serial1.begin(9600); //设置设备串口 通信波特率
Serial.println("Hello Word");
Serial1.println("TX:001"); //向数字引脚0、1所连接的设备发送数据"TX:001"
}
void loop() {
}
Leonardo 板子的缺陷
// bug , 上传本程序,运行正常。 打开PCarduino软件的串口监视器,再关闭串口监视器后,舵机异常,舵机表现为一跳一跳的分段快速转动。
// debug 这是 Leonardo 板子独有的问题,打开再关闭串口监视器后, Leonardo的运行速度大幅降低。
// debug 原因是:Leonardo 和 PC 之间的链接与 Uno 或 Mega 之间的链接工作方式不同,如果 PC 不接受数据,它的输出缓冲区可能会填满并阻塞(https://forum.arduino.cc/t/serial-print-on-leonardo-very-slow-after-disconnection-from-serial/483017)。
// debug 通过 Serial.println(USB_EP_SIZE);可知 leonardo 板子,usb的串口buffer size =64。(https://forum.arduino.cc/t/serial-print-on-leonardo-very-slow-after-disconnection-from-serial/483017/8)
// debug 程序最后的 delay(2); 改成delay(20); 打开再关闭PC arduinoIDE软件的串口监视器后,经过更长时间,舵机才开始一跳一跳的分段快速转动。说明PC串口有某种缓存。
// debug 如果串口连接尚未建立,打印/写入基本上会被忽略;当再次关闭串口时,问题就来了。 (https://forum.arduino.cc/t/serial-monitor-causes-lagging/954328/2)