到Arduino串行端口的Python接口。

arduinoserial的Python项目详细描述


arduinoserial.py是用于与arduino通信的Tod E. Kurt’s arduino-serial.c program的python端口 串行端口上的微控制器板。它只使用标准的python 模块(特别是termiosfcntl)不需要任何 特殊串行通信模块。

像tod的程序一样,您可以从命令行使用它。

将字符串“A5050”发送到Arduino:

$ ./arduinoserial.py -b 19200 -p /dev/tty.usbserial-A50018fz -s a5050

这将导致lemonodor post “Tilt”中描述的云台 回到中间位置。

从Arduino接收一行文本,等待1000毫秒,然后发送 字符串“a0000”:

$ ./arduinoserial.py -b 19200 -p /dev/tty.usbserial-A50018fz -r -d 1000 -s a0000

完整的命令行使用信息:

Usage: arduinoserial.py -p <serialport> [OPTIONS]
Options:
  -h, --help                   Print this help message.
  -p, --port=SERIALPORT        Serial port Arduino is on.
  -b, --baud=BAUDRATE          Baudrate (bps) of Arduino.
  -s, --send=DATA              Send data to Arduino.
  -r, --receive                Receive data from Arduino & print it out.
  -n  --num=NUM                Send a number as a single byte.
  -d  --delay=MILLIS           Delay for specified milliseconds.

Note: Order is important. Set '-b' before doing '-p'.
      Used to make series of actions:  '-d 2000 -s hello -d 100 -r'
      means 'wait 2 seconds, send 'hello', wait 100 msec, get reply'.

您还可以导入arduinoserial并使用其SerialPort类 从python程序与arduino通信:

import arduinoserial

arduino = arduinoserial.SerialPort('/dev/ttyUSB0', 19200)
print arduino.read_until('\n')
arduino.write('a5050')

另请参见lemonodor post “arduino_serial”

麻省理工学院许可证

版权所有(c)2009 John Wiseman

特此免费向任何人授予许可 获取此软件和相关文档的副本 文件(以下简称“软件”),用于在没有 限制,包括但不限于使用权, 复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许 为此提供了软件,但须遵守以下规定 条件:

上述版权公告及本许可公告须 包含在软件的所有副本或大部分中。

软件按“原样”提供,不作任何保证, 明示或默示,包括但不限于保证 适销性、适合特定用途的 不侵犯。在任何情况下,作者或版权 持有人应对任何索赔、损害或其他责任负责, 无论是在合同诉讼、侵权诉讼还是其他诉讼中 来自、脱离或与软件或使用或 软件的其他交易。

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

推荐PyPI第三方库


热门话题
tomcat java。lang.NoClassDefFoundError:无法初始化类com。太阳代理$Proxy8   java Spring引导CommandLineRunner异常处理建议   java文件。getParentFile()。mkdirs();在osx中创建重复文件夹   java Lucene IndexWriter线程安全   HashMapJava加速了哈希映射的创建   java执行器服务从Servlet线程启动   guava在Java中创建异构列表   泛型Java将比较器传递给构造函数   在Java中生成公钥和私钥的加密会生成类似的所有密钥,包括私钥和公钥   java ResourceLocation抛出FileNotFoundException Minecraft Forge 1.12.2   java使用动态键序列化JSON响应   在空映射上调用方法时发生java NullPointerException   java在Selenium中选择不同行中的按钮   优化在Java中,降低时间和空间复杂性的最佳方法是什么?   java表。setValueAt(…)不为JTable工作   javajsonrpc与JSON   ant从java编译中排除类的特定方法