Skip to main content

pyElectronics

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

This is a python library for using electronics (like i2c or spi devices) with a unified interface. It currently supports connecting to stuff through the Raspberry Pi gpio with the i2c kernel driver and using the Bus Pirate.

Supported gateways

The gateways are the bridge between Linux and the hardware. Currently supported:

  • Bus Pirate v3

  • Raspberry Pi / other linux i2c_dev supported interfaces

Supported chips/devices

Read the contributing guide to add devices

  • Bosch BMP180 Digital pressure sensor

  • Honeywell 3-Axis Digital Compass IC HMC5883L

  • MPU-6050 Six-Axis (Gyro + Accelerometer) MEMS MotionTracking™ Device

  • NXP LM75A Digital temperature sensor

  • Microchip MCP23017 16-Bit I/O Expander

  • 7-segment displays without multiplexing

Installation

Install it from pypi:

$ pip3 install pyelectronics

The various gateways have their own dependencies. Install the dependencies for the gateway you require:

# Requirements for the Raspberry Pi
$ pip3 install pysmbus

# Requirements for the Bus Pirate
$ pip3 install pyserial

To run the doctests you need all dependencies. You can install them with the doctest requirements file:

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

Usage

Read the full docs at pythonhosted.

First create a instance of a gateway:

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

Create instances for components connected to the gateway:

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()

Read values from sensors:

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

Example with 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)

Metadata

Release files for pyelectronics 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyelectronics 0.1.4
File Size Uploaded
pyelectronics-0.1.4.tar.gz 13.2 kB Details

Release files / pyelectronics-0.1.4.tar.gz

Download URL pyelectronics-0.1.4.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9931399172462c753658b6d5cd7ea1cf40c9576cdb769f5e40b1614cf64ea0c1
BLAKE2b-256 checksum
How to use checksums
b83f52003d90d83137dfb02bae6e58fa71f95fc49483ed85c93b62f48703f487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page