Skip to content

sparkfun/qwiic_led_stick_py

Repository files navigation

Qwiic LED_STICK - Python Package

SparkFun Qwiic LED_STICK - Python Package

PyPi Version GitHub issues License X API

The SparkFun Qwiic LED Stick LED_STICK Module provides a simple and cost effective solution for adding LED Stick 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.

This repository implements a Python package for the SparkFun Qwiic LED_STICK. This package works with Python, MicroPython and CircuitPython.

Contents

About the Package

This python package enables the user to access the features of the LED_STICK via a single Qwiic cable. This includes blinking LEDs, setting brightness, setting color and more. The capabilities of the LED_STICK are each demonstrated in the included examples.

New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.

Supported SparkFun Products

This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python.

Supported Platforms

Python Platform Boards
Python Linux Raspberry Pi , NVIDIA Jetson Orin Nano via the SparkFun Qwiic SHIM
MicroPython Raspberry Pi - RP2, ESP32 SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+
CircuitPython Raspberry Pi - RP2, ESP32 SparkFun RP2040 Thing+, SparkFun RP2350 Thing+, SparkFun ESP32 Thing+

Note

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.

Installation

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.

Python

PyPi Installation

The package is primarily installed using the pip3 command, downloading the package from the Python Index - "PyPi".

Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system.

First, setup a virtual environment from a specific directory using venv:

python3 -m venv path/to/venv

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.

Next, install the qwiic package with:

path/to/venv/bin/pip3 install sparkfun-qwiic-led_stick

Now you should be able to run any example or custom python scripts that have import qwiic_led_stick by running e.g.:

path/to/venv/bin/python3 example_script.py

MicroPython Installation

If not already installed, follow the instructions here to install mpremote on your computer.

Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.

mpremote mip install github:sparkfun/qwiic_led_stick_py

If you would also like to install the examples for this repository, issue the following mip command as well:

mpremote mip install --target "" github:sparkfun/qwiic_led_stick_py@examples

CircuitPython Installation

If not already installed, follow the instructions here to install CircUp on your computer.

Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.

circup bundle-add sparkfun/Qwiic_Py

Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.

circup install --py qwiic_led_stick

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. See the CircUp "example" command documentation for more information)

circup example qwiic_led_stick\qwiic_led_stick_ex10_change_address
circup example qwiic_led_stick\qwiic_led_stick_ex11_2_led_sticks
circup example qwiic_led_stick\qwiic_led_stick_ex1_blink
circup example qwiic_led_stick\qwiic_led_stick_ex2_single_pixel
circup example qwiic_led_stick\qwiic_led_stick_ex3_single_pixel2
circup example qwiic_led_stick\qwiic_led_stick_ex4_set_brightness
circup example qwiic_led_stick\qwiic_led_stick_ex5_binary_counter
circup example qwiic_led_stick\qwiic_led_stick_ex6_color_gradient
circup example qwiic_led_stick\qwiic_led_stick_ex7_cycle_rainbow
circup example qwiic_led_stick\qwiic_led_stick_ex8_walking_rainbow
circup example qwiic_led_stick\qwiic_led_stick_ex9_change_length

Example Use

Below is a quickstart program to print readings from the LED_STICK.

See the examples directory for more detailed use examples and examples/README.md for a summary of the available examples.

import qwiic_led_stick
import time
import sys

def run_example():

    print("\nSparkFun Qwiic LED Stick Example 1")
    my_stick = qwiic_led_stick.QwiicLEDStick()

    if my_stick.begin() == False:
        print("\nThe Qwiic LED Stick isn't connected to the sytsem. Please check your connection", \
            file=sys.stderr)
        return
    print("\nLED Stick ready!")
    
    my_stick.set_all_LED_brightness(15)

    while True:
        
        my_stick.set_all_LED_color(50, 50, 50)
        time.sleep(1)
        my_stick.LED_off()
        time.sleep(1)

if __name__ == '__main__':
    try:
        run_example()
    except (KeyboardInterrupt, SystemExit) as exErr:
        print("\nEnding Example 1")
        sys.exit(0)

SparkFun - Start Something