Raspberry Pi Pico W Project Setup

1. Pico SDK Install

  1. Create a new VS Code profile dedicated to Raspberry Pi Pico development.
  2. Install the Raspberry Pi Pico SDK extensions in that profile.

Locate your Ninja location

C:\Users\jonat\.pico-sdk\ninja\v1.12.1

Add this to pico/.vscode/settings.json:

"cmake.configureSettings": {
    "CMAKE_MAKE_PROGRAM": "C:/Users/jonat/.pico-sdk/ninja/v1.12.1/ninja.exe"
},

2. MQTT Setup for Local

Install Mosquitto MQTT Broker

Download Link

  • Create a new inbound firewall rule. Allow port 1883.
  • Simply add these two lines at the top of mosquitto.conf and save.
listener 1883 0.0.0.0
allow_anonymous true

2. MQTT Setup for Docker

  • If Mosquitto MQTT Broker is installed, disable it in the services settings.

3. .env Setup

  • At this point, build and flash the code onto the pico (see section 3 below). Open the serial monitor and copy the Pico's MAC and IP address to update it into the database and the .env file.
  • To find the MQTT_BROKER (computer ip) on windows in a command prompt:
ipconfig

Copy the env template:

cp .env.example .env

Edit .env at project root with your own values:

MQTT_BROKER=0.0.0.0
MQTT_PORT=1883
PICO_MAC_ADDRESS=00:00:00:00:00:00
PICO_IP_ADDRESS=0.0.0.0
TIME_ZONE=Europe/Copenhagen

4. wifi_config.h Setup

Copy the wifi config template :

cp pico/wifi_config.h.example pico/wifi_config.h

Configure the broker server ip, network SSID and password in wifi_config.h in the pico folder with your own values:

#define WIFI_SSID "your_network_name"
#define WIFI_PASSWORD "your_network_password"
#define MQTT_SERVER "0.0.0.0"

5. Update the Database with the Pico Fields

  • This can also be done manually in pgAdmin 4.
  • Otherwise find seed_data.py and update the IP address and MAC address fields. Seed the data to update the database:
env/Scripts/activate
cd backend
py manage.py seed_data

6. Build and Uploading Code

  1. First build the project from the cmake extension.
    • A successful build will show the message: [Build] Build finished with exit code 0
  2. Click the flash button

Without Debug Probe

  1. First build the project from the cmake extension.
    • A successful build will show the message: [Build] Build finished with exit code 0
  2. Locate the pico/build/main.uf2 file.
  3. Hold the BOOTSEL button while plugging the USB into the Pico.
  4. Copy and paste the main.uf2 file into the Pico drive that appears in file explorer.

Troubleshooting

  1. Delete the entire build folder.
  2. Reconfigure with:
cmake --no-warn-unused-cli -S . -B build -G Ninja

Recommended Pico Dev Workflow with VS Code

  • Open one VS Code instance at the root folder of the project.
  • Open a second VS Code instance.
    • Go to File > Open Folder and select the pico folder.
    • Set this instance to use the Pico-specific VS Code profile (with the required extensions).