Pimoroni Galactic Unicorn Hello World: Difference between revisions
(30 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
583 RGB leds in 53x11 grid. Raspberry Pi Pico W (microcontroller), speaker with amplifier, two (2) I2C Stemma/qt sensor sockets (3 or 4 pin JST PH), a light sensor (phototransistor) facing front and nine (9) control buttons, a reset button, JST-PH battery connector. | 583 RGB leds in 53x11 grid. Raspberry Pi Pico W (microcontroller), speaker with amplifier, two (2) I2C Stemma/qt sensor sockets (3 or 4 pin JST PH), a light sensor (phototransistor) facing front and nine (9) control buttons, a reset button, JST-PH battery connector. | ||
== Connecting == | == Connecting to other sensors == | ||
2 x QW/ST Connections (4 pin 1.00 mm pitch Stemma QT / Qwiic). Stemma QT works on both, 5V and 3.3V logic, but Pico W is a 3.3 V system and Arduino Uno 5V. | |||
* Stemma is Adafruit's [three or four pin JST PH with 2.00 mm pitch. The three pin for analog IO devices and four pin is for I2C.] Stemma QT is a smaller version of the four pin Stemma format, with a 1.0 mm pitch, and is only for I2C. | * Stemma is Adafruit's [three or four pin JST PH with 2.00 mm pitch. The three pin for analog IO devices and four pin is for I2C.] Stemma QT is a smaller version of the four pin Stemma format, with a 1.0 mm pitch, and is only for I2C. | ||
* Qwiic is Sparkfun's connector type | * Qwiic is Sparkfun's connector type | ||
The buttons and the QW/ST connectors are the only means to interface with Galactic Unicorn, and Wifi of course. It is possible to get StemmaQT to male jumper wire adapters for use with I2C devices or for basic GPIO access. | The buttons and the QW/ST connectors are the only means to interface with Galactic Unicorn, and Wifi of course. It is possible to get StemmaQT to male jumper wire adapters for use with I2C devices or for basic GPIO access. | ||
Stemma QT | |||
* Black for GND | |||
* Red for V+ | |||
* Blue for SDA | |||
* Yellow for SCL | |||
Galactic Unicorn uses GP4 and GP5 for its I2C interface. You can use the constants in the shared pimoroni module to set up the I2C interface. https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/galactic_unicorn/README.md#using-breakouts | |||
Master, Slave | |||
More information | More information | ||
* https://github.com/nickgammon/I2C_Anything | * https://github.com/nickgammon/I2C_Anything | ||
* https://arduino.stackexchange.com/questions/16292/sending-and-receiving-different-types-of-data-via-i2c-in-arduino | * https://arduino.stackexchange.com/questions/16292/sending-and-receiving-different-types-of-data-via-i2c-in-arduino | ||
=== Connect to Arduino UNO === | |||
Pico W is a 3.3 V system and Uno 5V system, so a logic level shifter (converter) should be used. | |||
Pull-up resistors: I2C Bus Pullup Resistor Calculation (Texas Instruments, Feb 2015). | |||
<syntaxhighlight lang="python"> | |||
from amchine import Pin, I2C | |||
from time import sleep | |||
MSG_SIZE=15 | |||
i2c = I2C(0, scl=PIN(17), sda=PIN(16), freq=100000) | |||
addr = i2c.scan()[] | |||
i2c.writeto(addr, 'Hi from Pi') | |||
sleep(0.1) | |||
a = i2c.readfrom(addr, MSG_SIZE) | |||
print(a) | |||
</syntaxhighlight> | |||
The Arduino Code is in Girhub: https://github.com/tinkertechtrove/pico-pi-playing/blob/main/arduino-i2c/sketch_i2c_sub/sketch_i2c_sub.ino | |||
More information: | |||
* https://www.youtube.com/watch?v=Wkk1aNWj6sQ | |||
* https://www.youtube.com/watch?v=Wh-SjhngILU | |||
== Programming == | == Programming == | ||
Line 24: | Line 62: | ||
* Thonny is the da facto | * Thonny is the da facto | ||
* [https://dev.to/blues/your-first-steps-with-raspberry-pi-pico-and-visual-studio-code-4jbd VS Studio]: MicroPico (the id is paulober.pico-w-go). If not found use this https://github.com/microsoft/vscode/issues/108147 because some Linux distros use OpenVSX. | * [https://dev.to/blues/your-first-steps-with-raspberry-pi-pico-and-visual-studio-code-4jbd VS Studio]: MicroPico (the id is paulober.pico-w-go). If not found use this https://github.com/microsoft/vscode/issues/108147 because some Linux distros use OpenVSX. | ||
Picographics, see https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/picographics/README.md There is functions for eg | |||
* drawing a line, circle, rectangle, triangle, polygon | |||
* limited sprite support | |||
* display jpeg files | |||
=== Thonny === | === Thonny === | ||
# Connect the USB cable while '''bootsel''' button is pressed: RPI-RP2 is found on device manager. | # Connect the USB cable while '''bootsel''' button is pressed: RPI-RP2 is found on device manager. If not working, check other cable. | ||
# Copy the ''pimoroni-galactic_unicorn-v1.20.6-micropython.uf2'' to RPI-RP2. | # Copy the ''pimoroni-galactic_unicorn-v1.20.6-micropython.uf2'' to RPI-RP2. | ||
# Start thonny; see the right down corner that correct device is connected. | # Start thonny; see the right down corner that correct device is connected. If not, choose it from the list (right down corner). | ||
# Program. | # Program. | ||
# Run/ Stop / Load. | # Run/ Stop / Load. | ||
Line 52: | Line 96: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Fonts == | == Text and Fonts == | ||
Stationary, centred, scrolling text. | Stationary, centred, scrolling text. | ||
Line 66: | Line 110: | ||
* Bouncing ball: https://www.instructables.com/Galactic-Unicorn-Bounce-Simple-GFX-Demo/ | * Bouncing ball: https://www.instructables.com/Galactic-Unicorn-Bounce-Simple-GFX-Demo/ | ||
* | * | ||
== Physically modeled fire == | |||
Pressing B gives some flames, but this is not what I am looking for. It is located at GitHub https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/galactic_unicorn/fire_effect.py | |||
See https://www.youtube.com/watch?v=bRXrL-8CTmg for a simple idea of a flame. | |||
* Draw vertical sine wave and animate that | |||
* Draw a circle to the point where the flame originates. I'll use Bresenhams algorithm; see https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/ However, there is no need to draw actual circle. | |||
* The circle should be expanded according to the sine function to look like a flame. Two easy option: | |||
*# Use linear function; eg <pre>x in range(nmax+y/2-5)</pre> where y is the height (in pixels, inverted) | |||
*# Use some probapilistic method; eg starting width and shorten it by one or 2. | |||
* Use smaller and larger circles with different colors. Colors | |||
** Yellow (Orange) smallest | |||
** Red mid-one | |||
** Yellow largest | |||
* Add more flames and make it asynchronous: make a flame object or sprite. Sprite would be easy, just create the animation in 128x128 pixel spritesheet. Thus, I'll try using objects. | |||
More detailed: http://graphics.ucsd.edu/~henrik/papers/fire/fire.pdf | |||
* | |||
Add flashing: https://www.youtube.com/watch?v=T7LOWIrUKwY |
Latest revision as of 10:58, 7 December 2023
Introduction
583 RGB leds in 53x11 grid. Raspberry Pi Pico W (microcontroller), speaker with amplifier, two (2) I2C Stemma/qt sensor sockets (3 or 4 pin JST PH), a light sensor (phototransistor) facing front and nine (9) control buttons, a reset button, JST-PH battery connector.
Connecting to other sensors
2 x QW/ST Connections (4 pin 1.00 mm pitch Stemma QT / Qwiic). Stemma QT works on both, 5V and 3.3V logic, but Pico W is a 3.3 V system and Arduino Uno 5V.
- Stemma is Adafruit's [three or four pin JST PH with 2.00 mm pitch. The three pin for analog IO devices and four pin is for I2C.] Stemma QT is a smaller version of the four pin Stemma format, with a 1.0 mm pitch, and is only for I2C.
- Qwiic is Sparkfun's connector type
The buttons and the QW/ST connectors are the only means to interface with Galactic Unicorn, and Wifi of course. It is possible to get StemmaQT to male jumper wire adapters for use with I2C devices or for basic GPIO access.
Stemma QT
- Black for GND
- Red for V+
- Blue for SDA
- Yellow for SCL
Galactic Unicorn uses GP4 and GP5 for its I2C interface. You can use the constants in the shared pimoroni module to set up the I2C interface. https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/galactic_unicorn/README.md#using-breakouts
Master, Slave
More information
- https://github.com/nickgammon/I2C_Anything
- https://arduino.stackexchange.com/questions/16292/sending-and-receiving-different-types-of-data-via-i2c-in-arduino
Connect to Arduino UNO
Pico W is a 3.3 V system and Uno 5V system, so a logic level shifter (converter) should be used.
Pull-up resistors: I2C Bus Pullup Resistor Calculation (Texas Instruments, Feb 2015).
from amchine import Pin, I2C
from time import sleep
MSG_SIZE=15
i2c = I2C(0, scl=PIN(17), sda=PIN(16), freq=100000)
addr = i2c.scan()[]
i2c.writeto(addr, 'Hi from Pi')
sleep(0.1)
a = i2c.readfrom(addr, MSG_SIZE)
print(a)
The Arduino Code is in Girhub: https://github.com/tinkertechtrove/pico-pi-playing/blob/main/arduino-i2c/sketch_i2c_sub/sketch_i2c_sub.ino
More information:
Programming
Raspberry Pi Pico can be programmed using Micropython or C/C++. This will deal only with MicroPython.
To upload your file to Pico, it need to be put into bootloader mode: hold down the bootsel button while plugging the USB cable: it should show up as a drive called RPI-RP2.
IDE's
- Thonny is the da facto
- VS Studio: MicroPico (the id is paulober.pico-w-go). If not found use this https://github.com/microsoft/vscode/issues/108147 because some Linux distros use OpenVSX.
Picographics, see https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/picographics/README.md There is functions for eg
- drawing a line, circle, rectangle, triangle, polygon
- limited sprite support
- display jpeg files
Thonny
- Connect the USB cable while bootsel button is pressed: RPI-RP2 is found on device manager. If not working, check other cable.
- Copy the pimoroni-galactic_unicorn-v1.20.6-micropython.uf2 to RPI-RP2.
- Start thonny; see the right down corner that correct device is connected. If not, choose it from the list (right down corner).
- Program.
- Run/ Stop / Load.
Micropython
Some libraries are needed. Download from https://github.com/pimoroni/pimoroni-pico/releases
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
Manual: PicoGraphics
from galactic import GalacticUnicorn
Manual: GalacticUnicorn
from machine import Pin, I2C
Text and Fonts
Stationary, centred, scrolling text.
Font library
Nice 5x3 characters: https://forums.pimoroni.com/t/galactic-unicorn-small-numeric-characters/20766
Sound
Effects
Physically modeled fire
Pressing B gives some flames, but this is not what I am looking for. It is located at GitHub https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/galactic_unicorn/fire_effect.py
See https://www.youtube.com/watch?v=bRXrL-8CTmg for a simple idea of a flame.
- Draw vertical sine wave and animate that
- Draw a circle to the point where the flame originates. I'll use Bresenhams algorithm; see https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/ However, there is no need to draw actual circle.
- The circle should be expanded according to the sine function to look like a flame. Two easy option:
- Use linear function; eg
x in range(nmax+y/2-5)
where y is the height (in pixels, inverted) - Use some probapilistic method; eg starting width and shorten it by one or 2.
- Use linear function; eg
- Use smaller and larger circles with different colors. Colors
- Yellow (Orange) smallest
- Red mid-one
- Yellow largest
- Add more flames and make it asynchronous: make a flame object or sprite. Sprite would be easy, just create the animation in 128x128 pixel spritesheet. Thus, I'll try using objects.
More detailed: http://graphics.ucsd.edu/~henrik/papers/fire/fire.pdf
Add flashing: https://www.youtube.com/watch?v=T7LOWIrUKwY