Raspberry Pi Pico Wの無線LANモジュールをアクセスポイントとして使って機器を操作します。

Raspberry Pi Pico Wの無線LANモジュールをアクセスポイントとして使います。
スマホなどからWi-Fi接続先としてRaspberry Pi Pico Wのアクセスポイントに接続します。接続後に機器を操作します。
今回はサーボモーターを動かして本体LEDを点滅させます。
Raspberry Pi Pico W ➕ スマホ ➕ サーボモーター
配線図
実際の配線
MicroPythonプログラム
import network
import machine
from machine import PWM
from machine import Pin
from time import sleep
led= machine.Pin('LED', machine.Pin.OUT)
#Pin param = servo GPIO pin number
pwm = PWM(machine.Pin(16))
ssid = 'Lights-Out'
password = 'sleeptime'
ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True)
while ap.active() == False:
  pass
print('Connection successful')
print(ap.ifconfig())
def rotateServo ():
    pwm.freq(50)
    pwm.duty_ns(2000000)
    sleep(0.5)
    pwm.duty_ns(1500000)
    
    led.high()
    sleep( 1 )
    led.low()
    
#ap.status is a blank array until someone connects, then it will have one entry
#when ap.status = true, then it will trigger rotateServo()
# then it will shut itself off to kick the user off the network,
# allowing the device to reconnect to its usual network
while True:
    try:
        if ap.status('stations'):
            print('client connected')
            rotateServo()
            sleep(5)
            ap.active(False)
            sleep(2)
            ap.active(True)
        
    except OSError as e:
        print('Connection closed')
実行
 






 
 
 
 
 
その後、アクセスポイントのパスワードは他からは見えなくなります。アクセスポイントとパスワードを知っていいる人だけが使える機器がつくれます。