|
| 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-top-phat-button/" alt="Package"> |
| 9 | + <img src="https://img.shields.io/pypi/pyversions/sparkfun-top-phat-button.svg" /></a> |
| 10 | + <a href="https://github.com/sparkfun/Top_pHAT_Button_Py/issues" alt="Issues"> |
| 11 | + <img src="https://img.shields.io/github/issues/sparkfun/Top_pHAT_Button_Py.svg" /></a> |
| 12 | + <a href="https://sparkfun-top-phat-button.readthedocs.io/en/latest/?" alt="Documentation"> |
| 13 | + <img src="https://readthedocs.org/projects/sparkfun-top-phat-button/badge/?version=latest&style=flat" /></a> |
| 14 | + <a href="https://github.com/sparkfun/Top_pHAT_Button_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> |
| 21 | + |
| 22 | +<img src="https://cdn.sparkfun.com/assets/parts/1/5/0/0/3/16301-SparkFun_Top_pHAT_for_Raspberry_Pi-01.jpg" align="right" width=300 alt="SparkFun Top pHAT"> |
| 23 | + |
| 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 Dual Solid State Relay](https://www.sparkfun.com/products/16810) |
| 28 | +* [SparkFun Qwiic Quad Solid State Relay](https://www.sparkfun.com/products/16796) |
| 29 | + |
| 30 | +This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py) |
| 31 | + |
| 32 | +New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
| 33 | + |
| 34 | +## Contents |
| 35 | + |
| 36 | +* [Supported Platforms](#supported-platforms) |
| 37 | +* [Dependencies](#dependencies) |
| 38 | +* [Installation](#installation) |
| 39 | +* [Documentation](#documentation) |
| 40 | +* [Example Use](#example-use) |
| 41 | + |
| 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) |
| 46 | + |
| 47 | +Dependencies |
| 48 | +--------------- |
| 49 | +This driver package depends on the qwiic I2C driver: |
| 50 | +[Qwiic_I2C_Py](https://github.com/sparkfun/Qwiic_I2C_Py) |
| 51 | + |
| 52 | +Documentation |
| 53 | +------------- |
| 54 | +The SparkFun Qwiic Relay module documentation is hosted at [ReadTheDocs](https://sparkfun-qwiic-relay.readthedocs.io/en/latest/?) |
| 55 | + |
| 56 | +Installation |
| 57 | +------------- |
| 58 | + |
| 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 |
| 61 | + |
| 62 | +For all users (note: the user must have sudo privileges): |
| 63 | +```sh |
| 64 | +sudo pip install sparkfun-qwiic-relay |
| 65 | +``` |
| 66 | +For the current user: |
| 67 | + |
| 68 | +```sh |
| 69 | +pip install sparkfun-qwiic-relay |
| 70 | +``` |
| 71 | + |
| 72 | +### Local Installation |
| 73 | +To install, make sure the setuptools package is installed on the system. |
| 74 | + |
| 75 | +Direct installation at the command line: |
| 76 | +```sh |
| 77 | +python setup.py install |
| 78 | +``` |
| 79 | + |
| 80 | +To build a package for use with pip: |
| 81 | +```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. |
| 85 | +```sh |
| 86 | +cd dist |
| 87 | +pip install sparkfun_qwiic_relay-<version>.tar.gz |
| 88 | + |
| 89 | +``` |
| 90 | +Example Use |
| 91 | + --------------- |
| 92 | +See the examples directory for more detailed use examples. |
| 93 | + |
| 94 | +```python |
| 95 | +from __future__ import print_function |
| 96 | +import top_phat_button |
| 97 | +import time |
| 98 | +import sys |
| 99 | + |
| 100 | +myButtons = top_phat_button.ToppHATButton() |
| 101 | + |
| 102 | +def runExample(): |
| 103 | + |
| 104 | + print("\nSparkFun Top pHAT Button Example 1\n") |
| 105 | + |
| 106 | + if myButtons.is_connected() == False: |
| 107 | + print("The Top pHAT Button device isn't connected to the system. Please check your connection", \ |
| 108 | + file=sys.stderr) |
| 109 | + return |
| 110 | + |
| 111 | + myButtons.pressed_interrupt_enable = False |
| 112 | + myButtons.clicked_interrupt_enable = False |
| 113 | + |
| 114 | + while True: |
| 115 | + myButtons.button_pressed #These functions must be called to update button variables to their latest setting |
| 116 | + myButtons.button_clicked #These functions must be called to update button variables to their latest setting |
| 117 | + if myButtons.a_pressed == True: |
| 118 | + print("A Pressed") |
| 119 | + if myButtons.a_clicked == True: |
| 120 | + print("A Released") |
| 121 | + if myButtons.b_pressed == True: |
| 122 | + print("B Pressed") |
| 123 | + if myButtons.b_clicked == True: |
| 124 | + print("B Released") |
| 125 | + if myButtons.up_pressed == True: |
| 126 | + print("Up Pressed") |
| 127 | + if myButtons.up_clicked == True: |
| 128 | + print("Up Released") |
| 129 | + if myButtons.down_pressed == True: |
| 130 | + print("Down Pressed") |
| 131 | + if myButtons.down_clicked == True: |
| 132 | + print("Down Released") |
| 133 | + if myButtons.left_pressed == True: |
| 134 | + print("Left Pressed") |
| 135 | + if myButtons.left_clicked == True: |
| 136 | + print("Left Released") |
| 137 | + if myButtons.right_pressed == True: |
| 138 | + print("Right Pressed") |
| 139 | + if myButtons.right_clicked == True: |
| 140 | + print("Right Released") |
| 141 | + if myButtons.center_pressed == True: |
| 142 | + print("Center Pressed") |
| 143 | + if myButtons.center_clicked == True: |
| 144 | + print("Center Released") |
| 145 | + |
| 146 | + time.sleep(.1) |
| 147 | + |
| 148 | + |
| 149 | +if __name__ == '__main__': |
| 150 | + try: |
| 151 | + runExample() |
| 152 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 153 | + print("\nEnding Example 1") |
| 154 | + sys.exit(0) |
| 155 | + |
| 156 | +``` |
| 157 | +<p align="center"> |
| 158 | +<img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something"> |
| 159 | +</p> |
0 commit comments