Skip to content

Commit

Permalink
Initial setup of build with added W example
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Oct 8, 2024
1 parent 2a868d5 commit d8927c9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/micropython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
ROOT_DIR: "$GITHUB_WORKSPACE/picofx"
BOARD_DIR: "$GITHUB_WORKSPACE/picofx/boards/${{matrix.board}}"
EXAMPLES_DIR: "$GITHUB_WORKSPACE/picofx/examples/tiny_fx"
EXAMPLES_W_DIR: "$GITHUB_WORKSPACE/picofx/examples/tiny_fx_w"
FILESYSTEM_DIR: "$GITHUB_WORKSPACE/picofx/temp"
FILESYSTEM_SUFFIX: "with-libs-and-examples"
BOARD: "PIMORONI_TINYFX"
Expand Down Expand Up @@ -186,13 +187,18 @@ jobs:
cp -v -r ${{env.BOARD_DIR}}/visible_libs/. ${{env.FILESYSTEM_DIR}}/lib
cp -v -r ${{env.EXAMPLES_DIR}}/. ${{env.FILESYSTEM_DIR}}
- name: "HACK: Mangle W examples into user filesystem"
if: matrix.shortname == 'tiny_fx_w'
shell: bash
run: |
cp -v -r ${{env.EXAMPLES_W_DIR}}/. ${{env.FILESYSTEM_DIR}}
- name: Append Filesystem
shell: bash
run: |
python3 -m pip install littlefs-python==0.12.0
./dir2uf2/dir2uf2 --fs-compact --append-to micropython/ports/rp2/build/${{env.RELEASE_FILE}}.uf2 --manifest ${{env.BOARD_DIR}}/uf2-manifest.txt --filename ${{env.FILESYSTEM_SUFFIX}}.uf2 ${{env.FILESYSTEM_DIR}}/
- name: Store .uf2 as artifact
uses: actions/upload-artifact@v4
with:
Expand Down
16 changes: 16 additions & 0 deletions examples/tiny_fx_w/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TinyFX W Micropython Examples <!-- omit in toc -->

These are micropython examples for the wireless functionality of the Pimoroni [TinyFX W](https://shop.pimoroni.com/products/tiny_fx_w), a stamp-sized light and sound effects controller board for model making, construction kits, and dioramas.

For examples that show off the rest of the board's functions, refer to the regular [TinyFX Micropython Examples](../tiny_fx/README.md)

- [WiFi Examples](#wifi-examples)
- [Random Colour](#random-colour)


## WiFi Examples

### Random Colour
[wifi/random_colour.py](examples/wifi/random_colour.py)

Show the state of TinyFX's Boot button on its RGB output.
63 changes: 63 additions & 0 deletions examples/tiny_fx_w/examples/wifi/random_colour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import time
import network
import requests
from tiny_fx import TinyFX

"""
Press "Boot" to exit the program.
"""
# secrets.py should contain:
# WIFI_SSID = ""
# WIFI_PASSWORD = ""

try:
from secrets import WIFI_SSID, WIFI_PASSWORD
except ImportError:
print("Create secrets.py with your WiFi credentials")


# Constants
MONO_NAMES = ("One", "Two", "Three", "Four", "Five", "Six")
COLOUR_NAMES = ("R", "G", "B")

# Variables
tiny = TinyFX() # Create a new TinyFX object to interact with the board


# Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)

while wlan.isconnected() == False:
print('Waiting for connection...')
time.sleep(1)

ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')


# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
try:
while True:
req = requests.get("https://random-flat-colors.vercel.app/api/random?count=2").json()

mono = tuple(int(req['colors'][0][i:i+1], 16) / 15 for i in range(1, 7))
colour = tuple(int(req['colors'][1][i:i+2], 16) for i in (1, 3, 5))

for i in range(len(tiny.outputs)):
tiny.outputs[i].brightness(mono[i])
print(f"{MONO_NAMES[i]} = {round(mono[i], 2)}", end=", ")

tiny.rgb.set_rgb(*colour)
for i in range(len(colour)):
print(f"{COLOUR_NAMES[i]} = {colour[i]}", end=", ")

print()

time.sleep(5)

# Turn off all the outputs
finally:
tiny.shutdown()
wlan.disconnect()
3 changes: 3 additions & 0 deletions examples/tiny_fx_w/secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# secrets.py should contain:
WIFI_SSID = ""
WIFI_PASSWORD = ""

0 comments on commit d8927c9

Please sign in to comment.