[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第三方库


热门话题
在Grails中集成javaapplet   动态设置片段时发生java错误   JavaSpringVelocity模板电子邮件?   SpringHateOAS中java自定义json输出   java wait()和notify()相关问题   正则表达式中的单词边界是什么?   使用外部库将项目部署到glassfish后发生java NoClassDefFoundError   java为什么在这里初始化ListNode两次?   java libGDX移动三维模型   java使线程等待另一个线程的执行   正则表达式如何在java中使用正则表达式解析给定字符串   java SWT ScrolledComposite在32768像素后切断画布生成的图像