Useful functions for creating games and apps with Sprig
Project description
Sprig Essentials
Useful functions to simplify the process of creating games and apps with Sprig.
This package is not affiliated with Sprig or HackClub in any form.
Documentation
This package is intended to run on any type of Raspberry Pi
.
Most focused on the Raspberry Pi Pico H
.
This package assumes you've installed CircuitPython
and are using the ST7735
display.
Wiring Diagram
The wiring diagram that this package assumes is intended for anyone using a Sprig, however, you can also wire this manually and achieve the same effect.
Display
Imports
You will need to import the following to connect to the pins and use the package.
import board
from sprig_essentials import *
If you're using a Sprig, chances are the wiring is going to be the exact same through the board, so you can skip to quickStartDisplay()
.
startBacklight()
def startBacklight(backlight_pin):
# Create the digital output
backlight = digitalio.DigitalInOut(backlight_pin)
# Set it as output
backlight.direction = digitalio.Direction.OUTPUT
# Turn it on
backlight.value = True
return backlight
This function takes in the pin number where the LITE
pin on the display is connected to (formatted like so: board.GP0
), and turns the backlight on.
It returns an object of type digitalio.DigitalInOut
which will be used in other functions.
Example:
import board
backlight = startBacklight(board.GP17)
createSPI()
def createSPI(clock_pin, MOSI_pin, MISO_pin):
spi = busio.SPI(clock=clock_pin, MOSI=MOSI_pin, MISO=MISO_pin)
return spi
This function takes in 3 pin numbers (formatted like so: board.GP0
) and creates an SPI which will be used when creating a display bus.
It returns an object of type busio.SPI
.
Example:
import board
spi = createSPI(board.GP18, board.GP19, board.GP16)
createDisplayBus()
def createDisplayBus(spi, cs_pin, dc_pin, reset_pin):
display_bus = displayio.FourWire(spi, command=dc_pin, chip_select=cs_pin, reset=reset_pin)
return display_bus
This function takes in 3 pin numbers (formatted like so: board.GP0
) along with an SPI (See createSPI()
) and creates a display bus.
It returns an object of type displayio.FourWire
.
Example:
import board
spi = createSPI(board.GP18, board.GP19, board.GP16)
display_bus = createDisplayBus(spi, board.GP20, board.GP22, board.GP26)
initDisplay()
def initDisplay(display_bus, width, height, rotation=0, bgr=True, auto_refresh=True):
display = ST7735R(display_bus, width=width, height=height, rotation=rotation, bgr=bgr)
display.auto_refresh = auto_refresh
return display
This function requires a display bus (See createDisplayBus()
), and the screen's width and height as an integer.
There are 3 optional parameters: the rotation which should be a multiple of 90 degrees, the colour format (depends on the type of screen), and whether the display should auto-refresh or not.
Example:
import board
spi = createSPI(board.GP18, board.GP19, board.GP16)
display_bus = createDisplayBus(spi, board.GP20, board.GP22, board.GP26)
display = initDisplay(display_bus, 160, 128, rotation=270)
quickStartDisplay()
def quickStartDisplay():
backlight = startBacklight(board.GP17)
spi = createSPI(board.GP18, board.GP19, board.GP16)
display_bus = createDisplayBus(spi, board.GP20, board.GP22, board.GP26)
display = initDisplay(display_bus, 160, 128, rotation=270)
return backlight, spi, display_bus, display
This function assumes you're using a Sprig, meaning the pin wiring will be the same across all of them. The display and Raspberry Pi Pico should be the same model and therefore these users can simply use this function rather than set the parameters manually using the previous functions.
Example:
backlight, spi, display_bus, display = quickStartDisplay()
Using this also doesn't require importing board
.
Documentation unfinished
Audio
createI2S()
def createI2S(bit_clock_pin, word_select_pin, data_pin):
i2s = audiobusio.I2SOut(bit_clock_pin, word_select_pin, data_pin)
return i2s
This function takes in 3 numbers (formatted like so: board.GP0
) and creates an I2S. The return is an audiobusio.I2SOut
that can be used to play a sound.
Example:
import board
i2s = createI2S(board.GP10, board.GP11, board.GP9)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sprig_essentials-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4edbd3e1b6255ef43acc15e2e881d96047474d2eef9e058db07f35443f70fc8 |
|
MD5 | bf94b779c1f06319ea8e32be4aed4b8b |
|
BLAKE2b-256 | 60cf3a120392f614aa3796e84293071d28de200d29cd064fceacb2a1265e5b24 |