Skip to content

Commit d2f49b5

Browse files
authored
Merge pull request #3 from pimoroni/dev
Development
2 parents 164ee65 + c3e4dd5 commit d2f49b5

File tree

16 files changed

+421
-118
lines changed

16 files changed

+421
-118
lines changed

.github/workflows/python-linting.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@ on:
77
jobs:
88
build:
99
name: Python Linting
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- name: Checkout Source
13+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
14+
15+
- name: Install Python
16+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
17+
with:
18+
python-version: '3.13'
1319

1420
- name: Install Python Deps
15-
run: |
16-
python3 -m venv .venv
17-
source .venv/bin/activate
18-
python -m pip install flake8
21+
run: source ci/python.sh && qa_prepare_all
1922

2023
- name: Lint MicroPython Examples
2124
shell: bash
22-
run: |
23-
source .venv/bin/activate
24-
python -m flake8 --show-source --ignore E501 examples/
25+
run: source ci/python.sh && qa_examples_check
2526

2627
- name: Lint MicroPython Modules
2728
shell: bash
28-
run: |
29-
source .venv/bin/activate
30-
python -m flake8 --show-source --ignore E501 modules/
29+
run: source ci/python.sh && qa_modules_check

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Build dirs
35+
**/build
36+
build-*
37+
build
38+
39+
# Apple filesystem cruft
40+
.DS_Store
41+
42+
# Other cruft
43+
venv
44+
.vscode
45+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ For each board there are two choices, a regular build that just updates the firm
5858

5959
* [Learn: Getting started with Plasma 2040](https://learn.pimoroni.com/article/plasma-2040)
6060
* [Learn: Assembling Wireless Plasma Kit](https://learn.pimoroni.com/article/assembling-wireless-plasma-kit)
61+
* [Plasma documentation](docs/plasma.md)
6162

6263
## Other Resources
6364

ci/micropython.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export TERM=${TERM:="xterm-256color"}
22

33
MICROPYTHON_FLAVOUR="pimoroni"
4-
MICROPYTHON_VERSION="feature/pico2_w_2025_3_11"
4+
MICROPYTHON_VERSION="v1.25.0-and-wireless"
55

66
PIMORONI_PICO_FLAVOUR="pimoroni"
7-
PIMORONI_PICO_VERSION="feature/picovector2-and-layers"
7+
PIMORONI_PICO_VERSION="v1.25.0"
88

99
PY_DECL_VERSION="v0.0.3"
1010
DIR2UF2_VERSION="v0.0.9"

ci/python.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# F = Pyflakes
2+
# Q = Quotes
3+
# E/W = pycodestyle (Whitespace, Line lengths etc)
4+
# B - flake8-bugbear = Unused loop variables, sloppy code
5+
# COM - flake8-commas
6+
# BLE - flake8-blind-except
7+
# C4 - flake8-comprehensions
8+
# ISC - flake8-implicit-str-concat = Implicit string concat, eg: `"hello" "world"` on one line
9+
# ICN - flake8-import-conventions = Import conventions
10+
# PIE - flake8-pie = Misc silliness, catches range with a 0 start argument
11+
# RET - flake8-return = Enforces straight-forward code around return statements
12+
# SLF - flake8-self
13+
# ARG - flake8-unused-arguments
14+
15+
QA_INCLUDE="F,Q,W,E,B,COM,BLE,C4,ISC,ICN,PIE,RSE,RET,SLF,ARG"
16+
QA_IGNORE="E501,E402,COM812"
17+
18+
function qa_prepare_all {
19+
pip install ruff
20+
}
21+
22+
function qa_examples_check {
23+
ruff check --select "$QA_INCLUDE" examples/ --ignore "$QA_IGNORE"
24+
}
25+
26+
function qa_examples_fix {
27+
ruff check --select "$QA_INCLUDE" examples/ --ignore "$QA_IGNORE" --fix
28+
}
29+
30+
function qa_modules_check {
31+
ruff check --select "$QA_INCLUDE" modules/ --ignore "$QA_IGNORE"
32+
}
33+
34+
function qa_modules_fix {
35+
ruff check --select "$QA_INCLUDE" modules/ --ignore "$QA_IGNORE" --fix
36+
}

docs/plasma.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Plasma <!-- omit in toc -->
2+
3+
The Plasma library is intended to drive APA102 / DotStar™ or WS2812 / NeoPixel™ LEDs on our [Plasma 2040](https://shop.pimoroni.com/products/plasma-2040), [Plasma 2350](https://shop.pimoroni.com/products/plasma-2350) and [Plasma 2350 W](https://shop.pimoroni.com/products/plasma-2350-w) boards, though it can also be used with your own custom pins/wiring.
4+
5+
It can also be used to drive WS2812 / NeoPixel™ LEDs from [Plasma Stick](https://shop.pimoroni.com/products/plasma-stick-2040-w). Note that APA102 compatibility, user buttons, RGB LED and current sensing functions are not present on Plasma Stick.
6+
7+
- [Notes On PIO Limitations](#notes-on-pio-limitations)
8+
- [WS2812](#ws2812)
9+
- [Getting Started](#getting-started)
10+
- [RGBW and Setting Colour Order](#rgbw-and-setting-colour-order)
11+
- [Set An LED](#set-an-led)
12+
- [RGB](#rgb)
13+
- [HSV](#hsv)
14+
- [APA102](#apa102)
15+
- [Getting Started](#getting-started-1)
16+
- [Set An LED](#set-an-led-1)
17+
- [RGB](#rgb-1)
18+
- [HSV](#hsv-1)
19+
- [Set Brightness](#set-brightness)
20+
- [Using the Buttons and RGB LED](#using-the-buttons-and-rgb-led)
21+
- [Buttons](#buttons)
22+
- [RGBLED](#rgbled)
23+
- [Measuring LED Strip Current Draw (Plasma 2040 only)](#measuring-led-strip-current-draw-plasma-2040-only)
24+
- [Analog](#analog)
25+
26+
## Notes On PIO Limitations
27+
28+
The WS2812 and APA102 drivers use the PIO hardware on the RP2040. There are only two PIOs with four state machines each, placing a hard limit on how many separate LED strips you can drive.
29+
30+
The default is `0` for PIO and `0` for PIO state-machine, but you should change these if you plan on running different strand types together, or if you're using something else that uses PIO.
31+
32+
## WS2812
33+
34+
### Getting Started
35+
36+
Construct a new `WS2812` instance. specifying the number of LEDs:
37+
38+
```python
39+
import plasma
40+
41+
LEDS = 30
42+
FPS = 60
43+
44+
led_strip = plasma.WS2812(LEDS)
45+
```
46+
47+
Start the LED strip by calling `start`. This sets up a timer which tells the RP2040 to DMA the pixel data into the PIO (a fast, asyncronous memory->peripheral copy) at the specified framerate.
48+
49+
```python
50+
led_strip.start(FPS)
51+
```
52+
53+
### RGBW and Setting Colour Order
54+
55+
Some WS2812-style LED strips have varying colour orders and support an additional white element. Two keyword arguments are supplied to configure this:
56+
57+
```python
58+
led_strip = plasma.WS2812(LEDS, rgbw=True, color_order=plasma.COLOR_ORDER_GRB)
59+
```
60+
61+
The available orders are defined as constants in `plasma`:
62+
63+
* `COLOR_ORDER_RGB`
64+
* `COLOR_ORDER_RBG`
65+
* `COLOR_ORDER_GRB`
66+
* `COLOR_ORDER_GBR`
67+
* `COLOR_ORDER_BRG`
68+
* `COLOR_ORDER_BGR`
69+
70+
### Set An LED
71+
72+
You can set the colour of an LED in either the RGB colourspace, or HSV (Hue, Saturation, Value). HSV is useful for creating rainbow patterns.
73+
74+
#### RGB
75+
76+
Set the first LED - `0` - to Purple `255, 0, 255`:
77+
78+
```python
79+
led_strip.set_rgb(0, 255, 0, 255)
80+
```
81+
82+
#### HSV
83+
84+
Set the first LED - `0` - to Red `0.0`:
85+
86+
```python
87+
led_strip.set_hsv(0, 0.0, 1.0, 1.0)
88+
```
89+
90+
## APA102
91+
92+
### Getting Started
93+
94+
Construct a new `APA102` instance, specifying the number of LEDs.
95+
96+
```python
97+
import plasma
98+
99+
LEDS = 30
100+
FPS = 60
101+
102+
led_strip = plasma.APA102(LEDS)
103+
```
104+
105+
Start the LED strip by calling `start`. This sets up a timer which tells the RP2040 to DMA the pixel data into the PIO (a fast, asyncronous memory->peripheral copy) at the specified framerate.
106+
107+
```python
108+
led_strip.start(FPS)
109+
```
110+
111+
### Set An LED
112+
113+
You can set the colour of an LED in either the RGB colourspace, or HSV (Hue, Saturation, Value). HSV is useful for creating rainbow patterns.
114+
115+
#### RGB
116+
117+
Set the first LED - `0` - to Purple `255, 0, 255`:
118+
119+
```python
120+
led_strip.set_rgb(0, 255, 0, 255)
121+
```
122+
123+
#### HSV
124+
125+
Set the first LED - `0` - to Red `0.0`:
126+
127+
```python
128+
led_strip.set_hsv(0, 0.0, 1.0, 1.0)
129+
```
130+
131+
### Set Brightness
132+
133+
APA102 pixels support global brightness, allowing their brightness to be specified independent of their colour. You can set the overall brightness of your strip by calling:
134+
135+
```python
136+
led_strip.set_brightness(15)
137+
```
138+
139+
You can set brightness from `0` to `31`. This directly maps to the 5-bit brightness value sent to the APA102 LEDs.
140+
141+
## Using the Buttons and RGB LED
142+
143+
The `pimoroni` module contains `Button` and `RGBLED` classes to simplify button debounce, auto-repeat and PWM'ing an RGB LED.
144+
145+
```python
146+
Button(button, invert=True, repeat_time=200, hold_time=1000)
147+
```
148+
149+
```python
150+
RGBLED(r, g, b, invert=True)
151+
```
152+
153+
If you're using one of the MicroPython builds from this repo, you can now specify the pin names directly. `help(machine.Pin.board)` will give you a convenient list of available pins and their names.
154+
155+
### Buttons
156+
157+
Import the `Button` class from the `pimoroni` module:
158+
159+
```python
160+
from pimoroni import Button
161+
```
162+
163+
Set up an instance of `Button` for each button.
164+
165+
```python
166+
button_a = Button("BUTTON_A")
167+
button_b = Button("BUTTON_B")
168+
user_sw = Button("USER_SW")
169+
```
170+
171+
To get the button state, call `.read()`. If the button is held down, then this will return `True` at the interval specified by `repeat_time` until `hold_time` is reached, at which point it will return `True` every `repeat_time / 3` milliseconds. This is useful for rapidly increasing/decreasing values such as hue:
172+
173+
```python
174+
state = button_a.read()
175+
```
176+
177+
### RGBLED
178+
179+
Import the `RGBLED` class from `pimoroni` :
180+
181+
```python
182+
from pimoroni import RGBLED
183+
```
184+
185+
And set up an instance of `RGBLED` for the LED:
186+
187+
```python
188+
led = RGBLED("LED_R", "LED_G", "LED_B")
189+
```
190+
191+
To set the LED colour, call `.set_rgb(r, g, b)`. Each value should be between 0 and 255:
192+
193+
```python
194+
led.set_rgb(255, 0, 0) # Full red
195+
led.set_rgb(0, 255, 0) # Full green
196+
led.set_rgb(0, 0, 255) # Full blue
197+
```
198+
199+
## Measuring LED Strip Current Draw (Plasma 2040 only)
200+
201+
Plasma 2040 features low-side current sensing, letting you measure how much current a strip of LEDs is drawing. This could be used just for monitoring, or as a way to reduce the maximum brightness of a strip to keep its current draw within the range of the USB port or power supply being used.
202+
203+
The `pimoroni` module contains an `Analog` class to simplify the reading of this current draw.
204+
205+
```python
206+
Analog(pin, amplifier_gain=1, resistor=0)
207+
```
208+
209+
### Analog
210+
211+
Import the `Analog` class from `pimoroni` and specify the pin and gain constants for the current sensing:
212+
213+
```python
214+
from pimoroni import Analog
215+
216+
ADC_GAIN = 50
217+
SHUNT_RESISTOR = 0.015
218+
```
219+
220+
And set up an instance of `Analog` for the current sensing:
221+
222+
```python
223+
sense = Analog("CURRENT_SENSE", ADC_GAIN, SHUNT_RESISTOR)
224+
```
225+
226+
To read the current draw, call `.read_current()`. The returned value will be in amps (A):
227+
228+
```python
229+
print("Current =", sense.read_current(), "A")
230+
```

0 commit comments

Comments
 (0)