PyRaspBeta

Wiring API reference

This is the complete reference for the wiring library: every public class and function, its signature, and the documentation that ships with it. It is generated from the library's own docstrings when the docs are built, so it always matches the code you are running — there is no second copy to drift out of date.

The guide pages explain how to use these pieces: The Pi and its pins, Wires and chains, Buying and naming parts, Pin naming, Modules and Kits. The reference below is where to look for the exact argument names and defaults.

Build a Raspberry Pi circuit in Python.

from wiring import Pi, LED, Resistor, Button

pi = Pi()
led = LED("red")
pi.GPIO17 >> Resistor(330) >> led >> pi.GND    # a chain through two-terminal parts
button = Button()
pi.GPIO27 >> button >> pi.V3_3

Every part you create is bought from the shop and placed on the board. Wire pins with a >> b (returns b, so chains read left to right) or connect(a, b).

Make your own components by subclassing Module; buy finished ones from kits.

class CircuitError(Exception)

A wiring mistake: unknown pin, a wire from a pin to itself, a second Pi, …

class Pin

One terminal of a part. pin >> other wires them and returns other (or a part's far end).

property ref

def connect(self, other, color=None)

Wires this pin to another pin (or to the near end of a two-terminal part). Returns the far side.

def connect(a, b, color=None)

Wires a to b (pins, or two-terminal parts). Same as a >> b.

class Component

A part from the shop. Subclasses set TYPE (the catalog slug).

def describe(self)

def pin_names(self)

def pin(self, name)

A pin by its datasheet name ("VCC", "V+") or a friendly alias ("anode").

property pins

property ends

def Part(type_id, args, *props)

Any part by its catalog slug: Part("dht22"), Part("resistor", 10000).

class Pi(Component)

The Raspberry Pi. Header pins: pi.GPIO17, pi.V3_3, pi.V5, pi.GND, pi.SDA, pi.pin(11) (physical).

def gpio(self, number)

The header pin of a BCM GPIO number.

def pin(self, name)

A header pin by physical number (11) or name ("GPIO17", "GND", "3V3").

property ends

class Module

Base class for your own components. Create parts in build(), publish pins with expose().

class Indicator(Module):
    def build(self, color="red"):
        self.led = LED(color)
        self.res = Resistor(330)
        self.res >> self.led
        self.expose(sig=self.res.pin1, gnd=self.led.cathode)
        self.chain("sig", "gnd")          # optional: lets `pi.GPIO17 >> Indicator() >> pi.GND` work

A module costs the sum of its parts and is drawn as a group.

def build(self, args, *kwargs)

def expose(self, **pins)

Publishes inner pins under new names: self.expose(vcc=self.sensor.vcc).

def chain(self, near, far)

Names the two pins a >> module >> b passes through.

def describe(self)

def pin_names(self)

def pin(self, name)

property ends

class Kit(Module)

A finished module from the shop: pre-wired, priced as one item.

def build(self)

def shop()

Prints the shop: every part and kit with its price.