The discharge of the Raspberry Pi Pico W brings with it an fascinating alternative. Prior to now if we wished to attach a Raspberry Pi to the world, we would want one of many bigger fashions. The Raspberry Pi Zero 2 W, and Raspberry Pi 4 had been typically pressed into information assortment duties. The Raspberry Pi 4 is a little bit of an influence hog, the Zero 2 W is a bit higher however nonetheless overkill for a easy info challenge.
With the arrival of the Raspberry Pi Pico W now we have a low energy, microcontroller with a reliable Wi-Fi chip, within the Pico type issue and solely $6!
So the place will we begin? How will we get our Raspberry Pi Pico W on-line, and the place can we discover fascinating information to gather? Allow us to information you thru benefiting from your $6 Raspberry Pi Pico W.
Getting the Raspberry Pi Pico W On-line
The Raspberry Pi Pico W comes with an Infineon CYW43439 2.4 GHz Wi-Fi chip and onboard antenna. This implies we get good Wi-Fi reception with out the necessity for plenty of wires. We’re utilizing the newest MicroPython launch for the Pico W because it provides the best means to get on-line and do enjoyable initiatives.
1. Setup your Raspberry Pi Pico W by following our getting began information. You have to to put in MicroPython in your Pico W earlier than you possibly can proceed additional.
2. Open the Thonny editor to a clean doc.
3. Create an object referred to as SSID and in it retailer the SSID of your Wi-Fi entry level.
SSID = "YOUR WIFI AP"
4. Create an object referred to as PASSWORD and retailer your Wi-Fi password.
PASSWORD = "TRUSTNO1"
5. Save the file to the Raspberry Pi Pico W as secrets and techniques.py By storing our delicate particulars in a secrets and techniques file, we will freely share the challenge code with buddies, or on-line. Simply keep in mind to not share the secrets and techniques file too.
6. Click on on New File to create a brand new clean doc.
7. Import three modules of code, community, secrets and techniques and time. These three modules allow our Pico to hook up with a Wi-Fi community, use the info saved in secrets and techniques.py and so as to add a pause to the code.
import community
import secrets and techniques
import time
8. Create an object, wlan, to create a connection from our code to the Pico W wi-fi chip. We use this connection to challenge instructions that can join and examine our Wi-Fi connection.
wlan = community.WLAN(community.STA_IF)
9. Activate the Raspberry Pi Pico W’s Wi-Fi.
wlan.energetic(True)
10. Hook up with your router utilizing the SSID and PASSWORD saved within the secrets and techniques.py file.
wlan.join(secrets and techniques.SSID, secrets and techniques.PASSWORD)
11. Print the connection standing to the Python shell. It will print True if linked, and False if the connection failed.
12. Click on Save after which choose “Raspberry Pi Pico”. Save the file as Wi-Fi.py to the Raspberry Pi Pico W.
13. Click on on Run to begin the code.
14. Look within the Python Shell for True or False. True means we’re linked.
Full Code Itemizing
import community
import secrets and techniques
import time
wlan = community.WLAN(community.STA_IF)
wlan.energetic(True)
wlan.join(secrets and techniques.SSID, secrets and techniques.PASSWORD)
print(wlan.isconnected())
Utilizing the Raspberry Pi Pico W With Exterior Knowledge
Now that now we have an Web connection, we’ll use it with publicly accessible datasets to tug information from exterior sources and show it on the Pico W. For this instance we’re going to use Open Notify’s “How many individuals are in area proper now” dataset. This has the quantity and names of all of the astronauts presently on the Worldwide Area Station.
We’re going to adapt our earlier instance code, Wi-Fi.py.
1. Add a line after “import time” and import the urequests module. This module allows us to work with community requests akin to HTTP and JSON.
import urequests
2. After print(wlan.isconnected()) add a brand new line which creates an object “astronauts” after which makes use of urequests to get the data in a JSON format. JavaScript Object Notation is an open normal file format which bears a placing resemblance to Python’s Dictionary which makes use of keys (names) to retrieve values from the article.
astronauts = urequests.get("
3. Create an object, quantity, which is able to open the astronauts object, and search for the important thing ‘quantity’. The worth linked to that secret’s then saved within the quantity object.
quantity = astronauts['number']
4. Create a for loop that can iterate for the variety of folks on the Worldwide Area Station. This worth might change as astronauts come and go, so slightly than exhausting coding a worth we use the reside information.
for i in vary(quantity):
5. Print the identify of every astronaut on the Worldwide Area Station utilizing a collection of keys that focus on the particular information. Our dictionary ‘astronauts’ has many keys, however we have an interest within the ‘folks’, the worth of “i” will increment every time the loop goes spherical, and it selects every particular person from a listing embedded within the dataset. We then use one other key, ‘identify’ to get the identify of that astronaut.
print(astronauts['people'][i]['name'])
6. Save the code and when prepared click on on Run to begin the code.
7. The names of all of the astronauts on the Worldwide Area Station will seem within the Python Shell. Word that “True” nonetheless seems, confirming that our Web connection is established.
Full Code Itemizing
import community
import secrets and techniques
import time
import urequests
wlan = community.WLAN(community.STA_IF)
wlan.energetic(True)
wlan.join(secrets and techniques.SSID, secrets and techniques.PASSWORD)
print(wlan.isconnected())
astronauts = urequests.get("
quantity = astronauts['number']
for i in vary(quantity):
print(astronauts['people'][i]['name'])