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


热门话题
java访问私有字段而不使用getter方法?   使用PowerMockito在JavaEWSAPI中模拟测试拉订阅   启动活动时未保存java首选项并清除变量   java如何在servlet中检索子域?斯普林有帮手吗   java使用Docker从命令行构建Android项目   java Android,ActionBar后退按钮(setDisplayHomeAsUpEnabled(true))重新创建父活动   java在重用FileOutputStream时应该关闭流吗?   java使用RESTAPI将文件上载到s3 bucket   Java SOAP Web服务应用程序中的mysql用户登录方法不工作   java使用多个数字计算百分比并转换为长   java Android SQLiteDatabase查询忽略空格   java如何在Javafx中比较两个字段文本   java错误:未设置java_HOME,在Eclipse安装后找不到   java在安卓中保存对象   java如何使用jaxws从返回List<Object>的服务中检索值   java Google OAuth2 JWT令牌验证异常   SpringMVC中的JavaUTF8编码问题,当从JSP表单发送POST请求中的越南语信件时   java从webview重定向到安卓应用程序   JUnit 5中多个扩展的java顺序