Skip to content

Instantly share code, notes, and snippets.

Avatar

Alasdair Allan aallan

View GitHub Profile
@aallan
aallan / watch_code.py
Last active May 11, 2023 20:31
Example MicroPython watch code for the RP2040 1.28-inch TFT display watch board
View watch_code.py
# Digital Watch Face
#
# Author: Tony Goodhew (28th January 2023)
# Updates: Toby Roberts, Andrew Scheller & Alasdair Allan (March 2023)
#
# Original code taken from https://www.instructables.com/Digital-Watch-Display-MicroPython/
from machine import Pin,I2C,SPI,PWM
import framebuf
import time
@aallan
aallan / lcd_imc_test.py
Created March 13, 2023 11:35
Micropython example code for the RP2040 1.28-inch TFT display watch board
View lcd_imc_test.py
'''
I2C_SDA -> 6
I2C_SDA -> 7
DC -> 8
CS -> 9
SCK -> 10
DIN -> 11
RST -> 12
BL -> 25
BAT_ADC -> 29
@aallan
aallan / hello_world.py
Last active May 6, 2023 11:44
Hello World example for the RP2040 1.28-inch TFT display watch board
View hello_world.py
"""
"Hello World!"
For https://www.tindie.com/products/adz1122/pi-pico-rp2040-128-inch-tft-display-watch-board/
Using GC9A01 Display Driver for MicroPython (https://github.com/russhughes/gc9a01_mpy)
DISPLAY
=======
Pin
@aallan
aallan / webserver.py
Created February 2, 2023 16:35
A webserver on a Raspberry Pi Pico W controlling the onboard LED.
View webserver.py
import network
import socket
import time
from machine import Pin
led = Pin("LED", Pin.OUT)
ssid = 'SSID'
password = 'PASSWORD'
View mastodon_followers.py
import rp2
import time
import network
import urequests as requests
# Connect to wireless network
SSID = 'NETWORK NAME'
PASSWORD = 'NETWORK PASSWORD'
rp2.country('GB')
View picow_ntp_client.py
import network
import socket
import time
import struct
from machine import Pin
NTP_DELTA = 2208988800
host = "pool.ntp.org"
@aallan
aallan / ap_webserver.py
Created July 7, 2022 13:43
Running a web server on an wireless Access Point for Raspberry Pi Pico W in MicroPython
View ap_webserver.py
import socket
import network
import machine
ssid = 'MicroPython-AP'
password = '123456789'
led = machine.Pin("LED",machine.Pin.OUT)
ap = network.WLAN(network.AP_IF)
@aallan
aallan / async_webserver.py
Created July 4, 2022 15:38
An asynchronous webserver written in MicroPython to turn an LED on/off on a Raspberry Pi Pico W
View async_webserver.py
import network
import socket
import time
from machine import Pin
import uasyncio as asyncio
led = Pin(15, Pin.OUT)
onboard = Pin("LED", Pin.OUT, value=0)
@aallan
aallan / tensorflow_example.py
Last active February 28, 2022 14:59
Simple TensorFlow Lite and Picamera2 example
View tensorflow_example.py
#!/usr/bin/python3
import tflite_runtime.interpreter as tflite
import sys
import os
import argparse
import cv2
import numpy as np
@aallan
aallan / widget.js
Created December 5, 2019 13:34
Additional code to add widgets into a Bangle.js application when using the Web IDE. Needs to be included at the top of your code.
View widget.js
var WIDGETPOS={tl:32,tr:g.getWidth()-32,bl:32,br:g.getWidth()-32};
var WIDGETS={};
function drawWidgets() { for (var w of WIDGETS) w.draw(); }
require("Storage").list().filter(a=>a[0]=='=').forEach(widget=>eval(require("Storage").read(widget)));
setTimeout(drawWidgets,100);