在一篇博文中找到了解决办法。
原文链接:http://pi19404.github.io/pyVision/2015/04/03/22/
出现 “/dev/rfcomm0”后,就可以写串口程序进行通信。
python代码:
#coding=utf-8
# send to arduino
import serial
port = "/dev/rfcomm0"
serial = serial.Serial(port,9600)
sendStr = "1"
serial.write(sendStr)
serial.flushInput()
Arduino:
String val;
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
void setup() {
Serial1.begin(115200);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop() {
while (Serial1.available() > 0)
{
val += char(Serial1.read());
delay(2);
}
if (val.length() > 0)
{
if (val.equals("1") == true)
{
//Forward
digitalWrite(M1, HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 150);
analogWrite(E2, 150);
}
val = "";
}
}
最后,实现的就是python程序控制arduino舵机。