From e8f101c79abcbf2d86a626d6cb9235764fd66557 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 21 Oct 2024 15:19:33 +0100 Subject: [PATCH] add RM2 Breakout example --- .../breakouts/rm2-breakout-catfacts.py | 26 +++++++++++++++++++ .../examples/pico_plus_2/breakouts/secrets.py | 2 ++ 2 files changed, 28 insertions(+) create mode 100644 micropython/examples/pico_plus_2/breakouts/rm2-breakout-catfacts.py create mode 100644 micropython/examples/pico_plus_2/breakouts/secrets.py diff --git a/micropython/examples/pico_plus_2/breakouts/rm2-breakout-catfacts.py b/micropython/examples/pico_plus_2/breakouts/rm2-breakout-catfacts.py new file mode 100644 index 0000000..8e4bf0b --- /dev/null +++ b/micropython/examples/pico_plus_2/breakouts/rm2-breakout-catfacts.py @@ -0,0 +1,26 @@ +""" +Get a cat fact from t'internet! +You will need to add your wireless SSID and password to secrets.py (and save this file to your Pico) +""" + +import network +import requests +from secrets import WIFI_SSID, WIFI_PASSWORD +from time import sleep + +# Specify the pins that that wireless module is connected to +# The pins below are for a Pimoroni Pico Plus 2 with a RM2 breakout connected via SP/CE +network.wlan_set_pins(32, 35, 34, 33) # Power, Data IO, Clock, CS + +# connect to wifi +wlan = network.WLAN(network.STA_IF) +wlan.active(True) +wlan.connect(WIFI_SSID, WIFI_PASSWORD) +while wlan.isconnected() is False: + print('Waiting for connection...') + sleep(1) + +request = requests.get('http://catfact.ninja/fact').json() +fact = request['fact'] +print('Cat fact!') +print(fact) diff --git a/micropython/examples/pico_plus_2/breakouts/secrets.py b/micropython/examples/pico_plus_2/breakouts/secrets.py new file mode 100644 index 0000000..1b9c92f --- /dev/null +++ b/micropython/examples/pico_plus_2/breakouts/secrets.py @@ -0,0 +1,2 @@ +WIFI_SSID = 'ssid_goes_here' +WIFI_PASSWORD = 'password_goes_here'