MicroPython Commands for Raspberry Pi Pico W (Basic to Advanced)
1. Importing Modules
MicroPython requires essential modules for GPIO, timing, Wi-Fi, etc.
Example:
import machine # For hardware access
import utime # For delays and timestamps
import network # For Wi-Fi (Pico W only)
2. GPIO Control
Configure GPIO as input/output.
led = Pin(25, [Link])
[Link](1) # ON
[Link](0) # OFF
button = Pin(15, [Link], Pin.PULL_UP)
if [Link]() == 0: print('Pressed')
3. Sleep/Delay
[Link](1) # 1 second
utime.sleep_ms(500) # 500 milliseconds
4. PWM for Servo or LED
pwm = PWM(Pin(15))
[Link](50) # Servo freq
pwm.duty_u16(5000)
5. I2C Communication
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=400000)
devices = [Link]()
6. Wi-Fi Connection (STA)
wlan = [Link](network.STA_IF)
[Link](True)
[Link]('SSID', 'PASS')
7. ADC Read
adc = ADC(Pin(26))
value = adc.read_u16()
8. File Read/Write
MicroPython Commands for Raspberry Pi Pico W (Basic to Advanced)
with open('[Link]', 'w') as f:
[Link]('Hello')
with open('[Link]', 'r') as f:
print([Link]())
9. uasyncio Multitasking
import uasyncio as asyncio
async def task(): ...
[Link](main())
10. Interrupt Handling
[Link](trigger=Pin.IRQ_FALLING, handler=callback)
11. Web Server
socket + HTTP server for controlling Pico via browser
12. Timer Events
tim = Timer()
[Link](freq=1, mode=[Link], callback=cb)
13. UART Communication
uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
14. SoftAP Mode
ap = [Link](network.AP_IF)
[Link](True)
[Link](essid='MyPico', password='12345678')
15. MQTT Client
client = MQTTClient('id', 'broker')
[Link]()
[Link]('topic', 'msg')
16. OTA Updates
response = [Link]('url')
with open('[Link]', 'w') as f:
[Link]([Link])
MicroPython Commands for Raspberry Pi Pico W (Basic to Advanced)
17. Custom Modules
# [Link]
def greet(): print('Hi')
# [Link]
import mymodule; [Link]()
18. Memory Optimization
import gc
[Link]()
print(gc.mem_free())
19. Web Dashboard with JS
Use HTML + JavaScript (AJAX) to control pins via browser
20. ESP32-CAM Integration
[Link]('snap') or HTTP to ESP32-CAM