Pimoroni Galactic Unicorn Hello World

From wikiluntti
Revision as of 09:58, 7 December 2023 by Mol (talk | contribs) (→‎Connect to Arduino UNO)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

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

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

  1. Connect the USB cable while bootsel button is pressed: RPI-RP2 is found on device manager. If not working, check other cable.
  2. Copy the pimoroni-galactic_unicorn-v1.20.6-micropython.uf2 to RPI-RP2.
  3. Start thonny; see the right down corner that correct device is connected. If not, choose it from the list (right down corner).
  4. Program.
  5. 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:
    1. Use linear function; eg
      x in range(nmax+y/2-5)
      where y is the height (in pixels, inverted)
    2. 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