|
1 |
| -Qwiic_Relay_Py |
2 |
| -================== |
3 |
| -<p align="center"> |
4 |
| - <img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-logo-registered.jpg" width=200> |
5 |
| - <img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240> |
6 |
| -</p> |
7 |
| -<p align="center"> |
8 |
| - <a href="https://pypi.org/project/sparkfun-qwiic-relay/" alt="Package"> |
9 |
| - <img src="https://img.shields.io/pypi/pyversions/sparkfun-qwiic-relay.svg" /></a> |
10 |
| - <a href="https://github.com/sparkfun/Qwiic_Relay_Py/issues" alt="Issues"> |
11 |
| - <img src="https://img.shields.io/github/issues/sparkfun/Qwiic_Relay_Py.svg" /></a> |
12 |
| - <a href="https://sparkfun-qwiic-relay.readthedocs.io/en/latest/?" alt="Documentation"> |
13 |
| - <img src="https://readthedocs.org/projects/sparkfun-qwiic-relay/badge/?version=latest&style=flat" /></a> |
14 |
| - <a href="https://github.com/sparkfun/Qwiic_Relay_Py/blob/master/LICENSE" alt="License"> |
15 |
| - <img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a> |
16 |
| - <a href="https://twitter.com/intent/follow?screen_name=sparkfun"> |
17 |
| - <img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter" |
18 |
| - alt="follow on Twitter"></a> |
19 |
| - |
20 |
| -</p> |
| 1 | + |
21 | 2 |
|
22 |
| -<img src="https://cdn.sparkfun.com/assets/parts/1/5/7/5/4/16833-SparkFun_Qwiic_Quad_Solid_State_Relay_Kit-01.jpg" align="right" width=300 alt="SparkFun Qwiic Solid State Relay"> |
| 3 | +# SparkFun Qwiic RELAY - Python Package |
23 | 4 |
|
24 |
| -Python module for the Qwiic Relays, Listed below |
25 |
| -* [SparkFun Qwiic Single Relay](https://www.sparkfun.com/products/15093) |
26 |
| -* [SparkFun Qwiic Quad Relay](https://www.sparkfun.com/products/15102) |
27 |
| -* [SparkFun Qwiic Quad Solid State Relay](https://www.sparkfun.com/products/16833) |
28 |
| -* [SparkFun Qwiic Dual Solid State Relay](https://www.sparkfun.com/products/16810) |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[](https://docs.sparkfun.com/qwiic_relay_py/classqwiic__relay_1_1_qwiic_relay.html) |
29 | 10 |
|
30 |
| -This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py) |
| 11 | +The SparkFun Qwiic Relay RELAY Module provides a simple and cost effective solution for adding Relay capabilities to your project. Implementing a SparkFun Qwiic I2C interface, these sensors can be rapidly added to any project with boards that are part of the SparkFun Qwiic ecosystem. |
31 | 12 |
|
32 |
| -New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
| 13 | +This repository implements a Python package for the SparkFun Qwiic RELAY. This package works with Python, MicroPython and CircuitPython. |
33 | 14 |
|
34 |
| -## Contents |
| 15 | +### Contents |
35 | 16 |
|
36 |
| -* [Supported Platforms](#supported-platforms) |
37 |
| -* [Dependencies](#dependencies) |
| 17 | +* [About](#about-the-package) |
| 18 | +* [Getting Started](#getting-started) |
38 | 19 | * [Installation](#installation)
|
39 |
| -* [Documentation](#documentation) |
40 |
| -* [Example Use](#example-use) |
| 20 | +* [Supported Platforms](#supported-platforms) |
| 21 | +* [Documentation](https://docs.sparkfun.com/qwiic_relay_py/classqwiic__relay_1_1_qwiic_relay.html) |
| 22 | +* [Examples](#examples) |
| 23 | + |
| 24 | +## About the Package |
| 25 | + |
| 26 | +This python package enables the user to access the features of the RELAY via a single Qwiic cable. This includes <setting relay state, reading relay state, set slow PWM value> and more. The capabilities of the RELAY are each demonstrated in the included examples. |
| 27 | + |
| 28 | +New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
41 | 29 |
|
42 |
| -Supported Platforms |
43 |
| --------------------- |
44 |
| -The Qwiic Relay Python package current supports the following platforms: |
45 |
| -* [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) |
| 30 | +### Supported SparkFun Products |
46 | 31 |
|
47 |
| -Dependencies |
48 |
| ---------------- |
49 |
| -This driver package depends on the qwiic I2C driver: |
50 |
| -[Qwiic_I2C_Py](https://github.com/sparkfun/Qwiic_I2C_Py) |
| 32 | +This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python. |
51 | 33 |
|
52 |
| -Documentation |
53 |
| -------------- |
54 |
| -The SparkFun Qwiic Relay module documentation is hosted at [ReadTheDocs](https://sparkfun-qwiic-relay.readthedocs.io/en/latest/?) |
| 34 | +* [SparkFun Relay Sensor - RELAY](http://www.sparkfun.com/qwiic) |
55 | 35 |
|
56 |
| -Installation |
57 |
| -------------- |
| 36 | +### Supported Platforms |
58 | 37 |
|
59 |
| -### PyPi Installation |
60 |
| -This repository is hosted on PyPi as the [sparkfun-qwiic-relay](https://pypi.org/project/sparkfun-qwiic-relay/) package. On systems that support PyPi installation via pip, this library is installed using the following commands |
| 38 | +| Python | Platform | Boards | |
| 39 | +|--|--|--| |
| 40 | +| Python | Linux | [Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html) | |
| 41 | +| MicroPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
| 42 | +|CircuitPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
61 | 43 |
|
62 |
| -For all users (note: the user must have sudo privileges): |
| 44 | +> [!NOTE] |
| 45 | +> The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems. |
| 46 | +
|
| 47 | +## Installation |
| 48 | + |
| 49 | +The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython. |
| 50 | + |
| 51 | +### Python |
| 52 | + |
| 53 | +#### PyPi Installation |
| 54 | + |
| 55 | +The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi". |
| 56 | + |
| 57 | +Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system. |
| 58 | + |
| 59 | +First, setup a virtual environment from a specific directory using venv: |
63 | 60 | ```sh
|
64 |
| -sudo pip install sparkfun-qwiic-relay |
| 61 | +python3 -m venv path/to/venv |
65 | 62 | ```
|
66 |
| -For the current user: |
| 63 | +You can pass any path as path/to/venv, just make sure you use the same one for all future steps. For more information on venv [click here](https://docs.python.org/3/library/venv.html). |
67 | 64 |
|
| 65 | +Next, install the qwiic package with: |
68 | 66 | ```sh
|
69 |
| -pip install sparkfun-qwiic-relay |
| 67 | +path/to/venv/bin/pip3 install sparkfun-qwiic-relay |
| 68 | +``` |
| 69 | +Now you should be able to run any example or custom python scripts that have `import qwiic_relay` by running e.g.: |
| 70 | +```sh |
| 71 | +path/to/venv/bin/python3 example_script.py |
70 | 72 | ```
|
71 | 73 |
|
72 |
| -### Local Installation |
73 |
| -To install, make sure the `setuptools` package is installed on the system. |
| 74 | +### MicroPython Installation |
| 75 | +If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer. |
74 | 76 |
|
75 |
| -Direct installation at the command line: |
| 77 | +Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip. |
76 | 78 | ```sh
|
77 |
| -python setup.py install |
| 79 | +mpremote mip install github:sparkfun/qwiic_relay_py |
78 | 80 | ```
|
79 | 81 |
|
80 |
| -To build a package for use with pip: |
| 82 | +If you would also like to install the examples for this repository, issue the following mip command as well: |
81 | 83 | ```sh
|
82 |
| -python setup.py sdist |
83 |
| - ``` |
84 |
| -A package file is built and placed in a subdirectory called dist. This package file can be installed using pip. |
| 84 | +mprmeote mip install github:sparkfun/qwiic_relay_py@examples |
| 85 | +``` |
| 86 | + |
| 87 | +### CircuitPython Installation |
| 88 | +If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer. |
| 89 | + |
| 90 | +Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle. |
| 91 | +```sh |
| 92 | +circup bundle-add sparkfun/Qwiic_Py |
| 93 | +``` |
| 94 | + |
| 95 | +Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup. |
85 | 96 | ```sh
|
86 |
| -cd dist |
87 |
| -pip install sparkfun_qwiic_relay-<version>.tar.gz |
88 |
| - |
| 97 | +circup install --py qwiic_relay |
89 | 98 | ```
|
| 99 | + |
| 100 | +If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUp on Windows. Linux and Mac will have different path seperators (i.e. "/" vs. "\"). See the [CircUp "example" command documentation](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command) for more information) |
| 101 | + |
| 102 | +```sh |
| 103 | +circup example qwiic_relay\qwiic_relay_ex1_single |
| 104 | +circup example qwiic_relay\qwiic_relay_ex2_dual |
| 105 | +circup example qwiic_relay\qwiic_relay_ex3_quad |
| 106 | +circup example qwiic_relay\qwiic_relay_ex4_pwm |
| 107 | +``` |
| 108 | + |
90 | 109 | Example Use
|
91 | 110 | ---------------
|
92 |
| -See the examples directory for more detailed use examples. |
| 111 | +Below is a quickstart program to print readings from the RELAY. |
| 112 | + |
| 113 | +See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_relay_py/blob/main/examples/README.md) for a summary of the available examples. |
93 | 114 |
|
94 | 115 | ```python
|
95 |
| -from __future__ import print_function |
| 116 | + |
96 | 117 | import qwiic_relay
|
97 | 118 | import time
|
98 | 119 | import sys
|
99 | 120 |
|
100 |
| -myRelays = qwiic_relay.QwiicRelay() |
| 121 | +myRelay = qwiic_relay.QwiicRelay(qwiic_relay.SINGLE_RELAY_DEFUALT_ADDR) |
101 | 122 |
|
102 | 123 | def runExample():
|
| 124 | + print("\nSparkFun Qwiic Relay Example 1 - Single\n") |
103 | 125 |
|
104 |
| - print("\nSparkFun Qwiic Relay Example 1\n") |
105 |
| - |
106 |
| - if myRelays.begin() == False: |
| 126 | + if myRelay.begin() == False: |
107 | 127 | print("The Qwiic Relay isn't connected to the system. Please check your connection", \
|
108 | 128 | file=sys.stderr)
|
109 | 129 | return
|
110 | 130 |
|
111 |
| - #Turn on relays one and three |
112 |
| - myRelays.set_relay_on(1) |
113 |
| - myRelays.set_relay_on(3) |
114 |
| - time.sleep(1) |
115 |
| - |
116 |
| - #Print the status of all relays |
117 |
| - for relayNum in range(4): |
118 |
| - current_status = None |
119 |
| - if myRelays.get_relay_state(relayNum) is True: |
120 |
| - current_status = "On" |
121 |
| - else: |
122 |
| - current_status = "Off" |
123 |
| - print("Status 1: " + current_status + "\n") |
124 |
| - |
125 |
| - #Turn off 1 and 3, turn on 2 and 4 |
126 |
| - myRelays.set_relay_off(1) |
127 |
| - myRelays.set_relay_on(2) |
128 |
| - myRelays.set_relay_off(3) |
129 |
| - myRelays.set_relay_on(4) |
130 |
| - time.sleep(1) |
131 |
| - |
| 131 | + for i in range(2): |
| 132 | + myRelay.set_relay_on() |
132 | 133 |
|
133 |
| - #Turn all relays on, then turn them all off |
134 |
| - myRelays.set_all_relays_on() |
135 |
| - time.sleep(1) |
136 |
| - |
137 |
| - myRelays.set_all_relays_off() |
138 |
| - |
| 134 | + print("Relay state: " + str(myRelay.get_relay_state())) |
| 135 | + |
| 136 | + time.sleep(1) |
| 137 | + |
| 138 | + myRelay.set_relay_off() |
| 139 | + |
| 140 | + print("Relay state: " + str(myRelay.get_relay_state())) |
139 | 141 |
|
| 142 | + time.sleep(1) |
140 | 143 |
|
141 | 144 | if __name__ == '__main__':
|
142 | 145 | try:
|
|
0 commit comments