[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"))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jenkins在java代码的csv中使用前导零传递数字   终止java应用程序javaw。exe eclipse   java平均字长。文本   java在事务中关闭连接时会发生什么?   java如何为rich faces extendedDatatable启用可调整大小的列?   SpringJavaWebApp头nosniff不适合js和css文件   Java:抛出异常   java获取拒绝ArrayList中存在的用户名的代码。   关于编写JNDI服务提供者的java教程   java Android emulator电子书示例已停止   java如何防止双向关系中的循环   在Java中,如何将接口的实现作为变量传递给方法?   java有没有办法通过注释来监听CoreNLP处理的进度?   java Eclipse错误:导入项目时“无法读取项目描述文件”   java为什么findViewById返回null?