到Arduino串行端口的Python接口。
arduinoserial的Python项目详细描述
arduinoserial.py是用于与arduino通信的Tod E. Kurt’s arduino-serial.c program的python端口 串行端口上的微控制器板。它只使用标准的python 模块(特别是termios和fcntl)不需要任何 特殊串行通信模块。
像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
特此免费向任何人授予许可 获取此软件和相关文档的副本 文件(以下简称“软件”),用于在没有 限制,包括但不限于使用权, 复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许 为此提供了软件,但须遵守以下规定 条件:
上述版权公告及本许可公告须 包含在软件的所有副本或大部分中。
软件按“原样”提供,不作任何保证, 明示或默示,包括但不限于保证 适销性、适合特定用途的 不侵犯。在任何情况下,作者或版权 持有人应对任何索赔、损害或其他责任负责, 无论是在合同诉讼、侵权诉讼还是其他诉讼中 来自、脱离或与软件或使用或 软件的其他交易。