python 3电子工作库

pyelectronics的Python项目详细描述


https://travis-ci.org/MartijnBraam/pyElectronics.svg?branch=masterhttps://badge.fury.io/py/pyelectronics.svg

这是一个python库,用于使用具有统一接口的电子设备(如i2c或spi设备)。它目前支持 使用i2c内核驱动程序通过树莓pi gpio连接到数据,并使用总线盗版。

支持的网关

网关是linux和硬件之间的桥梁。当前支持:

  • 总线海盗v3
  • Raspberry PI/其他Linux i2c_dev支持的接口

支持的芯片/设备

Read the contributing guide添加设备

  • 博世BMP180数字压力传感器
  • 霍尼韦尔3轴数字罗盘IC HMC583L 六轴(陀螺+加速度计)MEMS器件
  • NXP LM75A数字温度传感器
  • 微芯片MCP23017 16位I/O扩展器
  • 7段显示不复用

安装

从pypi安装:

$ pip3 install pyelectronics

各种网关都有自己的依赖关系。安装所需网关的依赖项:

# Requirements for the Raspberry Pi
$ pip3 install pysmbus

# Requirements for the Bus Pirate
$ pip3 install pyserial

要运行doctests,您需要所有依赖项。您可以使用doctest需求文件安装它们:

$ pip3 install -r docs/doctest-requirements.txt

用法

阅读pythonhosted上的完整文档。

首先创建网关实例:

from electronics.gateways import BusPirate
from electronics.gateways import LinuxDevice

# Use a BusPirate to connect to a bus
gw = BusPirate('/dev/ttyUSB0')

# Use a i2c bus with a linux driver (like the raspberry pi)
gw = LinuxDevice(1) # /dev/i2c-1

为连接到网关的组件创建实例:

from electronics.devices import BMP180
from electronics.devices import MPU6050I2C

barometer = BMP180(gw, address=0x77) # Address is optional
inertia = MPU6050(gw)

# Do chip specific initialisation
barometer.load_calibration()
inertia.wakeup()

从传感器读取值:

temperature = barometer.temperature()
pressure = barometer.pressure()
acceleration = inertia.acceleration()
rotation = inertia.angular_rate()

GPIO示例:

# Red led conected to the aux pin of the bus pirate
red_led = gw.get_aux_pin()
# Turn the led on
red_led.write(True)

# An Microchip port expander connected through I2C
expander = MCP23017I2C(gw, address=0x21)

# Get the pins for the two other leds that are connected
# to the port expander
green_led = expander.get_pin('A0')
blue_led = expander.get_pin('A1')

# Bundle the leds to a bus so you can address 8 colours as an int
# the pins on the port expander are open drain, they are inverted with the invert operator (~)
bus = GPIOBus([red_led, ~green_led, ~blue_led])
bus.write(0) # Black
bus.write(7) # White

# Disco!
while True:
    for i in range(0,8):
        bus.write(i)
        sleep(0.2)

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

推荐PyPI第三方库


热门话题
ec2中tomcat脚本的java自动启动   java如何连接到3个不同的数据库并通过JDBC并行运行查询   eclipse如何解决SpringDataMaven构建的“生命周期配置未涵盖的插件执行”   java在长时间运行的线程完成之前显示Android布局?   数组在Java中向mongoDB插入ArrayList   java如何检查网站是否已更新并发送电子邮件?   javaxaomi杀死前台服务   将动态JSON值解析为Java对象   java在主机名中是否支持下划线?   java如何获取RTC工作项epic id并使用功能id对数据进行归档   java我如何告诉Maven捆绑依赖的JAR   java Slidepuzzle,切换图标   java应用程序小部件:当背景添加到外部布局时,列表项上的涟漪效应消失   java为什么是系统。nanoTime()返回这么大的数字,而这么长的时间还没有过去?   java JPA:实现模型层次结构@MappedSuperclass vs.继承