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:
| Pin | What it is | Type |
|---|---|---|
| A | Anode (+, longer leg) | passive |
| K | Cathode (−, flat side) | passive |
| Setting | Type | Range | Default |
|---|---|---|---|
color | enum | red, yellow, green, blue, white | red |
And for the six-pin relay, whose entry has more pin names than most:
| Pin | What it is | Type |
|---|---|---|
| DC+ | Coil supply 5 V | power |
| DC- | Ground | ground |
| IN | Control input (see trigger jumper) | io |
| NO | Normally open contact | passive |
| COM | Common contact | passive |
| NC | Normally closed contact | passive |
| Setting | Type | Range | Default |
|---|---|---|---|
trigger | enum | low, high | low |
Aliases
The catalogue gives some pins a friendlier name. These are live examples:
led.anodeis theApin andled.cathodeisK;relay.signalisIN,relay.vccisDC+andrelay.gndisDC-;rgb.red,rgb.green,rgb.blueandrgb.commonpoint atR,G,BandCOM;pot.wiperis theWpin, andslide.commonisCOM.
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:
| Name | Attribute |
|---|---|
5V | v5 |
3V3 | v3_3 |
+5V | v5 |
+12V | v12 |
+ | 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,
pingoes in front —1→pin1,2→pin2; - if the result is a Python keyword, a trailing
_is added —IN→in_(becauseinis a keyword).
The common cases:
| Datasheet name | Attribute | Reached as |
|---|---|---|
A | a | led.a, led.anode |
K | k | led.k, led.cathode |
V+ | v_plus | servo.v_plus |
1 | pin1 | res.pin1 |
3V3 | v3_3 | supply.v3_3 |
5V | v5 | supply.v5 |
VCC | vcc | dht.vcc |
+ | plus | buzzer.plus |
- | minus | buzzer.minus |
IN | in_ | relay.in_, relay.signal |
DC+ | dc_plus | relay.dc_plus |
DC- | dc_minus | relay.dc_minus |
A1 | a1 | button.a1 |
R1 | r1 | keypad.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 aCircuitErrorthat lists the datasheet names:LED(led) has no pin 'V+'; pins: A, K.led.v_plusraises anAttributeErrorthat 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.pinsalways 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 becauserelay.inis a syntax error; there is no general escaping beyond the trailing underscore and thepinprefix for digits.