Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: Copyright (c) 2022 Graham Beland
2#
3# SPDX-License-Identifier: MIT
4
5# import the CircuitPython board and busio libraries
6import board
7import sparkfun_qwiicquadsolidstaterelay
8
9# Create bus object using the board's I2C port
10i2c = board.I2C()
11
12# Note: default i2c address is 8
13relay = None
14try:
15 relay = sparkfun_qwiicquadsolidstaterelay.Sparkfun_QwiicQuadSolidStateRelay(i2c)
16 print("Opened: Relay Controller")
17 if relay.connected:
18 print("Relay connected. ")
19 else:
20 print("Relay does not appear to be connected. Please check wiring. ")
21except ValueError as e:
22 print("Error: Could not open Relay Controller rxception:" + str(e))
23
24# For a different address use QwiicRelay(i2c, address)
25# Warning - this is stored in non-volitile memory and you must remember the setting
26# to change it back to the default address of 8.
27# relay.set_i2c_address(9)
28
29relay.relay_on(1)
30relay.relay_on(2)
31relay.relay_on(3)
32relay.relay_on(4)
33relay.relay_off(1)
34relay.relay_off(4)
35relay.relay_all_toggle()
36relay.relay_all_on()
37relay.relay_all_off()