Skip to main content

Hardware List

Setup with Thonny

1

Install Thonny IDE

Download Thonny for your operating system. Thonny has built-in MicroPython support for the Pico W.
2

Flash MicroPython firmware

  1. Hold the BOOTSEL button on the Pico W
  2. While holding, connect the USB cable to your computer
  3. Release BOOTSEL — the Pico appears as a USB drive
  4. Download the latest .uf2 firmware from micropython.org/download/RPI_PICO_W
  5. Drag the .uf2 file onto the Pico USB drive
  6. The Pico reboots automatically with MicroPython
3

Configure Thonny for Pico W

  1. Open Thonny
  2. Go to Tools > Options > Interpreter
  3. Select MicroPython (Raspberry Pi Pico)
  4. Select the correct port (usually auto-detected)
  5. Click OK
  6. You should see the MicroPython REPL in the bottom panel
4

Upload the Lua device library

  1. Open lua_device.py in Thonny
  2. Go to File > Save as…
  3. Select Raspberry Pi Pico as the target
  4. Save as lua_device.py on the Pico
5

Configure WiFi credentials

Create a config.py file on the Pico with your WiFi and Lua credentials:
Keep config.py on the Pico only. Do not commit WiFi passwords or API keys to version control.
6

Create main.py

Create the main application file. This runs automatically when the Pico boots:
7

Run and test

  1. Click the green Run button in Thonny (or press F5)
  2. You should see:
  3. Open lua chat in your terminal and try:

File Structure on Pico

After setup, the Pico should have these files:

Troubleshooting

  • Make sure you are holding BOOTSEL before plugging in the USB cable
  • Try a different USB cable (some are charge-only, not data)
  • Try a different USB port on your computer
  • Pico W only supports 2.4 GHz WiFi (not 5 GHz)
  • Check SSID and password in config.py (case-sensitive)
  • Move the Pico closer to the router
  • Check wlan.status() for error codes: -1 = connection failed, -2 = no matching SSID, -3 = auth failed
  • Verify agent_id and api_key in config.py
  • Check WiFi is connected first (wlan.isconnected())
  • Ensure port 443 (WebSocket) is not blocked by your network
  • Try device = LuaDevice(..., use_ssl=False) temporarily for debugging
  • Add import gc; gc.collect() periodically in your code
  • Compile lua_device.py to bytecode: mpy-cross lua_device.py, then copy lua_device.mpy
  • Reduce payload sizes in command responses
  • Keep the dedup cache small (it auto-cleans at 100 entries)
  • Check the REPL output for error messages
  • Verify command names match between the handler and what the agent expects
  • Ensure device.run() is being called (it is the message processing loop)
  • Check that device.connect() completed without errors
  • Check wiring: data pin to GP15, 10k pull-up resistor between data and 3.3V
  • DHT22 requires at least 2 seconds between readings
  • Try dht_sensor.measure() in the REPL first to verify

Next Steps

MicroPython Client

Full LuaDevice class reference

Factory Monitor

Industrial monitoring example on Pico W

MQTT Transport

MQTT topic structure and QoS details

Triggers

Send events from the Pico W to your agent