我希望这里有人能帮助我,我想控制我的arduino uno,通过发送命令从一个C++程序执行一些基本的面部识别。重要的是,我以这样的方式发送数据字符串。
its John;
这样arduino才能做出正确的反应。然而,我很难找到正确的方法来执行这样的动作。如果有人能为我指明正确的方向,我将不胜感激。
请注意,我并不是在windows上运行这个程序。它将在覆盆子皮上运行。
发布于 2014-03-20 21:00:13
在raspberry pi上,串行端口是设备/dev/ttyAMA0 0。它还可能运行一个终端,因此您必须打开/etc/inittab并注释掉这一行并重新启动:
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100如果您不这样做,您的arduino将尝试登录到您的pi,每当它发送任何东西到串口。
另一个陷阱是,如果要在协议中使用二进制数据,则在默认情况下启用XON/XOFF流控制,它将默默地占用某些字节(^S和^Q)。
下面是如何打开,设置串口模式(禁用流控制!)和波特率,并写入串口:
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
// (i may be forgetting some headers)
...
int fd = open("/dev/ttyAMA0", O_RDWR);
if (fd == -1) {
perror("/dev/ttyAMA0");
return 1;
}
struct termios tios;
tcgetattr(fd, &tios);
// disable flow control and all that, and ignore break and parity errors
tios.c_iflag = IGNBRK | IGNPAR;
tios.c_oflag = 0;
tios.c_lflag = 0;
cfsetspeed(&tios, B9600);
tcsetattr(fd, TCSAFLUSH, &tios);
// the serial port has a brief glitch once we turn it on which generates a
// start bit; sleep for 1ms to let it settle
usleep(1000);
// output to serial port
char msg[] = "hi there";
write(fd, msg, strlen(msg));https://stackoverflow.com/questions/22544751
复制相似问题