kopia lustrzana https://github.com/pimoroni/pimoroni-pico
commit
4b3d39bf44
|
@ -79,6 +79,7 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te
|
|||
* Pico Display 2.0 - https://shop.pimoroni.com/products/pico-display-pack-2-0
|
||||
* Pico Enviro+ Pack - https://shop.pimoroni.com/products/pico-enviro-pack
|
||||
* Pico Inky Pack - https://shop.pimoroni.com/products/pico-inky-pack
|
||||
* Pico GFX Pack - https://shop.pimoroni.com/products/pico-gfx-pack
|
||||
|
||||
## SHIMs
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
- [Galactic Paint](#galactic-paint)
|
||||
- [Other Examples](#other-examples)
|
||||
- [Launch (Demo Reel)](#launch-demo-reel)
|
||||
- [Other Resources](#other-resources)
|
||||
|
||||
## About Galactic Unicorn
|
||||
|
||||
|
@ -129,3 +130,11 @@ Requires `WIFI_CONFIG.py` from the `common` directory. It also needs the `microp
|
|||
|
||||
If you want to get the demo reel that Galactic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W.
|
||||
|
||||
## Other Resources
|
||||
|
||||
Here are some cool Galactic Unicorn community projects and resources that you might find useful / inspirational! Note that code at the links below has not been tested by us and we're not able to offer support with it.
|
||||
|
||||
- :link: [Galactic Unicorn MQTT scroller (and 3D printed case)](https://github.com/ucl-casa-ce/Galactic-Unicorn-MQTT-Scroller)
|
||||
- :link: [Compiling custom pimoroni-pico MicroPython (with ulab)](https://medium.com/@iestynlloyd/galactic-unicorns-and-custom-pimoroni-pico-firmware-38dd7c5913b8)
|
||||
- :link: [Galactic Unicorn Graphical Workout](https://www.instructables.com/Galactic-Unicorn-Graphical-Workout/)
|
||||
- :link: [Cheerlights + Galactic Unicorn + MicroPython (beginner-friendly tutorial)](https://cheerlights.com/cheerlights-raspberry-pi-pico-w-micropython/)
|
|
@ -0,0 +1,88 @@
|
|||
# Pico GFX Pack MicroPython Examples <!-- omit in toc -->
|
||||
|
||||
- [About Pico GFX Pack](#about-pico-gfx-pack)
|
||||
- [Pico GFX Pack and PicoGraphics](#pico-gfx-pack-and-picographics)
|
||||
- [Basic Examples](#basic-examples)
|
||||
- [Balls Demo](#balls-demo)
|
||||
- [Button Test](#button-test)
|
||||
- [Rainbow](#rainbow)
|
||||
- [Snake](#snake)
|
||||
- [Advanced Examples](#advanced-examples)
|
||||
- [CO2](#co2)
|
||||
- [Thermometer](#thermometer)
|
||||
|
||||
## About Pico GFX Pack
|
||||
|
||||
GFX Pack adds a 128x64 LCD Matrix display to your headered Raspberry Pi Pico or PicoW, with RGBW backlight and 5 input buttons for all your display and control needs.
|
||||
|
||||
- :link: [Pico GFX Pack store page](https://shop.pimoroni.com/products/pico-gfx-pack)
|
||||
|
||||
You'll need to download the most recent version of our MicroPython firmware for your board from the link below.
|
||||
|
||||
- [MicroPython releases](https://github.com/pimoroni/pimoroni-pico/releases)
|
||||
- [Installing MicroPython](../../../setting-up-micropython.md)
|
||||
|
||||
## Pico GFX Pack and PicoGraphics
|
||||
|
||||
The easiest way to start displaying cool stuff on GFX Pack is using our GFX Pack helper module (which contains a bunch of useful shortcuts for interacting with the board) and our PicoGraphics display library which handles drawing things on the screen.
|
||||
|
||||
- [GFX Pack function reference](../../modules_py/gfx_pack.md)
|
||||
- [PicoGraphics function reference](../../modules/picographics/README.md)
|
||||
|
||||
## Basic Examples
|
||||
|
||||
### Balls Demo
|
||||
|
||||
[balls_demo.py](balls_demo.py)
|
||||
|
||||
LCD demo with a bunch of bouncy balls!
|
||||
|
||||
### Button Test
|
||||
|
||||
[button_test.py](button_test.py)
|
||||
|
||||
Shows how to read the buttons, display text and change the colour of the RGBW backlight.
|
||||
|
||||
### Rainbow
|
||||
|
||||
[rainbow.py](rainbow.py)
|
||||
|
||||
This example borrows a CircuitPython hsv to rgb function to cycle through some rainbows on GFX Pack's screen.
|
||||
|
||||
### Snake
|
||||
|
||||
[snake.py](snake.py)
|
||||
|
||||
Basic Snake demo for GFX Pack.
|
||||
|
||||
- A = up
|
||||
- B = down
|
||||
- C = reset
|
||||
- D = left
|
||||
- E = right
|
||||
|
||||
## Advanced Examples
|
||||
|
||||
These examples require additional hardware. We connected our breakouts using a JST-SH to JST-SH cable:
|
||||
|
||||
- :link: [Qw/ST cable store page](https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609813587)
|
||||
|
||||
### CO2
|
||||
|
||||
[co2.py](co2.py)
|
||||
|
||||
Add a SCD41 sensor breakout to your GFX Pack to make a handy CO2 detector!
|
||||
Press A to reset the high/low values.
|
||||
|
||||
- :link: [SCD41 breakout store page](https://shop.pimoroni.com/products/scd41-co2-sensor-breakout)
|
||||
|
||||
### Thermometer
|
||||
|
||||
[thermometer.py](thermometer.py)
|
||||
|
||||
This demo uses a BME680 or BME688 breakout to measure temperature, pressure, and humidity and display it on the GFX display.
|
||||
|
||||
To use the Pico's internal temperature sensor in place of the BME68x breakout, just change `use_bme68x_breakout` to `False`.
|
||||
|
||||
- :link: [BME680 breakout store page](https://shop.pimoroni.com/products/bme680-breakout)
|
||||
- :link: [BME688 breakout store page](https://shop.pimoroni.com/products/bme688-breakout)
|
|
@ -0,0 +1,60 @@
|
|||
# This example shows you a simple, non-interrupt way of reading GFX Pack's buttons with a loop that checks to see if buttons are pressed.
|
||||
|
||||
import time
|
||||
from gfx_pack import GfxPack, SWITCH_A, SWITCH_B, SWITCH_C, SWITCH_D, SWITCH_E
|
||||
|
||||
gp = GfxPack()
|
||||
display = gp.display
|
||||
|
||||
WIDTH, HEIGHT = display.get_bounds()
|
||||
display.set_backlight(0) # turn off the white component of the backlight
|
||||
|
||||
|
||||
# sets up a handy function we can call to clear the screen
|
||||
def clear():
|
||||
display.set_pen(0)
|
||||
display.clear()
|
||||
display.set_pen(15)
|
||||
|
||||
|
||||
# set up
|
||||
display.set_font("bitmap8")
|
||||
|
||||
while True:
|
||||
if gp.switch_pressed(SWITCH_A): # if a button press is detected... # clear to black
|
||||
gp.set_backlight(255, 0, 0, 0) # red, green, blue, white
|
||||
clear()
|
||||
display.text("Button A pressed", 0, 0, WIDTH, 2) # display some text on the screen
|
||||
display.update() # update the display
|
||||
time.sleep(1)
|
||||
elif gp.switch_pressed(SWITCH_B):
|
||||
gp.set_backlight(255, 125, 0, 0)
|
||||
clear()
|
||||
display.text("Button B pressed", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
time.sleep(1)
|
||||
elif gp.switch_pressed(SWITCH_C):
|
||||
gp.set_backlight(0, 255, 0, 0)
|
||||
clear()
|
||||
display.text("Button C pressed", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
time.sleep(1)
|
||||
elif gp.switch_pressed(SWITCH_D):
|
||||
gp.set_backlight(0, 0, 255, 0)
|
||||
clear()
|
||||
display.text("Button D pressed", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
time.sleep(1)
|
||||
elif gp.switch_pressed(SWITCH_E):
|
||||
gp.set_backlight(255, 0, 255, 0)
|
||||
clear()
|
||||
display.text("Button E pressed", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
time.sleep(1)
|
||||
else:
|
||||
gp.set_backlight(0, 0, 0, 125)
|
||||
clear()
|
||||
display.set_pen(15)
|
||||
display.text("Press any button!", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
time.sleep(0.01) # this number is how frequently the Pico checks for button presses
|
|
@ -0,0 +1,124 @@
|
|||
# Add a SCD41 sensor breakout to your GFX Pack to make a handy CO2 detector!
|
||||
# https://shop.pimoroni.com/products/scd41-co2-sensor-breakout
|
||||
# Press A to reset the high/low values.
|
||||
|
||||
from gfx_pack import GfxPack, SWITCH_A
|
||||
import breakout_scd41
|
||||
|
||||
gp = GfxPack()
|
||||
display = gp.display
|
||||
|
||||
WIDTH, HEIGHT = display.get_bounds()
|
||||
display.set_backlight(0) # turn off the white component of the backlight
|
||||
|
||||
# the range of readings to map to colours (and scale our graph to)
|
||||
# https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms
|
||||
MIN = 400
|
||||
MAX = 2000
|
||||
|
||||
# pick what bits of the colour wheel to use (from 0-360°)
|
||||
# https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/
|
||||
HUE_START = 100 # green
|
||||
HUE_END = 0 # red
|
||||
|
||||
BRIGHTNESS = 0.5
|
||||
|
||||
# the area of the screen we want to draw our graph into
|
||||
GRAPH_TOP = 24
|
||||
GRAPH_BOTTOM = 54
|
||||
|
||||
|
||||
# sets up a handy function we can call to clear the screen
|
||||
def clear():
|
||||
display.set_pen(0)
|
||||
display.clear()
|
||||
display.set_pen(15)
|
||||
|
||||
|
||||
# From CPython Lib/colorsys.py
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h * 6.0)
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
t = v * (1.0 - s * (1.0 - f))
|
||||
i = i % 6
|
||||
if i == 0:
|
||||
return v, t, p
|
||||
if i == 1:
|
||||
return q, v, p
|
||||
if i == 2:
|
||||
return p, v, t
|
||||
if i == 3:
|
||||
return p, q, v
|
||||
if i == 4:
|
||||
return t, p, v
|
||||
if i == 5:
|
||||
return v, p, q
|
||||
|
||||
|
||||
highest = 0.0
|
||||
lowest = 4000.0
|
||||
readings = []
|
||||
|
||||
# set up
|
||||
breakout_scd41.init(gp.i2c)
|
||||
breakout_scd41.start()
|
||||
|
||||
gp.set_backlight(0, 0, 0, 127)
|
||||
display.set_font("bitmap8")
|
||||
display.set_pen(15)
|
||||
display.text("Waiting for sensor to be ready", 0, 0, WIDTH, 2)
|
||||
display.update()
|
||||
|
||||
while True:
|
||||
if gp.switch_pressed(SWITCH_A):
|
||||
# reset recorded high / low values
|
||||
highest = 0.0
|
||||
lowest = 4000.0
|
||||
|
||||
if breakout_scd41.ready():
|
||||
# read the sensor
|
||||
co2, temperature, humidity = breakout_scd41.measure()
|
||||
|
||||
# update highest / lowest values
|
||||
if co2 < lowest:
|
||||
lowest = co2
|
||||
if co2 > highest:
|
||||
highest = co2
|
||||
|
||||
# calculates a colour from the sensor reading
|
||||
hue = max(0, HUE_START + ((co2 - MIN) * (HUE_END - HUE_START) / (MAX - MIN)))
|
||||
|
||||
# set the leds
|
||||
r, g, b = [int(255 * c) for c in hsv_to_rgb(hue / 360, 1.0, BRIGHTNESS)]
|
||||
gp.set_backlight(r, g, b, 0)
|
||||
|
||||
# keep track of readings in a list (so we can draw the graph)
|
||||
readings.append(co2)
|
||||
# we only need to save a screen's worth of readings, so delete the oldest
|
||||
if len(readings) > WIDTH:
|
||||
readings.pop(0)
|
||||
|
||||
# draw the graph
|
||||
clear()
|
||||
for r in range(len(readings)):
|
||||
# this line scales the y axis of the graph into the available space
|
||||
y = round(GRAPH_BOTTOM + ((readings[r] - MIN) * (GRAPH_TOP - GRAPH_BOTTOM) / (MAX - MIN)))
|
||||
display.pixel(r, y)
|
||||
|
||||
# draw the text
|
||||
display.text("CO2", 0, 0, scale=2)
|
||||
display.text(f"Temp {temperature:.0f}°c", 0, 16, scale=1)
|
||||
display.text(f"Low {lowest:.0f}ppm", 0, HEIGHT - 8, scale=1)
|
||||
# measure the rest of the text before drawing so that we can right align it
|
||||
text_width = display.measure_text(f"{co2:.0f}ppm", scale=2)
|
||||
display.text(f"{co2:.0f}ppm", WIDTH - text_width, 0, scale=2)
|
||||
text_width = display.measure_text(f"Humidity {humidity:.0f}%", scale=1)
|
||||
display.text(f"Humidity {humidity:.0f}%", WIDTH - text_width, 16, scale=1)
|
||||
text_width = display.measure_text(f"High {highest:.0f}ppm", scale=1)
|
||||
display.text(f"High {highest:.0f}ppm", WIDTH - text_width, HEIGHT - 8, scale=1)
|
||||
|
||||
display.update()
|
|
@ -36,7 +36,7 @@ POS_KD = 0.0022 # Position derivative (D) gain
|
|||
|
||||
|
||||
# Create a new Inventor2040W and get a motor and encoder from it
|
||||
board = Inventor2040W(motor_rear_ratio=GEAR_RATIO)
|
||||
board = Inventor2040W(motor_gear_ratio=GEAR_RATIO)
|
||||
m = board.motors[MOTOR_A]
|
||||
enc = board.encoders[MOTOR_A]
|
||||
|
||||
|
|
|
@ -51,9 +51,9 @@ Plasma Stick uses GP4 and GP5 for its I2C interface. You can use the constants i
|
|||
|
||||
```python
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from pimoroni import PINS_BREAKOUT_GARDEN
|
||||
from pimoroni import BREAKOUT_GARDEN_I2C_PINS
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
|
||||
```
|
||||
|
||||
Alternatively, you can specify the pin numbers directly:
|
||||
|
|
|
@ -301,9 +301,9 @@ Galactic Unicorn uses GP4 and GP5 for its I2C interface. You can use the constan
|
|||
|
||||
```python
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from pimoroni import PINS_BREAKOUT_GARDEN
|
||||
from pimoroni import BREAKOUT_GARDEN_I2C_PINS
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
|
||||
```
|
||||
|
||||
Alternatively, you can specify the pin numbers directly:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
- [If you have a board without a reset button:](#if-you-have-a-board-without-a-reset-button)
|
||||
- [Copying the firmware to your board](#copying-the-firmware-to-your-board)
|
||||
- [Where are the examples?](#where-are-the-examples)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
|
||||
We provide pre-built MicroPython images which include all the drivers that include all the libraries and drivers you'll need to use our [supported products](https://github.com/pimoroni/pimoroni-pico#supported-products) To install MicroPython, you'll need to **copy the appropriate .uf2 file from the releases page to your device while it's in DFU/bootloader mode.**
|
||||
|
||||
|
@ -60,3 +61,9 @@ You can also transfer files to boards running MicroPython using command line too
|
|||
Note that most of our MicroPython images don't include examples, so you'll need to copy across the ones you want using Thonny. You can find all our MicroPython examples at the link below.
|
||||
|
||||
- [MicroPython examples](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Having trouble getting started? Check out the link below:
|
||||
|
||||
- [MicroPython FAQs](faqs-micropython.md)
|
||||
|
|
Ładowanie…
Reference in New Issue