Basic Circuit Elements

These elements are defined in the SchemDraw.elements module.

2-terminal Elements

Basic Elements

Basic elements define a start and end anchor for placing. Depending on the arguments to the add method, the leads may be extended to make the element the desired length.

../_images/electrical_1_0.svg

Sources and Meters

../_images/electrical_2_0.svg

Switches

../_images/electrical_3_0.svg

Labels

The LABEL element can be used to add a label anywhere. The GAP_LABEL is like an “invisible” element, useful for marking the voltage between output terminals.

../_images/electrical_4_0.svg

Other

The microphone and speaker have anchors in1 and in2.

../_images/electrical_5_0.svg

Lines, Dots, Arrows

../_images/electrical_6_0.svg

1-terminal elements

One-terminal elements do not move the current drawing position, and ignore any add parameters that specify an endpoint.

../_images/electrical_7_0.svg

3-terminal Elements

Three terminal elements define anchor names so that any of the three terminals can be placed at the desired drawing position.

Potentiometer is defined with one additional anchor for the ‘tap’:

../_images/electrical_8_0.svg

BJT and FET transistors also define three anchors:

../_images/electrical_9_0.svg

Names of the different transistor elements are shown below:

../_images/electrical_10_0.svg
../_images/electrical_11_0.svg

An opamp defines anchors in1, in2, and out, plus vd, vs for supply voltages and n1, n2, n1a, n2a for offset inputs.

../_images/electrical_12_0.svg

Transformers

Transformer elements can be generated using the SchemDraw.elements.transformer() function.

SchemDraw.elements.transformer(t1=4, t2=4, core=True, ltaps=None, rtaps=None, loop=False)

Generate an element definition for a transformer

Parameters
  • t1 (int) – turns on left side

  • t2 (int) – turns on right side

  • core (bool) – show the transformer core

  • ltaps (dict) – anchor definitions for left side. Each key/value pair defines the name/turn number

  • rtaps (dict) – anchor definitions for right side.

  • loop (bool) – Use spiral/cycloid (loopy) style

Returns

element definition dictionary

Return type

dict

Two transformers with cycloid=False (left) cycloid=True (right) shown below. Anchor names are p1 and p2 for the primary (left) side, and s1 and s2 for the secondary (right) side.

../_images/electrical_13_0.svg

Example usage with taps:

d = SchemDraw.Drawing()
xf = d.add(elm.transformer(t1=4, t2=8, rtaps={'B':3}, loop=False ) )
d.add(elm.LINE, xy=xf.s1, l=d.unit/4, rgtlabel='s1')
d.add(elm.LINE, xy=xf.s2, l=d.unit/4, rgtlabel='s2')
d.add(elm.LINE, xy=xf.p1, l=d.unit/4, d='left', lftlabel='p1')
d.add(elm.LINE, xy=xf.p2, l=d.unit/4, d='left', lftlabel='p2')
d.add(elm.LINE, xy=xf.B, l=d.unit/2, d='right', rgtlabel='B')
d.draw()
../_images/electrical_14_0.svg

Integrated Circuits

Elements drawn as boxes, such as integrated circuits, can be generated using the SchemDraw.elements.ic() function. An arbitrary number of inputs/outputs can be drawn to each side of the box. The inputs can be evenly spaced (default) or arbitrarily placed anywhere along each edge.

SchemDraw.elements.ic(*pins, **kwargs)

Define an integrated circuit element

Parameters

pins – Dictionaries defining each input pin entered as positional arguments

Pins dictionary
  • name: (string) Signal name, labeled inside the IC box. If name is ‘>’, a proper clock input triangle will be drawn instead of a text label.

  • pin: (string) Pin name, labeled outside the IC box

  • side: [‘left’, ‘right’, ‘top’, ‘bottom’]. Which side the pin belongs on. Can be abbreviated ‘L’, ‘R’, ‘T’, or ‘B’.

  • pos: (float) Absolute position as fraction from 0-1 along the side. If not provided, pins are evenly spaced along the side.

  • slot: (string) Position designation for the pin in “X/Y” format where X is the pin number and Y the total number of pins along the side. Use when missing pins are desired with even spacing.

  • invert: (bool) Draw an invert bubble outside the pin

  • invertradius: (float) Radius of invert bubble

  • color: (string) Matplotlib color for label

  • rotation: (float) Rotation angle for label (degrees)

  • anchorname: (string) Name of anchor at end of pin lead. By default pins will have anchors of both the name parameter and inXY where X the side designation [‘L’, ‘R’, ‘T’, ‘B’] and Y the pin number along that side.

Keyword Arguments
  • size: (w, h) tuple specifying size of the IC. If not provided, size is automatically determined based on number of pins and the pinspacing parameter.

  • pinspacing: Smallest distance between pins [1.25]

  • edgepadH, edgepadW: Additional distance from edge to first pin on each sides [.25]

  • lblofst: Default offset for (internal) labels [.15]

  • plblofst: Default offset for external pin labels [.1]

  • leadlen: Length of leads extending from box [.5]

  • lblsize: Font size for (internal) labels [14]

  • plblsize: Font size for external pin labels [11]

  • slant: Degrees to slant top and bottom sides (e.g. for multiplexers) [0]

Here, a J-K flip flop, as part of an HC7476 integrated circuit, is drawn with input names and pin numbers.

linputs = {'labels':['>', 'K', 'J'], 'plabels':['1', '16', '4']}
rinputs = {'labels':['$\overline{Q}$', 'Q'], 'plabels':['14', '15']}
JKdef = elm.ic({'name': '>', 'pin': '1', 'side': 'left'},
               {'name': 'K', 'pin': '16', 'side': 'left'},
               {'name': 'J', 'pin': '4', 'side': 'left'},
               {'name': '$\overline{Q}$', 'pin': '14', 'side': 'right', 'anchorname': 'QBAR'},
               {'name': 'Q', 'pin': '15', 'side': 'right'},
               edgepadW = .5  # Make it a bit wider
               )
JK = d.add(JKdef, label='HC7476', lblsize=12, lblofst=.5)
../_images/electrical_17_0.svg

Notice the use of $overline{Q}$ to acheive the label on the inverting output. The anchor positions can be accessed using attributes, such as JK.Q for the non-inverting output. However, inverting output is named $overline{Q}, which is not accessible using the typical dot notation. It could be accessed using getattr(JK, ‘$overline{Q}$’), but to avoid this an alternative anchorname of QBAR was defined.

Multiplexers

Multiplexers and demultiplexers may be drawn using the SchemDraw.elements.mux() function which wraps the SchemDraw.elements.ic() function.

SchemDraw.elements.multiplexer(*pins, demux=False, **kwargs)

Define a multiplexer or demultiplexer element

Parameters

pins – Pin definition dictionaries. See SchemDraw.elements.ic().

Keyword Arguments
m1 = elm.multiplexer({'name': 'C', 'side': 'L'},
                     {'name': 'B', 'side': 'L'},
                     {'name': 'A', 'side': 'L'},
                     {'name': 'Q', 'side': 'R'},
                     {'name': 'T', 'side': 'B', 'invert':True},
                     edgepadH=-.5)
d.add(m1)
../_images/electrical_20_0.svg