|
1 | | -Qwiic_SCMD_Py |
2 | | -============== |
| 1 | + |
3 | 2 |
|
4 | | -<p align="center"> |
5 | | - <img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-logo-registered.jpg" width=200> |
6 | | - <img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240> |
7 | | -</p> |
8 | | -<p align="center"> |
9 | | - <a href="https://pypi.org/project/sparkfun-qwiic-scmd/" alt="Package"> |
10 | | - <img src="https://img.shields.io/pypi/pyversions/sparkfun_qwiic_scmd.svg" /></a> |
11 | | - <a href="https://github.com/sparkfun/Qwiic_SCMD_Py/issues" alt="Issues"> |
12 | | - <img src="https://img.shields.io/github/issues/sparkfun/Qwiic_SCMD_Py.svg" /></a> |
13 | | - <a href="https://qwiic-scmd-py.readthedocs.io/en/latest/?" alt="Documentation"> |
14 | | - <img src="https://readthedocs.org/projects/qwiic-scmd-py/badge/?version=latest&style=flat" /></a> |
15 | | - <a href="https://github.com/sparkfun/Qwiic_SCMD_Py/blob/master/LICENSE" alt="License"> |
16 | | - <img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a> |
17 | | - <a href="https://twitter.com/intent/follow?screen_name=sparkfun"> |
18 | | - <img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter" |
19 | | - alt="follow on Twitter"></a> |
20 | | - |
21 | | -</p> |
| 3 | +# SparkFun Qwiic SCMD - Python Package |
22 | 4 |
|
23 | | -<img src="https://cdn.sparkfun.com//assets/parts/1/4/0/2/9/15451-SparkFun_Qwiic_Motor_Driver-01.jpg" align="right" width=300> |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[](https://docs.sparkfun.com/qwiic_scmd_py/classqwiic__scmd_1_1_qwiic_scmd.html) |
24 | 10 |
|
25 | | -Python module for the [qwiic motor driver](https://www.sparkfun.com/products/15451) |
| 11 | +The SparkFun Qwiic Motor Driver SCMD Module provides a simple and cost effective solution for adding Motor Driver 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. |
26 | 12 |
|
27 | | -This python package is a port of the existing [SparkFun Serial Controlled Motor Driver Arduino Library](https://github.com/sparkfun/SparkFun_Serial_Controlled_Motor_Driver_Arduino_Library) |
| 13 | +This repository implements a Python package for the SparkFun Qwiic SCMD. This package works with Python, MicroPython and CircuitPython. |
28 | 14 |
|
29 | | -This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py) |
| 15 | +### Contents |
| 16 | + |
| 17 | +* [About](#about-the-package) |
| 18 | +* [Getting Started](#getting-started) |
| 19 | +* [Installation](#installation) |
| 20 | +* [Supported Platforms](#supported-platforms) |
| 21 | +* [Documentation](https://docs.sparkfun.com/qwiic_scmd_py/classqwiic__scmd_1_1_qwiic_scmd.html) |
| 22 | +* [Examples](#examples) |
| 23 | + |
| 24 | +## About the Package |
| 25 | + |
| 26 | +This python package enables the user to access the features of the SCMD via a single Qwiic cable. This includes <driving a single motor, driving two motors> and more. The capabilities of the SCMD are each demonstrated in the included examples. |
30 | 27 |
|
31 | 28 | New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
32 | 29 |
|
33 | | -## Contents |
| 30 | +### Supported SparkFun Products |
34 | 31 |
|
35 | | -* [Supported Plaforms](#supported-platforms) |
36 | | -* [Dependencies](#dependencies) |
37 | | -* [Installation](#installation) |
38 | | -* [Documentation](#documentation) |
39 | | - |
40 | | -Supported Platforms |
41 | | --------------------- |
42 | | -The qwiic Python package current supports the following platforms: |
43 | | -* [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) |
44 | | -* [NVidia Jetson Nano](https://www.sparkfun.com/products/15297) |
45 | | -* [Google Coral Development Board](https://www.sparkfun.com/products/15318) |
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 SCMD module documentation is hosted at [ReadTheDocs](https://qwiic-scmd-py.readthedocs.io/en/latest/index.html) |
55 | | - |
56 | | -Installation |
57 | | ---------------- |
58 | | -### PyPi Installation |
59 | | -This repository is hosted on PyPi as the [sparkfun-qwiic-scmd](https://pypi.org/project/sparkfun-qwiic-scmd/) package. On systems that support PyPi installation via pip, this library is installed using the following commands |
60 | | - |
61 | | -For all users (note: the user must have sudo privileges): |
| 32 | +This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python. |
| 33 | + |
| 34 | +* [SparkFun Motor Driver Sensor - SCMD](https://www.sparkfun.com/qwiic) |
| 35 | + |
| 36 | +### Supported Platforms |
| 37 | + |
| 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) |
| 43 | + |
| 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: |
62 | 60 | ```sh |
63 | | -sudo pip install sparkfun-qwiic-scmd |
| 61 | +python3 -m venv path/to/venv |
64 | 62 | ``` |
65 | | -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). |
66 | 64 |
|
| 65 | +Next, install the qwiic package with: |
67 | 66 | ```sh |
68 | | -pip install sparkfun-qwiic-scmd |
| 67 | +path/to/venv/bin/pip3 install sparkfun-qwiic-scmd |
69 | 68 | ``` |
| 69 | +Now you should be able to run any example or custom python scripts that have `import qwiic_scmd` by running e.g.: |
| 70 | +```sh |
| 71 | +path/to/venv/bin/python3 example_script.py |
| 72 | +``` |
| 73 | + |
| 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. |
70 | 76 |
|
71 | | -### Local Installation |
72 | | -To install, make sure the setuptools package is installed on the system. |
| 77 | +Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip. |
| 78 | +```sh |
| 79 | +mpremote mip install github:sparkfun/qwiic_scmd_py |
| 80 | +``` |
73 | 81 |
|
74 | | -Direct installation at the command line: |
| 82 | +If you would also like to install the examples for this repository, issue the following mip command as well: |
75 | 83 | ```sh |
76 | | -python setup.py install |
| 84 | +mprmeote mip install github:sparkfun/qwiic_scmd_py@examples |
77 | 85 | ``` |
78 | 86 |
|
79 | | -To build a package for use with pip: |
| 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. |
80 | 91 | ```sh |
81 | | -python setup.py sdist |
82 | | - ``` |
83 | | -A package file is built and placed in a subdirectory called dist. This package file can be installed using pip. |
| 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. |
| 96 | +```sh |
| 97 | +circup install --py qwiic_scmd |
| 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 | + |
84 | 102 | ```sh |
85 | | -cd dist |
86 | | -pip install sparkfun_qwiic_scmd-<version>.tar.gz |
87 | | - |
| 103 | +circup example qwiic_scmd\ex1_qwiic_scmd_basic |
| 104 | +circup example qwiic_scmd\ex2_qwiic_scmd_two_motor |
88 | 105 | ``` |
89 | | - Example Use |
90 | | - ------------- |
91 | | - ``` |
92 | | - TBD |
93 | | - |
94 | | - ``` |
95 | 106 |
|
| 107 | +Example Use |
| 108 | + --------------- |
| 109 | +Below is a quickstart program to print readings from the SCMD. |
| 110 | + |
| 111 | +See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_scmd_py/blob/main/examples/README.md) for a summary of the available examples. |
| 112 | + |
| 113 | +```python |
| 114 | + |
| 115 | +import time |
| 116 | +import sys |
| 117 | +import math |
| 118 | +import qwiic_scmd |
| 119 | + |
| 120 | +myMotor = qwiic_scmd.QwiicScmd() |
| 121 | + |
| 122 | +def runExample(): |
| 123 | + print("Motor Test.") |
| 124 | + R_MTR = 0 |
| 125 | + L_MTR = 1 |
| 126 | + FWD = 0 |
| 127 | + BWD = 1 |
| 128 | + |
| 129 | + if myMotor.connected == False: |
| 130 | + print("Motor Driver not connected. Check connections.", \ |
| 131 | + file=sys.stderr) |
| 132 | + return |
| 133 | + myMotor.begin() |
| 134 | + print("Motor initialized.") |
| 135 | + time.sleep(.250) |
| 136 | + |
| 137 | + myMotor.set_drive(0,0,0) |
| 138 | + myMotor.set_drive(1,0,0) |
| 139 | + |
| 140 | + myMotor.enable() |
| 141 | + print("Motor enabled") |
| 142 | + time.sleep(.250) |
| 143 | + |
| 144 | + |
| 145 | + while True: |
| 146 | + speed = 20 |
| 147 | + for speed in range(20,255): |
| 148 | + print(speed) |
| 149 | + myMotor.set_drive(R_MTR,FWD,speed) |
| 150 | + time.sleep(.05) |
| 151 | + for speed in range(254,20, -1): |
| 152 | + print(speed) |
| 153 | + myMotor.set_drive(R_MTR,FWD,speed) |
| 154 | + time.sleep(.05) |
| 155 | + |
| 156 | +if __name__ == '__main__': |
| 157 | + try: |
| 158 | + runExample() |
| 159 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 160 | + print("Ending example.") |
| 161 | + myMotor.disable() |
| 162 | + sys.exit(0) |
| 163 | + |
| 164 | +``` |
96 | 165 | <p align="center"> |
97 | 166 | <img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something"> |
98 | 167 | </p> |
0 commit comments