Raspberry Pi OS
Prerequisites
To get maximum performance from your hardware, please make sure you'll meet the following requirements.
Operating System
We recommend using the latest version of Raspberry Pi OS. Download the latest version from raspberrypi.org/downloads/raspberry-pi-os address.
Python Library
Turta_RelayController library is responsible for controlling onboard relays.
To install the library from the (PyPI) Python Package Index, enter the following command to the console.
Add the following statement to the top of your Python code.
Then, create an instance of the Turta_RelayHAT class.
Now you're ready to access the library by calling the rc instance.
Initialization
The library automatically initializes the required components when its instance is being created, so there is no need to do a manual initialization.
Basic Members
Set Relay
Turns the desired relay on or off.
Parameters
Int ch: Relay channel. 1 to 4.
Bool st: Relay state. True or False.
Returns
None
Read Relay State
Reads the desired relay state.
Parameters
Int ch: Relay channel. 1 to 4.
Returns
Bool: Relay state. True or False.
Samples
You can copy the example code from https://github.com/Turta-io/RelayHAT/tree/master/Samples/Raspbian/Python address, and then copy it to the Raspberry Pi. There is one example of this sensor.
Relay Controller Sample App
This application demonstrates relay functions. It turns relays on and off in a loop.
To run the example:
Copy the library and sample code to a folder on the Raspberry Pi.
Open terminal, and go to the folder you copied the codes.
Run the sample with the following command:
Sample Code
Result
When you run the sample, the relays turn on one after another and then turn off in the same order. The application also writes the relay states to the terminal. The example output should be like this:
To stop the Python script, just press CTRL + C.
Last updated