Qwiic_Relay_Py¶
Python module for the Qwiic Relays, Listed below
- SparkFun Qwiic Single Relay
- SparkFun Qwiic Quad Relay
- SparkFun Qwiic Quad Solid State Relay
- SparkFun Qwiic Dual Solid State Relay
This package can be used in conjunction with the overall SparkFun qwiic Python Package
New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.
Supported Platforms¶
The Qwiic Relay Python package current supports the following platforms:
Dependencies¶
This driver package depends on the qwiic I2C driver: Qwiic_I2C_Py
Documentation¶
The SparkFun Qwiic Relay module documentation is hosted at ReadTheDocs
Installation¶
PyPi Installation¶
This repository is hosted on PyPi as the sparkfun-qwiic-relay package. On systems that support PyPi installation via pip, this library is installed using the following commands
For all users (note: the user must have sudo privileges):
sudo pip install sparkfun-qwiic-relay
For the current user:
pip install sparkfun-qwiic-relay
Local Installation¶
To install, make sure the setuptools
package is installed on the system.
Direct installation at the command line:
python setup.py install
To build a package for use with pip:
python setup.py sdist
A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.
cd dist
pip install sparkfun_qwiic_relay-<version>.tar.gz
Example Use¶
See the examples directory for more detailed use examples.
from __future__ import print_function
import qwiic_relay
import time
import sys
myRelays = qwiic_relay.QwiicRelay()
def runExample():
print("\nSparkFun Qwiic Relay Example 1\n")
if myRelays.begin() == False:
print("The Qwiic Relay isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
#Turn on relays one and three
myRelays.set_relay_on(1)
myRelays.set_relay_on(3)
time.sleep(1)
#Print the status of all relays
for relayNum in range(4):
current_status = None
if myRelays.get_relay_state(relayNum) is True:
current_status = "On"
else:
current_status = "Off"
print("Status 1: " + current_status + "\n")
#Turn off 1 and 3, turn on 2 and 4
myRelays.set_relay_off(1)
myRelays.set_relay_on(2)
myRelays.set_relay_off(3)
myRelays.set_relay_on(4)
time.sleep(1)
#Turn all relays on, then turn them all off
myRelays.set_all_relays_on()
time.sleep(1)
myRelays.set_all_relays_off()
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding Example 1")
sys.exit(0)