0
0 items
Rp0
No products in the cart.
Last Offers
Rp50.000 Rp45.000
Rp45.000 Rp37.500
Rp3.015.000 Rp2.950.000
Rp565.000 Rp550.000
Rp685.000 Rp600.000
Raspberry Pi Pico / Pico W Sensor Shield Developer Board
Shield ESP32 Wroom DevkitC V4 38PIN
Seeed Studio Industrial pH Meter / Sensor RS485 Modbus
Arduino Ethernet Shield 2
Arduino Mega 2560 Rev3 ATmega2560
Langkah2 blink LED via WiFi on Pico W
Persiapan Bahan: #
– Raspberry Pi Pico W
– Kabel Micro USD
– Aplikasi Thonny IDE
Set up MicroPython #
Siapkan MikroPython
Pertama, Anda perlu menyiapkan MicroPython. Unduh file UF2 di sini yang khusus ditujukan untuk Pico W.
Tahan tombol BOOTSEL dan sambungkan Pico W Anda melalui USB.
Setelah dipasang, salin file UF2 yang baru saja Anda unduh ke Pico W.
Sample Code – secret.py #
secrets = {
'ssid': 'Replace-this-with-your-Wi-Fi-Name',
'pw': 'Replace-this-with-your-Wi-Fi-Password'
}
Sample Code – main.py #
import rp2
import network
import ubinascii
import machine
import urequests as requests
import time
from secrets import secrets
import socket
# Set country to avoid possible errors
rp2.country('DE')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# If you need to disable powersaving mode
# wlan.config(pm = 0xa11140)
# See the MAC address in the wireless chip OTP
mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
print('mac = ' + mac)
# Other things to query
# print(wlan.config('channel'))
# print(wlan.config('essid'))
# print(wlan.config('txpower'))
# Load login data from different file for safety reasons
ssid = secrets['ssid']
pw = secrets['pw']
wlan.connect(ssid, pw)
# Wait for connection with 10 second timeout
timeout = 10
while timeout > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
timeout -= 1
print('Waiting for connection...')
time.sleep(1)
# Define blinking function for onboard LED to indicate error codes
def blink_onboard_led(num_blinks):
led = machine.Pin('LED', machine.Pin.OUT)
for i in range(num_blinks):
led.on()
time.sleep(.2)
led.off()
time.sleep(.2)
# Handle connection error
# Error meanings
# 0 Link Down
# 1 Link Join
# 2 Link NoIp
# 3 Link Up
# -1 Link Fail
# -2 Link NoNet
# -3 Link BadAuth
wlan_status = wlan.status()
blink_onboard_led(wlan_status)
if wlan_status != 3:
raise RuntimeError('Wi-Fi connection failed')
else:
print('Connected')
status = wlan.ifconfig()
print('ip = ' + status[0])
# Function to load in html page
def get_html(html_name):
with open(html_name, 'r') as file:
html = file.read()
return html
# HTTP server with socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print('Listening on', addr)
led = machine.Pin('LED', machine.Pin.OUT)
# Listen for connections
while True:
try:
cl, addr = s.accept()
print('Client connected from', addr)
r = cl.recv(1024)
# print(r)
r = str(r)
led_on = r.find('?led=on')
led_off = r.find('?led=off')
print('led_on = ', led_on)
print('led_off = ', led_off)
if led_on > -1:
print('LED ON')
led.value(1)
if led_off > -1:
print('LED OFF')
led.value(0)
response = get_html('index.html')
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
cl.send(response)
cl.close()
except OSError as e:
cl.close()
print('Connection closed')
# Make GET request
#request = requests.get('http://www.google.com')
#print(request.content)
#request.close()
Sample Code – index.html #
<!DOCTYPE html>
<html>
<head>
<title>Pico W</title>
</head>
<body>
<h1>Pico W</h1>
<p>Control the onboard LED</p>
<a href=\"?led=on\"><button>ON</button></a>
<a href=\"?led=off\"><button>OFF</button></a>
</body>
</html>
Updated on 13/01/2023
Join our newsletter for £10 offs
Get our emails for info on new items, sales and much more.
Register now to get latest updates on promotions & coupons. Don’t worry, we not spam!
Völogi deledes ponade eujäjurtad
Autoseligen syr. Nek diarask fröbomba. Nör antipol kynoda nynat. Pressa fåmoska. Aposkop redelingar nede, sektigt.
Need Help?
Customer Service
Store Information
- -5% for all order in this week Shop now
- Free delivery for all orders over $200