Relay
This documentation includes installation guidelines and sample code for your hardware.
Python Library
Turta_Relay library is responsible for controlling onboard relays.
Initialization
Add the following statement to the top of your Python code.
Then, create an instance of the RelayController class.
Now you're ready to access the library by calling its instance.
Advanced Initialization
There are three advanced initialization parameters.
Parameters
Byte addr: Device address. 0x20 to 0x27. Default is 0x20.
Bool leds_state: True to enable, False to disable indicator LEDs. Default is True.
Bool preserve_state: Keeps relay states as they are, even if you reboot the Raspberry Pi. Default is False.
Stacking Relay HATs
If you're stacking Relay HATs, create an instance for each board.
Basic Members
Write (Control) Relay
Controls the relay.
Parameters
Byte ch: Relay channel. (1 to 5.)
Bool st: Relay state. (True or False.)
Returns
None
Write Once to Relays
Controls all the relays in one command.
Parameters
Byte st: Relay states. (0b00000 to 0b11111.)
Returns
None
Write (Control) All Relays
Turns on or off all the relays.
Parameters
Bool st: Relay states. (True or False.)
Returns
None
Toggle Relay
Inverts the relay's state.
Parameters
Byte ch: Relay channel. (1 to 5.)
Returns
None
Toggle All
Inverts all the relay states.
Parameters
None
Returns
None
Read Relay
Reads the relay state.
Parameters
Byte ch: Relay channel. (1 to 5.)
Returns
Bool: Relay state. (True or False.)
Read All Relay States
Reads all the relay states.
Parameters
None
Returns
Byte: Relay states. (0b00000 to 0b11111.)
Advanced Members
Set Indicator LEDs
Enables or disables the indicator LEDs. Useful if you're stacking a few Relay HATs.
Parameters
Bool st: Indicator LEDs state. (True or False.)
Returns
None
Finalizer
When exiting from the program, the library sets all the relays off if preserve state setting is not enabled.
Last updated