Skip to main content
Control digital input/output pins for digital signaling and control.

Import

There are two ways to use GPIO:
# Option 1: Net-based API
from lager import Net, NetType

# Option 2: Module-level functions
from lager.gpio import read, write, gpi, gpo

Methods

MethodDescription
input()Read digital pin state
output()Set digital pin state

Method Reference

Net.get(name, type=NetType.GPIO)

Get a GPIO net by name.
from lager import Net, NetType

pin = Net.get('LED', type=NetType.GPIO)
Parameters:
ParameterTypeDescription
namestrName of the GPIO net
typeNetTypeMust be NetType.GPIO
Returns: GPIO Net instance

input()

Read the digital state of the pin.
state = pin.input()
if state:
    print("Pin is HIGH")
else:
    print("Pin is LOW")
Returns: int - 0 for LOW, 1 for HIGH

output(level)

Set the digital state of the pin.
# Set HIGH
pin.output(1)

# Set LOW
pin.output(0)
ParameterTypeDescription
levelint or str0/1, “low”/“high”, “off”/“on”

Examples

Read Button State

from lager import Net, NetType

button = Net.get('BUTTON', type=NetType.GPIO)

state = button.input()
if state:
    print("Button pressed")
else:
    print("Button released")

Control LED

from lager import Net, NetType

led = Net.get('LED', type=NetType.GPIO)

# Turn on
led.output(1)

# Turn off
led.output(0)

Button-Controlled LED

from lager import Net, NetType
import time

button = Net.get('BUTTON', type=NetType.GPIO)
led = Net.get('LED', type=NetType.GPIO)

print("Press Ctrl+C to exit")

while True:
    try:
        if button.input():
            led.output(1)
        else:
            led.output(0)
        time.sleep(0.1)
    except KeyboardInterrupt:
        led.output(0)
        break

Toggle Output

from lager import Net, NetType
import time

output_pin = Net.get('SIGNAL', type=NetType.GPIO)

# Generate 10 pulses
for i in range(10):
    output_pin.output(1)
    time.sleep(0.5)
    output_pin.output(0)
    time.sleep(0.5)

Hardware Integration

HardwarePin Mapping
LabJack T7FIO0-FIO7, EIO0-EIO7, CIO0-CIO3

Pin Mapping

Pin NumberLabJack Channel
0FIO0
1FIO1
2FIO2
7FIO7

Module-Level Functions

For simple scripts, you can use module-level functions instead of the Net API:

read(net_name) / gpi(net_name)

Read the current state of a GPIO input pin.
from lager.gpio import read, gpi

# Both are equivalent
value = read('BUTTON')
value = gpi('BUTTON')

if value == 1:
    print("Button pressed!")
Parameters:
ParameterTypeDescription
net_namestrName of the GPIO net to read
Returns: int - 0 for LOW, 1 for HIGH

write(net_name, level) / gpo(net_name, level)

Set the output state of a GPIO pin.
from lager.gpio import write, gpo

# Both are equivalent
write('LED', 1)        # Turn on
gpo('LED', 0)          # Turn off

# String values also work
write('LED', 'high')   # Turn on
write('LED', 'off')    # Turn off
Parameters:
ParameterTypeDescription
net_namestrName of the GPIO net to set
levelint or str0/1, “low”/“high”, “off”/“on”

Module Functions vs Net API

# Module-level functions (simpler for quick operations)
from lager.gpio import read, write

value = read('BUTTON')
write('LED', 1)

# Net API (more consistent with other hardware types)
from lager import Net, NetType

button = Net.get('BUTTON', type=NetType.GPIO)
value = button.input()

led = Net.get('LED', type=NetType.GPIO)
led.output(1)
Both approaches work identically - choose based on your preference and code style.

Notes

  • GPIO nets work directly without enable()/disable() calls
  • Input returns 0 or 1
  • Output accepts integers (0/1) or strings (“high”/“low”, “on”/“off”)
  • Each operation opens and closes the LabJack connection
  • Net names must match those configured on the Lager Box
  • gpi and gpo are aliases for read and write (matching CLI command names)