add wireless examples
This commit is contained in:
parent
b96cbf7364
commit
686e623326
25
micropython/examples/pico_plus_2_w/astronauts.py
Normal file
25
micropython/examples/pico_plus_2_w/astronauts.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
"""
|
||||||
|
List all the humans who are currently in space!
|
||||||
|
You will need to add your wireless SSID and password to secrets.py (and save this file to your Pico)
|
||||||
|
This example was adapted from one written by Les Pounder for Tom's Hardware: https://www.tomshardware.com/how-to/connect-raspberry-pi-pico-w-to-the-internet
|
||||||
|
"""
|
||||||
|
|
||||||
|
import network
|
||||||
|
import requests
|
||||||
|
from secrets import SSID, PASSWORD
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# connect to wifi
|
||||||
|
wlan = network.WLAN(network.STA_IF)
|
||||||
|
wlan.active(True)
|
||||||
|
wlan.connect(SSID, PASSWORD)
|
||||||
|
while wlan.isconnected() is False:
|
||||||
|
print('Waiting for connection...')
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
astronauts = requests.get("http://api.open-notify.org/astros.json").json()
|
||||||
|
number = astronauts['number']
|
||||||
|
|
||||||
|
print(f'There are currently {number} humans in space:')
|
||||||
|
for i in range(number):
|
||||||
|
print(astronauts['people'][i]['name'])
|
||||||
13
micropython/examples/pico_plus_2_w/button.py
Normal file
13
micropython/examples/pico_plus_2_w/button.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from machine import Pin
|
||||||
|
|
||||||
|
# Setup the LED and Button pin.
|
||||||
|
led = Pin('LEDW', Pin.OUT)
|
||||||
|
button = Pin(45, Pin.IN)
|
||||||
|
|
||||||
|
# Light the LED when the button is pressed!
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if button.value() == 0:
|
||||||
|
led.value(1)
|
||||||
|
else:
|
||||||
|
led.value(0)
|
||||||
22
micropython/examples/pico_plus_2_w/catfacts.py
Normal file
22
micropython/examples/pico_plus_2_w/catfacts.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""
|
||||||
|
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 SSID, PASSWORD
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# connect to wifi
|
||||||
|
wlan = network.WLAN(network.STA_IF)
|
||||||
|
wlan.active(True)
|
||||||
|
wlan.connect(SSID, 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)
|
||||||
14
micropython/examples/pico_plus_2_w/onboard_led.py
Normal file
14
micropython/examples/pico_plus_2_w/onboard_led.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import time
|
||||||
|
from machine import Pin
|
||||||
|
|
||||||
|
# Setup the LED pin.
|
||||||
|
led = Pin('LEDW', Pin.OUT)
|
||||||
|
|
||||||
|
# Blink the LED!
|
||||||
|
while True:
|
||||||
|
|
||||||
|
led.value(1)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
led.value(0)
|
||||||
|
time.sleep(1)
|
||||||
2
micropython/examples/pico_plus_2_w/secrets.py
Normal file
2
micropython/examples/pico_plus_2_w/secrets.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
SSID = 'ssid_goes_here'
|
||||||
|
PASSWORD = 'password_goes_here'
|
||||||
Loading…
Reference in New Issue
Block a user