[BETA]使用串行端口连接Arduino和Python
seriarduino的Python项目详细描述
塞里亚迪诺
安装
对于Arduino
- 克隆回购
- {{cd2>压缩到文件夹中
Note: You can also download
seriarduino_cpp.zip
from the releases
- 打开Arduino IDE
- 进入
Sketch
>;Include a library
并从seriarduino_cpp.zip
文件添加库
对于Python(在Raspbian上测试)
- 在
克隆repo或从版本中解压缩
在seriarduino_py.zip
文件 - 在
打开终端中的
在seriarduino_py
文件夹 - 在
在终端中,输入
在./setup.py install
用法
以下示例将Arduino与Raspberry Pi链接:
Arduino侧
#include<SeriArduino.h>SeriArduinoraspberry;Stringinput;floatvalue;voidsetup(){// We set the serial to 9600 bauds (be sure to use the same on the Python side)Serial.begin(9600);}voidloop(){// If raspberry gets any dataif(raspberry.available()){// We read the data and save it into the "input" variableinput=raspberry.read();// We convert the input into a float,// to do some computations latervalue=input.toFloat();Serial.println("We got a "+String(value));// A simple computationvalue=value*2;// We send the new data to the Raspberry Piraspberry.write(value);}delay(100);}
Python侧(覆盆子皮)
^{pr2}$
By default, SeriArduino will try to find the serial address, but you can also manually specify it by using the address argument on the constructor (e.g. SeriArduino(address = "/dev/ttyACM0")
)
标签:
- 项目
By default, SeriArduino will try to find the serial address, but you can also manually specify it by using the address argument on the constructor (e.g. SeriArduino(address = "/dev/ttyACM0")
)
标签: