由於需要運用樹莓派算出座標 再傳輸給單片機 所以兩者之間進行串口通信
參考資料 http://www.cnblogs.com/uestc-mm/p/7204429.html
https://www.cnblogs.com/lulipro/p/5992172.html
本人使用QT 注意 在.pro 加入LIBS += -lwiringPi
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main(int argc, char *argv[])
{
int fd;
if ((fd = serialOpen("/dev/ttyAMA0", 115200)) < 0)
{
fprintf(stderr, "Unable to open serial device: %s\n", strerror(errno));
return 1 ;
}
serialPuts(fd, "100 50 100\r\n");
delay(1000);
for (;;)
{
if (serialDataAvail(fd) > 0)
{
putchar(serialGetchar(fd));
}
}
return 0;
}
由於通訊協議是正點原子的 說所以serialPuts(fd, "100 50 100\r\n"); 要加\r\n 否則無法識別
連接圖傳不上來 就樹莓派的io口接單片機的io口 接地就行了