Skip to content

Commit

Permalink
Examples: updating for use with built-in touch module and EzWiFi
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdr committed Nov 28, 2024
1 parent 1a710c6 commit e9b9d93
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 124 deletions.
55 changes: 11 additions & 44 deletions examples/agile_pricing_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,26 @@
Shows the current, next and last energy price for Octopus Energys Agile Price tarrif
'''

import network
import asyncio
import datetime
import time
import requests

import machine
import ntptime
import datetime
from picographics import PicoGraphics, DISPLAY_PRESTO
import requests
from ezwifi import EzWiFi
from picographics import DISPLAY_PRESTO, PicoGraphics
from picovector import ANTIALIAS_BEST, PicoVector, Polygon, Transform
from presto import Presto
from picovector import PicoVector, ANTIALIAS_BEST, Polygon, Transform
import machine

machine.freq(264000000)

# Check and import the Network SSID and Password from secrets.py
# import the Spotify API keys from that file too
try:
from secrets import WIFI_SSID, WIFI_PASSWORD
if WIFI_SSID == "":
raise ValueError("WIFI_SSID in 'secrets.py' is empty!")
if WIFI_PASSWORD == "":
raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!")
except ImportError:
raise ImportError("'secrets.py' is missing from your Pimoroni Presto!")
except ValueError as e:
print(e)

# Constants
API_URL = 'https://api.octopus.energy/v1/products/AGILE-FLEX-22-11-25/electricity-tariffs/E-1R-AGILE-FLEX-22-11-25-C/standard-unit-rates/'

wlan = network.WLAN(network.STA_IF)


def network_connect():
# Connect to the network specified in secrets.py
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
attempts = 0
while wlan.isconnected() is False:
print("Attempting connection to {}".format(WIFI_SSID))
time.sleep(1)
attempts += 1
if attempts > 10:
raise OSError('Unable to connect to wireless network. Check your WIFI_SSID and WIFI_PASSWORD and try again.')


# Start connection to the network
network_connect()

# Store the local IP address
ip_addr = wlan.ipconfig('addr4')[0]

# Let the user know the connection has been successful
# and display the current IP address of the Pimoroni Presto
print("Successfully connected to {}. Your Pimoroni Presto IP is: {}".format(WIFI_SSID, ip_addr))
# WiFi setup
wifi = EzWiFi(verbose=True)
connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2))

# Set the correct time using the NTP service.
ntptime.settime()
Expand Down
39 changes: 8 additions & 31 deletions examples/cheerlights_bulb.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import asyncio
import time

import machine
import network
import plasma
import requests
from ft6236 import FT6236
from ezwifi import EzWiFi
from picographics import DISPLAY_PRESTO, PicoGraphics
from picovector import ANTIALIAS_BEST, PicoVector, Polygon, Transform
from presto import Presto
from touch import FT6236

BULB_OUTLINE = [(130.44, 0.0),
(150.36, 1.51),
Expand Down Expand Up @@ -105,17 +106,9 @@

machine.freq(264000000)

# Check and import the SSID and Password from secrets.py
try:
from secrets import WIFI_PASSWORD, WIFI_SSID
if WIFI_SSID == "":
raise ValueError("WIFI_SSID in 'secrets.py' is empty!")
if WIFI_PASSWORD == "":
raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!")
except ImportError:
raise ImportError("'secrets.py' is missing from your Plasma 2350 W!")
except ValueError as e:
print(e)
# WiFi setup
wifi = EzWiFi(verbose=True)
connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2))

# Setup for the Presto display
presto = Presto()
Expand All @@ -134,21 +127,6 @@
BLACK = display.create_pen(0, 0, 0)
GRAY = display.create_pen(75, 75, 75)

wlan = network.WLAN(network.STA_IF)


def connect():
# Connect to the network specified in secrets.py
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while wlan.isconnected() is False:
print("Attempting connection to {}".format(WIFI_SSID))
time.sleep(1)


# Start connection to the network
connect()

# WS2812 / NeoPixel™ LEDs used for the backlight
bl = plasma.WS2812(7, 0, 0, 33)
bl.start()
Expand Down Expand Up @@ -235,11 +213,10 @@ def get_cheerlight():
# Poll the touch so we can see if anything changed since the last time
touch.poll()

if wlan.isconnected():
if connected:
# If the user is touching the screen we'll do the following
if touch.state:
bulb_on = not bulb_on
print(f"Bulb is {bulb_on}")
# Wait for the user to stop touching the screen
while touch.state:
touch.poll()
Expand Down Expand Up @@ -271,6 +248,6 @@ def get_cheerlight():
draw_bulb((50, 50, 50))

else:
print("Lost connection to network {}".format(WIFI_SSID))
print("Lost connection to network")

presto.update(display)
2 changes: 1 addition & 1 deletion examples/image_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import plasma
import sdcard
import uos
from ft6236 import FT6236
from picographics import DISPLAY_PRESTO, PicoGraphics
from presto import Presto
from touch import FT6236

machine.freq(264000000)

Expand Down
9 changes: 5 additions & 4 deletions examples/touchscreen_dots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from picographics import PicoGraphics, DISPLAY_PRESTO
from presto import Presto
from ft6236 import FT6236
from random import randint
import time
from random import randint

from picographics import DISPLAY_PRESTO, PicoGraphics
from presto import Presto
from PrestoLight import Reactive
from touch import FT6236

# Setup for the Presto display
presto = Presto()
Expand Down
11 changes: 6 additions & 5 deletions examples/touchscreen_dots_vector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from picographics import PicoGraphics, DISPLAY_PRESTO
from presto import Presto
from ft6236 import FT6236
from random import randint
import time
from picovector import PicoVector, ANTIALIAS_FAST, Polygon
from random import randint

import machine
from picographics import DISPLAY_PRESTO, PicoGraphics
from picovector import ANTIALIAS_FAST, PicoVector, Polygon
from presto import Presto
from touch import FT6236

machine.freq(264000000)

Expand Down
44 changes: 5 additions & 39 deletions examples/word_clock.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import asyncio
import time

import machine
import network
import ntptime
import pngdec
from ezwifi import EzWiFi
from picographics import DISPLAY_PRESTO, PicoGraphics
from presto import Presto

machine.freq(264000000)

# Check and import the Network SSID and Password from secrets.py
# import the Spotify API keys from that file too
try:
from secrets import WIFI_PASSWORD, WIFI_SSID
if WIFI_SSID == "":
raise ValueError("WIFI_SSID in 'secrets.py' is empty!")
if WIFI_PASSWORD == "":
raise ValueError("WIFI_PASSWORD in 'secrets.py' is empty!")
except ImportError:
raise ImportError("'secrets.py' is missing from your Pimoroni Presto!")
except ValueError as e:
print(e)

# Length of time between updates in minutes.
UPDATE_INTERVAL = 15

Expand All @@ -30,31 +18,9 @@
words = ["it", "d", "is", "m", "about", "lv", "half", "c", "quarter", "b", "to", "past", "n", "one",
"two", "three", "four", "five", "six", "eleven", "ten", "d", "nin", "eight", "seven", "rm", "twelve", "rtywtqdj", "O'Clock", "grd", "nhelloprestoa"]

wlan = network.WLAN(network.STA_IF)


def network_connect():
# Connect to the network specified in secrets.py
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
attempts = 0
while wlan.isconnected() is False:
print("Attempting connection to {}".format(WIFI_SSID))
time.sleep(1)
attempts += 1
if attempts > 10:
raise OSError('Unable to connect to wireless network. Check your WIFI_SSID and WIFI_PASSWORD and try again.')


# Start connection to the network
network_connect()

# Store the local IP address
ip_addr = wlan.ipconfig('addr4')[0]

# Let the user know the connection has been successful
# and display the current IP address of the Pimoroni Presto
print("Successfully connected to {}. Your Pimoroni Presto IP is: {}".format(WIFI_SSID, ip_addr))
# WiFi setup
wifi = EzWiFi(verbose=True)
connected = asyncio.get_event_loop().run_until_complete(wifi.connect(retries=2))

# Set the correct time using the NTP service.
ntptime.settime()
Expand Down

0 comments on commit e9b9d93

Please sign in to comment.