覆盆子pi i/o的易扩展性
RpiScratchIO的Python项目详细描述
RpiScratchIO是一个为 抓痕,运行在本地覆盆子皮或远程覆盆子皮或 其他电脑该包使用scratchpy客户端接口连接 到临时服务器进程可以通过运行 rpiscratchio脚本或via:
#!/usr/bin/env python import time import RpiScratchIO from RpiScratchIO import ScratchIO s = ScratchIO.ScratchIO("myConfig.cfg") try: while 1: time.sleep(1000) except KeyboardInterrupt: s.cleanup()
配置文件
使用ConfigParser读取配置文件文件有三个 章节,例如:
# Unique device name and class. If the device name is a GPIO # BCM id, then no class name is needed. [DeviceTypes] GPIO23 = ADC = MCP3008() Motor = HBRIDGE() file = FileConnection() # The connection mapping for each device. Simple GPIO devices do # not need a mapping. The unique device name must be defined in # the DeviceTypes section before the DeviceConnections section. [DeviceConnections] ADC = SPI0 MOTOR = GPIO12,GPIO13,GPIO02 file = file.txt # Used to connect to the Scratch server. Set the host name to # localhost to use the local Scratch server or choose an IP of # another Scratch server. [ScratchConnection] host = localhost port = 42001
设备类型
- 等号前面使用的名称必须唯一。这是名字 这个划痕将用来指代设备。
- 等号右边的文本应该对应于一个类 实例化字符串被解释为Python,其中 参数被传递给类构造函数这意味着 可以在构造函数调用和 import语句可用于包括其他Python类
- 如果设备名称是gpio bcm编号(例如gpio23), 不需要分配任何对象,因为已关联SimpleGpio对象 默认情况下。
设备连接
- “设备连接”部分必须在“设备类型”部分之后。
- 设备连接定义了组件的物理布线 或者Scratch和physical中文件名之间的连接 磁盘上的文件名。
- 等号左边的设备名必须在 在这里使用之前的设备类型
- equals右侧的文本可以是单个bcm pin参考, 由逗号或总线分隔的BCM管脚参考列表有效总线 名称是I2C0、I2C1、SPI0、SPI1、UART0
起始划痕
- Scratch必须在实例化ScratchIO对象之前启动
- 必须通过选择sensors工具选项板启用远程传感器。 然后右键单击sensor value。然后选择 启用远程传感器连接