How To Connect All New Raspberry Pi Pico W to Internet - Raspberry Pi Projects, Tutorials, Learning DIY Electronics - Makergenix

Breaking

 


How To Connect All New Raspberry Pi Pico W to Internet

 Raspberry Pi Pico W comes with a wireless Infineon CYW43439 chip, We all have been struggling to connect Raspberry Pi Pico to the Internet got a few solutions like Pico Wi-Fi HAT & many DIY solutions to Install Wi-Fi and Internet on a Raspberry Pi Pico.


Now Raspberry Pi Pico W release is made easier for electronic enthusiasts, Pico W comes with Infineon CYW43439 chip Onboard 2.4GHz wireless (802.11n) interface it also supports Bluetooth feature but Raspberry Pi hasn't announced yet.


This indicates that we have strong Wi-Fi reception without the use of several cables. The most convenient way to connect to the internet and complete enjoyable tasks on the Pico W is to use the most recent MicroPython version.

How To Connect Raspberry Pi Pico W to Internet

So how do we connect Raspberry Pi Pico W to Internet? Where can we discover relevant data to gather? We'll show you how to maximize the capabilities of a $6 Raspberry Pi Pico W.

Connecting Raspberry Pi Pico W online with C/C++ or MicroPython 

1. Configure your Raspberry Pi Pico W by using our setup instructions. Before continuing, you must first install MicroPython on your Pico W.


2. Open a new document in the Thonny editor.


3. Create an object named SSID and put your Wi-Fi access point's SSID inside of it.

SSID = "YOUR WIFI AP"

4. Create the PASSWORD object and use it to store your Wi-Fi password.

PASSWORD = "TRUSTNO1"

5. Save the document as secrets.py to the Raspberry Pi Pico W. We may freely share the project code with friends or the internet by keeping our private information in a secret file. Just be sure to keep the secrets file private.


6. To create a brand-new, blank document, click New File.


7. Import 3 code, network, secret, and time modules. These three modules allow our Pico to establish a Wi-Fi connection, access the information contained in secrets.py, and insert a stop into the programme.

import network
import secrets
import time

8. Create the WLAN object so that our code may connect to the Pico W wireless chip. We send commands across this connection to connect and check our Wi-Fi connection.

wlan = network.WLAN(network.STA_IF)

9. Turn on the WiFi on the Raspberry Pi Pico W.

wlan.active(True)

10. Use the SSID and PASSWORD found in the secrets.py file to log into your router.

wlan.connect(secrets.SSID, secrets.PASSWORD)

11. To the Python shell, print the connection status. If the connection was successful, this will print True; otherwise, it will print False.


12. After clicking Save, choose "Raspberry Pi Pico." To the Raspberry Pi Pico W, save the file as Wi-Fi.py.


13. To begin the code, click Run.


14. Search for True or False in the Python Shell. True implies that we are related.


Making Use of External Data with the Raspberry Pi Pico W

We will leverage the Internet connection we already have in conjunction with openly accessible datasets to pull information from outside sources and show it on the Pico W. We'll utilize Open Notify's "How many people are in space right now" dataset for this example. All of the astronauts that are presently stationed aboard the International Space Station are listed here by number and name.

We're going to modify the Wi-Fi.py programme from our previous example.


1. After "import time," add a line, and import the urequests module. We can interact with network requests like HTTP and JSON thanks to this module.

import urequests

2. Insert a new line after print (wlan is connected) that creates the object "astronauts" and uses requests to retrieve the data in JSON format. An open standard file format called JavaScript Object Notation is very similar to Python's Dictionary, which employs keys (names) to get data from the object.

astronauts = urequests.get("http://api.open-notify.org/astros.json").json()

3. Make a number-containing item that will open the astronauts' object, and search for the key. The number object is then used to hold the value associated with that key.

number = astronauts['number']

4. Construct an iterative for loop that counts the inhabitants of the International Space Station. Instead of hard-coding a value, we use real-time data because this number could vary when astronauts arrive and go.

for i in range(number):

5. Using a series of keys that specifically target the relevant data, print the names of each astronaut aboard the International Space Station. The value of I will increase every time the loop iterates, and it chooses each astronaut from a list contained in the dataset. Although our dictionary's "astronauts" includes several keys, we are only interested in the "people." The name of the astronaut is then obtained using a different key, "name."

   print(astronauts['people'][i]['name'])

6. Save the code, then when you're ready, click Run to launch it.

7. The Python Shell will display the names of every astronaut currently on the International Space Station. It is important to note that "True" is still shown, indicating that our Internet connection is active.

Have you got your Raspberry Pi Pico W!

 Credit: Les Pounder

 


Most Viewed Posts

Write For Us

Name

Email *

Message *

All Blogs