surrortg.devices

Classes

surrortg.devices.led

class LED(pin, initial_state_off=True)

Bases: object

Simple to use LED class implemented with pigpio

Parameters
  • pin (int) – GPIO pin number

  • initial_state_off (bool, optional) – Determines whether the LED should be turned off when initialized. If set to False, the LED is turned on at init. Defaults to True.

Raises
  • RuntimeError – If cannot connect to pigpio daemon

  • RuntimeError – If methods are called after calling stop

on()

Turns the LED on

off()

Turns the LED off

toggle()

Toggles the LED’s state

Turns the LED on if the state was previously off, and vice versa.

Blinks the LED once, waiting blink_time seconds in between

Parameters

blink_time (float or int) – Time in seconds to wait between turning the LED on and off

start_blinking(blinking_rate, on_off_ratio=1)

Starts blinking the LED in the background

Parameters
  • blinking_rate (float or int) – Rate of the blinking, i.e. how many times the LED blinks in a second.

  • on_off_ratio (float or int, optional) – Ratio between on and off time, defaults to 1.

stop_blinking()

Stops any active blinking of the LED

is_on()

Checks if the LED is turned on

Returns

True if the LED is turned on

Return type

bool

is_off()

Checks if the LED is turned off

Returns

True if the LED is turned off

Return type

bool

is_blinking()

Checks if the LED is blinking

Returns

True if the LED is blinking

Return type

bool

stop()

Sets the pin to input state and stops pigpio daemon connection

surrortg.devices.relay

class Relay(pin, on_level_low=True, initial_state_off=True)

Bases: object

Simple to use relay class implemented with pigpio

Parameters
  • pin (int) – GPIO pin number

  • on_level_low (bool, optional) – Determines the logic level of the on-state. If set to True, the relay is on when the GPIO pin state is LOW. Defaults to True.

  • initial_state_off (bool, optional) – Determines whether the relay should be set to off-state when initialized. If set to False, the relay is set to on-state at init. Defaults to True.

Raises
  • RuntimeError – If cannot connect to pigpio daemon

  • RuntimeError – If methods are called after calling stop

on()

Turns the relay on

off()

Turns the relay off

toggle()

Toggles the relay’s state

Turns the relay on if the state was previously off, and vice versa.

async press_once(press_time)

Turns the relay on and off, waiting press_time seconds in between

Parameters

press_time (float or int) – Time in seconds to wait between turning the relay on and off

is_on()

Checks if the relay is turned on

Returns

True if the relay is turned on

Return type

bool

is_off()

Checks if the relay is turned off

Returns

True if the relay is turned off

Return type

bool

on_level_is_low()

Checks if the relay is on when the GPIO state is LOW

Returns

True if the relay is on when the GPIO state is LOW

Return type

bool

stop()

Sets the pin to input state and stops pigpio daemon connection

surrortg.devices.servo

class Servo(pin, min_pulse_width=500, max_pulse_width=2500, min_full_sweep_time=0.5, rotation_update_freq=25)

Bases: object

property position
Parameters

position – Servo position between -1 and 1

Returns

0 is in the middle, negative positions are on the left and positive are on the right

Return type

int

property rotation_speed
Parameters

rotation_speed – Servo rotation speed between -1 and 1

0 stops the servo, positive value rotates clockwise and negative counterclockwise. When end position is reached, servo stops and the rotation_speed updates to 0.

Returns

rotation speed value between -1 and 1

Return type

int

async rotate_to(position, rotation_speed=None)

Rotate to some position, optionally with a spesific speed

Parameters
  • position (int) – position between -1 and 1, see position property

  • rotation_speed (int, optional) – rotation speed between -1 and 1, see rotation_speed property. Defaults to None, which is changed to the max speed in the correct direction.

detach()

Stops servo rotation and releases active servo control

stop()

Detaches servo and stops pigpio daemon connection