Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmic: tidy examples and docs #696

Merged
merged 12 commits into from
Feb 27, 2023
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te
* Inky Frame 5.7" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-5-7
* Automation 2040 W Mini (inputs, outputs and a relay, 6-40V compatible) - https://shop.pimoroni.com/products/automation-2040-w-mini
* Plasma Stick 2040 W (bijou LED strip controller) - https://shop.pimoroni.com/products/plasma-stick-2040-w
* Galactic Unicorn (dazzling 53 x 11 LED matrix) - https://shop.pimoroni.com/products/galactic-unicorn
* Galactic Unicorn (53 x 11 LED matrix) - https://shop.pimoroni.com/products/galactic-unicorn
* Interstate 75 W (HUB75 matrix driver) - https://shop.pimoroni.com/products/interstate-75-w
* Inky Frame 4.0" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-4
* Badger 2040 W (E Ink badge) - https://shop.pimoroni.com/products/badger-2040-w
* Cosmic Unicorn (32 x 32 LED matrix) - https://shop.pimoroni.com/products/cosmic-unicorn

## Breakouts

Expand Down
64 changes: 32 additions & 32 deletions libraries/cosmic_unicorn/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Galactic Unicorn (C/C++)<!-- omit in toc -->
# Cosmic Unicorn (C/C++)<!-- omit in toc -->

Galactic Unicorn offers 53x11 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!
Cosmic Unicorn offers 32x32 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!

You can buy one here: https://shop.pimoroni.com/products/galactic-unicorn
You can buy one here: https://shop.pimoroni.com/products/cosmic-unicorn

## These are not your everyday RGB LEDs!

Internally Galactic Unicorn applies gamma correction to the supplied image data and updates the display with 14-bit precision resulting in extremely linear visual output - including at the low end.
Internally Cosmic Unicorn applies gamma correction to the supplied image data and updates the display with 14-bit precision resulting in extremely linear visual output - including at the low end.

The display is refreshed around 300 times per second (300fps!) allowing for rock solid stability even when being filmed, no smearing or flickering even when in motion.

No strobing or brightness stepping here folks - it's the perfect backdrop for your tricked out streaming setup!

## Getting started

The Galactic Unicorn library provides a collection of methods that allow you to easily access all of the features on the board.
The Cosmic Unicorn library provides a collection of methods that allow you to easily access all of the features on the board.

Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_graphics) library which provides a comprehensive selection of drawing methods - once your drawing work is complete you pass the PicoGraphics object to Galactic Unicorn to have it displayed on the screen.
Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_graphics) library which provides a comprehensive selection of drawing methods - once your drawing work is complete you pass the PicoGraphics object to Cosmic Unicorn to have it displayed on the screen.

- [Example Program](#example-program)
- [Interleaved Framebuffer](#interleaved-framebuffer)
Expand All @@ -41,7 +41,7 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/
- [`void play_synth()`](#void-play_synth)
- [`void stop_playing()`](#void-stop_playing)
- [Constants](#constants)
- [`WIDTH` & `HEIGHT`](#width--height)
- [`WIDTH` \& `HEIGHT`](#width--height)

# Example Program

Expand All @@ -52,15 +52,15 @@ The following example shows how to scroll a simple message across the display.
#include <stdlib.h>

#include "libraries/pico_graphics/pico_graphics.hpp"
#include "galactic_unicorn.hpp"
#include "cosmic_unicorn.hpp"

using namespace pimoroni;

// create a PicoGraphics framebuffer to draw into
PicoGraphics_PenRGB888 graphics(GalacticUnicorn::WIDTH, GalacticUnicorn::HEIGHT, nullptr);
PicoGraphics_PenRGB888 graphics(CosmicUnicorn::WIDTH, CosmicUnicorn::HEIGHT, nullptr);

// create our GalacticUnicorn object
GalacticUnicorn galactic_unicorn;
// create our CosmicUnicorn object
CosmicUnicorn cosmic_unicorn;

// message to scroll
std::string message = "Pirate. Monkey. Robot. Ninja.";
Expand All @@ -69,18 +69,18 @@ int main() {

stdio_init_all();

// initialise the GalacticUnicorn object
galactic_unicorn.init();
// initialise the CosmicUnicorn object
cosmic_unicorn.init();

// start position for scrolling (off the side of the display)
float scroll = -(float)GalacticUnicorn::WIDTH;
float scroll = -(float)CosmicUnicorn::WIDTH;

while(true) {
// determine the scroll position of the text
int width = graphics.measure_text(message, 1);
scroll += 0.25f;
if(scroll > width) {
scroll = -(float)GalacticUnicorn::WIDTH;
scroll = -(float)CosmicUnicorn::WIDTH;
}

// clear the graphics object
Expand All @@ -92,7 +92,7 @@ int main() {
graphics.text(message, Point(0 - scroll, 5), -1, 0.55);

// update the display
galactic_unicorn.update(&graphics);
cosmic_unicorn.update(&graphics);

sleep_ms(10);
}
Expand All @@ -103,7 +103,7 @@ int main() {

# Interleaved Framebuffer

Galactic Unicorn takes advantage of the RP2040's PIOs to drive screen updates - this is what gives it the performance it needs to render with 14-bit precision at over 300 frames per second.
Cosmic Unicorn takes advantage of the RP2040's PIOs to drive screen updates - this is what gives it the performance it needs to render with 14-bit precision at over 300 frames per second.

The PIO is a powerful, but limited, tool. It has no way to access memory at random and minimal support for decision making and branching. All it can really do is process a stream of data/instructions in order.

Expand All @@ -129,7 +129,7 @@ If you're working with our library then you don't need to worry about any of the

### `void init()`

Initialise the Galactic Unicorn hardware, interleaved framebuffer, and PIO programs. This function must be called before attempting to do anything else with Galactic Unicorn.
Initialise the Cosmic Unicorn hardware, interleaved framebuffer, and PIO programs. This function must be called before attempting to do anything else with Cosmic Unicorn.

### `void set_brightness(float value)`

Expand All @@ -146,10 +146,10 @@ Adjust the brightness of the display - `delta` is supplied as a floating point v
For example:

```c++
galactic.set_brightness(0.5f);
galactic.adjust_brightness(0.1f); // brightness is now 0.6
galactic.adjust_brightness(0.7f); // brightness is now 1.0
galactic.adjust_brightness(-0.2f); // brightness is now 0.8
cosmic.set_brightness(0.5f);
cosmic.adjust_brightness(0.1f); // brightness is now 0.6
cosmic.adjust_brightness(0.7f); // brightness is now 1.0
cosmic.adjust_brightness(-0.2f); // brightness is now 0.8
```

### `void set_volume(float value)`
Expand All @@ -167,10 +167,10 @@ Adjust the volume - `delta` is supplied as a floating point value and will be ad
For example:

```c++
galactic.set_volume(0.5f);
galactic.adjust_volume(0.1f); // volume is now 0.6
galactic.adjust_volume(0.7f); // volume is now 1.0
galactic.adjust_volume(-0.2f); // volume is now 0.8
cosmic.set_volume(0.5f);
cosmic.adjust_volume(0.1f); // volume is now 0.6
cosmic.adjust_volume(0.7f); // volume is now 1.0
cosmic.adjust_volume(-0.2f); // volume is now 0.8
```

### `uint16_t light()`
Expand All @@ -181,7 +181,7 @@ Get the current value seen by the onboard light sensor as a value between `0` an

Returns true if the requested `button` is currently pressed.

There are a set of constants on the GalacticUnicorn class that represent each of the buttons. The brightness, sleep, and volume buttons are not tied to hardware functions (they are implemented entirely in software) so can also be used for user functions if preferred.
There are a set of constants on the CosmicUnicorn class that represent each of the buttons. The brightness, sleep, and volume buttons are not tied to hardware functions (they are implemented entirely in software) so can also be used for user functions if preferred.

```c++
static const uint8_t SWITCH_A = 0;
Expand All @@ -198,7 +198,7 @@ static const uint8_t SWITCH_BRIGHTNESS_DOWN = 26;
For example:

```c++
while(!galactic.is_pressed(GalacticUnicorn::SWITCH_A)) {
while(!cosmic.is_pressed(CosmicUnicorn::SWITCH_A)) {
// wait for switch A to be pressed
}
printf("We did it! We pressed switch A! Heck yeah!");
Expand All @@ -208,15 +208,15 @@ printf("We did it! We pressed switch A! Heck yeah!");

### `void update(PicoGraphics *graphics)`

**This is our recommended way to update the image on Galactic Unicorn.** The PicoGraphics library provides a collection of powerful drawing methods to make things simple.
**This is our recommended way to update the image on Cosmic Unicorn.** The PicoGraphics library provides a collection of powerful drawing methods to make things simple.

The image on the PicoGraphics object provided is copied to the interleaved framebuffer with gamma correction applied. This lets you have multiple PicoGraphics objects on the go at once and switch between them by changing which gets passed into this function.

If however you'd rather twiddle individual pixels (for example you're producing some sort of algorithmic output) then you can simply use the `clear()` and `set_pixel()` methods mentioned below.

### `void clear()`

Clear the contents of the interleaved framebuffer. This will make your Galactic Unicorn display turn off when the next frame is displayed.
Clear the contents of the interleaved framebuffer. This will make your Cosmic Unicorn display turn off when the next frame is displayed.

If you're using PicoGraphics to build your image (recommended!) then you won't need to call this method as you'll overwrite the entire display when you call `update()` anyway.

Expand Down Expand Up @@ -250,10 +250,10 @@ Stops any currently playing audio.

### `WIDTH` & `HEIGHT`

The width and height of Galactic Unicorn are available in constants `WIDTH` and `HEIGHT`.
The width and height of Cosmic Unicorn are available in constants `WIDTH` and `HEIGHT`.

For example:

```c++
int num_pixels = GalacticUnicorn::WIDTH * GalacticUnicorn::HEIGHT;
int num_pixels = CosmicUnicorn::WIDTH * CosmicUnicorn::HEIGHT;
```
89 changes: 58 additions & 31 deletions micropython/examples/cosmic_unicorn/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Galactic Unicorn MicroPython Examples <!-- omit in toc -->
# Cosmic Unicorn MicroPython Examples <!-- omit in toc -->

- [About Galactic Unicorn](#about-galactic-unicorn)
- [Galactic Unicorn and PicoGraphics](#galactic-unicorn-and-picographics)
- [About Cosmic Unicorn](#about-cosmic-unicorn)
- [Cosmic Unicorn and PicoGraphics](#cosmic-unicorn-and-picographics)
- [Examples](#examples)
- [Clock](#clock)
- [Eighties Super Computer](#eighties-super-computer)
Expand All @@ -12,29 +12,33 @@
- [Nostalgia Prompt](#nostalgia-prompt)
- [Rainbow](#rainbow)
- [Scrolling Text](#scrolling-text)
- [Today](#today)
- [Wireless Examples](#wireless-examples)
- [Cheerlights History](#cheerlights-history)
- [Galactic Paint](#galactic-paint)
- [Cosmic Paint](#cosmic-paint)
- [Exchange Ticker](#exchange-ticker)
- [HTTP Text](#http-text)
- [Weather](#weather)
- [NumPy examples](#numpy-examples)
- [Other Examples](#other-examples)
- [Launch (Demo Reel)](#launch-demo-reel)
- [Other Resources](#other-resources)

## About Galactic Unicorn
## About Cosmic Unicorn

Galactic Unicorn offers 53x11 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!
Cosmic Unicorn offers 32x32 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!

- :link: [Galactic Unicorn store page](https://shop.pimoroni.com/products/galactic-unicorn)
- :link: [Cosmic Unicorn store page](https://shop.pimoroni.com/products/cosmic-unicorn)

Galactic Unicorn ships with MicroPython firmware pre-loaded, but you can download the most recent version at the link below (you'll want the `galactic-unicorn` image).
Cosmic Unicorn ships with MicroPython firmware pre-loaded, but you can download the most recent version at the link below (you'll want the `cosmic-unicorn` image).

- [MicroPython releases](https://github.com/pimoroni/pimoroni-pico/releases)
- [Installing MicroPython](../../../setting-up-micropython.md)

## Galactic Unicorn and PicoGraphics
## Cosmic Unicorn and PicoGraphics

The easiest way to start displaying cool stuff on Galactic Unicorn is using our Galactic Unicorn module (which contains a bunch of helpful functions for interacting with the buttons, adjusting brightness and suchlike) and our PicoGraphics library, which is chock full of useful functions for drawing on the LED matrix.
The easiest way to start displaying cool stuff on Cosmic Unicorn is using our Cosmic Unicorn module (which contains a bunch of helpful functions for interacting with the buttons, adjusting brightness and suchlike) and our PicoGraphics library, which is chock full of useful functions for drawing on the LED matrix.

- [Galactic Unicorn function reference](../../modules/galactic_unicorn/README.md)
- [Cosmic Unicorn function reference](../../modules/cosmic_unicorn/README.md)
- [PicoGraphics function reference](../../modules/picographics/README.md)

## Examples
Expand Down Expand Up @@ -98,45 +102,68 @@ Some good old fashioned rainbows! You can adjust the cycling speed with A and B,

Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -.

### Today

[today.py](today.py)

Calendar example with (optional) NTP synchronization. You can adjust the brightness with LUX + and -, and resync the date by pressing C.

## Wireless Examples

These examples need `WIFI_CONFIG.py` (from the `common` directory) to be saved to your Pico W. Open up `WIFI_CONFIG.py` in Thonny to add your wifi details (and save it when you're done).
These examples need `WIFI_CONFIG.py` and `network_manager.py` (from the `common` directory) to be saved to your Pico W. Open up `WIFI_CONFIG.py` in Thonny to add your wifi details (and save it when you're done).

- [micropython/examples/common](../../examples/common)

### Cheerlights History

[cheerlights_history.py](cheerlights_history.py)

Updates one pixel every five minutes to display the most recent #Cheerlights colour. Discover the most popular colours over time, or use it as an avant garde (but colourful) 53 hour clock! Find out more about the Cheerlights API at https://cheerlights.com/
Updates one pixel every two minutes to display the most recent #Cheerlights colour. Discover the most popular colours over time, or use it as an avant garde (but colourful) 32 hour clock! Find out more about the Cheerlights API at https://cheerlights.com/

You can adjust the brightness with LUX + and -.

### Cosmic Paint

[cosmic_paint](cosmic_paint)

Draw on your Cosmic Unicorn from another device in real time, over wifi!

This example needs the `micropython-phew` and `microdot` libraries (you can install these using Thonny's 'Tools > Manage Packages').

### Exchange Ticker

[exchange_ticker.py](exchange_ticker.py)

Requires `WIFI_CONFIG.py` and `network_manager.py` from the `common` directory.
This example uses the Coinbase open API to collect the current exchange rates of various cryptocurrencies.

Press A to change to a different base exchange currency.

### HTTP Text

[http_text](http_text)

Display scrolling wisdom, quotes or greetz... from another computer or device!

You can adjust the brightness with LUX + and -.

### Galactic Paint
Requires `logging.mpy` and `tinyweb` from [micropython/examples/common](../../examples/common) - copy these into the `lib` folder on your Pico W. You'll also need `index.html` to be saved alongside `html_text.py`.

[galactic_paint](galactic_paint)
### Weather

Draw on your Galactic Unicorn from another device in real time, over wifi!
[weather](weather)

Requires `WIFI_CONFIG.py` from the `common` directory. It also needs the `micropython-phew` and `microdot` libraries (you can install these using Thonny's 'Tools > Manage Packages').
Display current weather data from the [Open-Meteo](https://open-meteo.com/) weather API.

## Other Examples
## NumPy examples

### Launch (Demo Reel)
[numpy](numpy)

[launch](launch)
The examples in the folder use `numpy`-like array functions contained in the `ulab` library for super fast graphical effects.

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 Examples

## Other Resources
### Launch (Demo Reel)

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.
[launch](launch)

- :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: [Galactic Unicorn Bounce - Simple GFX Demo](https://www.instructables.com/Galactic-Unicorn-Bounce-Simple-GFX-Demo/)
- :link: [Cheerlights + Galactic Unicorn + MicroPython (beginner-friendly tutorial)](https://cheerlights.com/cheerlights-raspberry-pi-pico-w-micropython/)
- :link: [CheerClock (plus laser-cut templates for a fancy case/diffuser)](https://github.com/seanosteen/CheerClock)
If you want to get the demo reel that Cosmic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W.
22 changes: 11 additions & 11 deletions micropython/examples/cosmic_unicorn/cheerlights_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Cosmic Unicorn example updates a pixel every five(ish) minutes
# This Cosmic Unicorn example updates a pixel every two(ish) minutes
# to display the most recent #cheerlights colour. Discover the most popular
# colours over time, or use it as an avant garde (but colourful) 53 hour clock!
# colours over time, or use it as an avant garde (but colourful) 32 hour clock!
# Find out more about the Cheerlights API at https://cheerlights.com/
#
# To run this example you'll need WIFI_CONFIG.py and network_manager.py from
Expand Down Expand Up @@ -77,17 +77,17 @@ def update_leds():
graphics.set_pen(current_colour)
graphics.pixel(x, y)
i = i + 1
gu.update(graphics)
cu.update(graphics)
print("LEDs updated!")


gu = CosmicUnicorn()
cu = CosmicUnicorn()
graphics = PicoGraphics(DISPLAY)

width = CosmicUnicorn.WIDTH
height = CosmicUnicorn.HEIGHT

gu.set_brightness(0.5)
cu.set_brightness(0.5)

# set up the Pico W's onboard LED
pico_led = Pin('LED', Pin.OUT)
Expand All @@ -114,15 +114,15 @@ def update_leds():
while True:
# adjust brightness with LUX + and -
# LEDs take a couple of secs to update, so adjust in big (10%) steps
if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
gu.adjust_brightness(+0.1)
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP):
cu.adjust_brightness(+0.1)
update_leds()
print(f"Brightness set to {gu.get_brightness()}")
print(f"Brightness set to {cu.get_brightness()}")

if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
gu.adjust_brightness(-0.1)
if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN):
cu.adjust_brightness(-0.1)
update_leds()
print(f"Brightness set to {gu.get_brightness()}")
print(f"Brightness set to {cu.get_brightness()}")

# pause for a moment (important or the USB serial device will fail)
time.sleep(0.001)
Loading