From d8927c95754b1241e1eaab6e88509fa9c302d8aa Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 8 Oct 2024 16:14:50 +0100 Subject: [PATCH] Initial setup of build with added W example --- .github/workflows/micropython.yml | 8 ++- examples/tiny_fx_w/README.md | 16 +++++ .../tiny_fx_w/examples/wifi/random_colour.py | 63 +++++++++++++++++++ examples/tiny_fx_w/secrets.py | 3 + 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 examples/tiny_fx_w/README.md create mode 100644 examples/tiny_fx_w/examples/wifi/random_colour.py create mode 100644 examples/tiny_fx_w/secrets.py diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 4a272c7..48ed1a5 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -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" @@ -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: diff --git a/examples/tiny_fx_w/README.md b/examples/tiny_fx_w/README.md new file mode 100644 index 0000000..50ac6f6 --- /dev/null +++ b/examples/tiny_fx_w/README.md @@ -0,0 +1,16 @@ +# TinyFX W Micropython Examples + +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. diff --git a/examples/tiny_fx_w/examples/wifi/random_colour.py b/examples/tiny_fx_w/examples/wifi/random_colour.py new file mode 100644 index 0000000..a63790a --- /dev/null +++ b/examples/tiny_fx_w/examples/wifi/random_colour.py @@ -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() \ No newline at end of file diff --git a/examples/tiny_fx_w/secrets.py b/examples/tiny_fx_w/secrets.py new file mode 100644 index 0000000..ad19206 --- /dev/null +++ b/examples/tiny_fx_w/secrets.py @@ -0,0 +1,3 @@ +# secrets.py should contain: +WIFI_SSID = "" +WIFI_PASSWORD = "" \ No newline at end of file