PyRaspBeta

Pin naming

Every pin has a datasheet name — "A", "V+", "IN", "1" — and a Python spelling of that name that is safe to type as an attribute: led.a, buzzer.plus, relay.in_, res.pin1. You can reach a pin three ways, and they all return the same Pin:

led.pin("A")            # by datasheet name, the canonical way
led["A"]                # brackets are exactly pin(...)
led.anode               # by a friendly alias from the catalogue

part.pin(...) also takes a number for numeric pin names, so a resistor's leads are res.pin(1) and res.pin(2). A lookup checks, in order: the exact name, then the lower-cased aliases, then the lower-cased name or its attribute spelling. That is why led.anode, led.pin("A"), led.pin("a") and led.a all find the same terminal.

The pin table

The generated table for a part lists its datasheet pin names. For the LED:

PinWhat it isType
AAnode (+, longer leg)passive
KCathode (−, flat side)passive
SettingTypeRangeDefault
colorenumred, yellow, green, blue, whitered

And for the six-pin relay, whose entry has more pin names than most:

PinWhat it isType
DC+Coil supply 5 Vpower
DC-Groundground
INControl input (see trigger jumper)io
NONormally open contactpassive
COMCommon contactpassive
NCNormally closed contactpassive
SettingTypeRangeDefault
triggerenumlow, highlow

Aliases

The catalogue gives some pins a friendlier name. These are live examples:

  • led.anode is the A pin and led.cathode is K;
  • relay.signal is IN, relay.vcc is DC+ and relay.gnd is DC-;
  • rgb.red, rgb.green, rgb.blue and rgb.common point at R, G, B and COM;
  • pot.wiper is the W pin, and slide.common is COM.

Aliases are matched case-insensitively, so relay.SIGNAL works too.

Attribute spelling

The attribute form of a name is decided by a small set of rules. First the whole name is checked against a special map:

NameAttribute
5Vv5
3V3v3_3
+5Vv5
+12Vv12
+plus
-minus

Anything not in the map is rewritten: + becomes _plus, - becomes _minus, every other run of characters that is not a letter or a digit becomes _, and the result is trimmed of _ and lower-cased. Then two last touches:

  • if it starts with a digit, pin goes in front — 1 → pin1, 2 → pin2;
  • if the result is a Python keyword, a trailing _ is added — IN → in_ (because in is a keyword).

The common cases:

Datasheet nameAttributeReached as
Aaled.a, led.anode
Kkled.k, led.cathode
V+v_plusservo.v_plus
1pin1res.pin1
3V3v3_3supply.v3_3
5Vv5supply.v5
VCCvccdht.vcc
+plusbuzzer.plus
-minusbuzzer.minus
INin_relay.in_, relay.signal
DC+dc_plusrelay.dc_plus
DC-dc_minusrelay.dc_minus
A1a1button.a1
R1r1keypad.r1

A part's pins property gives them all at once, keyed by attribute spelling:

for name, pin in relay.pins.items():
    print(name)         # dc_plus, dc_minus, in_, no, com, nc

Unknown pins

A name that does not exist is reported differently depending on how you asked:

  • led.pin("V+") raises a CircuitError that lists the datasheet names: LED(led) has no pin 'V+'; pins: A, K.
  • led.v_plus raises an AttributeError that lists the attribute spellings.

Both are covered on Circuit errors.

Going deeper

  • Names come from the part, not the wiring library. The pin list and aliases are generated from the component catalogue, so a part's page and part.pins always show the same names.
  • The alias rule is deliberately small. Aliases are only added where the datasheet name is unfriendly; everything else is reached by spelling it — part.pin("NO"), part.no.
  • Keywords are the only suffix rule. in_ exists because relay.in is a syntax error; there is no general escaping beyond the trailing underscore and the pin prefix for digits.