🛠️ Raspberry Pi Pico W IoT Guide: Generalized Firmware for Home Automation

A privacy-first, reproducible firmware for Raspberry Pi Pico W—designed for seamless Home Assistant integration and scalable IoT projects.

📋 Table of Contents

🔍 High-Level Overview

This Raspberry Pi Pico W firmware creates a generalized IoT agent for home automation. Instead of hardcoding behavior, each device retrieves GPIO configuration from a database via API, based on its physical setup. The same firmware runs across all Pico W devices, reducing maintenance and enabling scalable, privacy-respecting automation.

View Firmware on GitHub | Explore More IoT Projects

Raspberry Pi Pico W IoT architecture diagram

📚 Pico W Firmware Workflow

The firmware follows a streamlined process to enable IoT functionality with Raspberry Pi Pico W:

  1. Connect to Wi-Fi: Attempts connection to configured networks.
  2. Register with Environment: Sends device metadata to an API to identify itself.
  3. Retrieve GPIO Configuration: Downloads pin mappings defining inputs (e.g., sensors) and outputs (e.g., relays).
  4. Read Inputs: Monitors sensor values and publishes to an MQTT topic for Home Assistant.
  5. Listen for Output Instructions: Subscribes to MQTT topics for commands.
  6. Apply Outputs: Executes instructions on configured GPIO outputs.
  7. Publish Acknowledgment: Confirms output actions via MQTT for Home Assistant feedback.
Raspberry Pi Pico W firmware workflow for IoT

📄 Sample Raspberry Pi Pico W Firmware Log

This log demonstrates the Pico W’s startup, registration, GPIO setup, and MQTT communication for IoT integration.

View Sample Log Output
Script starting...
Trying to connect to ccc-home-IoT...
Waiting for connection to ccc-home-IoT... 0
Waiting for connection to ccc-home-IoT... 1
Waiting for connection to ccc-home-IoT... 2
Connected, IP: 192.168.1.252
Time set took 38ms
set_time took 3370ms
Loop start: Free memory 182368, Time 7568
Registration payload: {'prev_outputs': {}, 'mac': '28:cd:c1:0e:c0:db', 'input_vals': {}, 'mqtt_input_topic': '', 'iscon': True, 'isreged': False, 'logerrors': False, 'ssid': 'ccc-home-IoT', 'ip': '192.168.1.252', 'hasioconf': False, 'device_id': None, 'printdebug': None, 'printerr': True, 'device_type': 'pico_w', 'name': 'I need a name', 'mqtt_output_topic': ''}
Free memory before register: 181296
Register request took 248ms
Registration Response: {'results': {'device_id': 8, 'refrsh_int': 1, 'name': 'Testing pico', 'mqtt_output_topic': 'testing/pico/outputs', 'mqtt_acked_output_topic': 'test', 'mqtt_input_topic': 'testing/pico/inputs', 'device_grp': 'test'}, 'status': '200 Ok'}
Register took 293ms
Registered: {'device_name': 'Testing pico', 'printerr': True, 'name': 'Testing pico', 'device_type': 'pico_w', 'printdebug': None, 'logerrors': False, 'mqtt_output_topic': 'testing/pico/outputs', 'mqtt_acked_output_topic': 'test', 'ssid': 'ccc-home-IoT', 'mac': '28:cd:c1:0e:c0:db', 'device_grp': 'test', 'refrsh_int': 1, 'isreged': True, 'mqtt_input_topic': 'testing/pico/inputs', 'ip': '192.168.1.252', 'hasioconf': False, 'iscon': True, 'prev_outputs': {}, 'device_id': 8, 'input_vals': {}}
Free memory before get_io_config: 181104
Get IO config request took 46ms
Received io_conf: {'25': {'io_type': 'LED', 'io_mode': 'OUT', 'ioid': '25', 'io_name': 'LED'}, '4': {'io_type': 'ADC', 'io_mode': 'IN', 'ioid': '4', 'io_name': 'Internal Temperature'}}
Initialized LED on pin 25 as OUTPUT
Initialized ADC on pin 4
Get IO config took 81ms
Got IO Config: {'device_name': 'Testing pico', 'printerr': True, 'name': 'Testing pico', 'device_type': 'pico_w', 'printdebug': None, 'logerrors': False, 'mqtt_output_topic': 'testing/pico/outputs', 'mqtt_acked_output_topic': 'test', 'ssid': 'ccc-home-IoT', 'mac': '28:cd:c1:0e:c0:db', 'device_grp': 'test', 'refrsh_int': 1, 'isreged': True, 'mqtt_input_topic': 'testing/pico/inputs', 'ip': '192.168.1.252', 'hasioconf': True, 'iscon': True, 'prev_outputs': {}, 'device_id': 8, 'input_vals': {}}
MQTT client reconnected with ID: 28cdc10ec0db
MQTT setup took 197ms
MQTT connected and subscribed to outputs
Read IO 4 took 0ms
Read input vals took 199ms
Published inputs: {'4': {'io_duty': '', 'io_v': 30.79575, 'io_name': 'Internal Temperature', 'io_type': 'ADC', 'io_freq': '', 'ioid': '4', 'io_mode': 'IN'}}
Publish took 4ms
Availability publish took 2ms
Published availability: online
Check msg took 1ms
Loop end: Total time 2ms
Loop start: Free memory 180720, Time 9149
MQTT setup took 14ms
MQTT connected and subscribed to outputs
Read IO 4 took 0ms
Read input vals took 17ms
Published inputs: {'4': {'io_duty': '', 'io_v': 31.2639, 'io_name': 'Internal Temperature', 'io_type': 'ADC', 'io_freq': '', 'ioid': '4', 'io_mode': 'IN'}}
Publish took 5ms
Check msg took 0ms
Loop end: Total time 2ms
Loop start: Free memory 180720, Time 10174

🛡️ Privacy by Design

All data stays local with no cloud dependencies or vendor lock-in. This Raspberry Pi Pico W firmware respects your network boundaries and integrates with Home Assistant using open MQTT protocols. You control the logic, data, and infrastructure.

🧩 Dependencies & Setup for Pico W IoT

The firmware requires these components for Raspberry Pi Pico W IoT projects:

  • SQL Database: Stores device metadata and GPIO configurations.
  • API Server: Manages device registration and configuration delivery.
  • MQTT Broker: Enables real-time communication with Home Assistant.

Setup files and schema:

🗃️ Database Schema & Samples for IoT

Devices Table

CREATE TABLE `devices` (
  `eid` int(11) NOT NULL AUTO_INCREMENT,
  `mac` varchar(50),
  `ip` varchar(15),
  `name` varchar(50),
  `device_type` varchar(50),
  `updated` datetime,
  `last_seen` datetime,
  `refrsh_int` int(11),
  `device_grp` varchar(50),
  `mqtt_input_topic` varchar(255),
  `mqtt_output_topic` varchar(255),
  `mqtt_acked_output_topic` varchar(255),
  PRIMARY KEY (`eid`)
);

Sample Entry

eid: 2
mac: 28:cd:c1:0c:63:ce
ip: 192.168.1.157
name: BedRoom Thermostat
device_type: pico_w
updated: 2025-09-01 15:31:41
last_seen: 2025-09-23 18:39:21
refrsh_int: 5
device_grp: HVAC
mqtt_input_topic: hvac/bedroom/inputs
mqtt_output_topic: hvac/bedroom/outputs
mqtt_acked_output_topic: hvac/bedroom/outputs/acked

Device IO Config Table

CREATE TABLE `device_io_config` (
  `eid` int(11) NOT NULL AUTO_INCREMENT,
  `device_id` int(11),
  `ioid` varchar(10),
  `io_name` varchar(50),
  `io_description` varchar(255),
  `io_type` varchar(20),
  `io_mode` varchar(10),
  `updated` datetime,
  PRIMARY KEY (`eid`)
);

Sample Entries

eid: 3
device_id: 2
ioid: 25
io_name: LED
io_description: LED
io_type: LED
io_mode: OUT
updated: 2025-08-01 17:23:40

eid: 4
device_id: 2
ioid: 4
io_name: Internal Temperature
io_description: Internal Temperature
io_type: ADC
io_mode: IN
updated: 2025-08-01 17:23:40

eid: 5
device_id: 2
ioid: 22
io_name: Ambient Temperature
io_description: Ambient Temperature
io_type: DS18x20
io_mode: IN
updated: 2025-08-15 16:54:45
Raspberry Pi Pico W IoT database schema

🏡 Home Assistant Integration with Pico W

Using MQTT and REST APIs, the Raspberry Pi Pico W becomes a fully compatible Home Assistant node. You can:

  • Display sensor data in dashboards
  • Trigger automations based on input states
  • Send output commands via scripts or UI
  • Receive acknowledgments for output actions

This makes the Pico W a low-cost, transparent alternative to commercial IoT devices.

🚀 Getting Started with Pico W IoT

Step 1: Flash Firmware

Flash main.py to your Raspberry Pi Pico W to enable IoT functionality.

Step 2: Set Up API and Database

Configure the API server and SQL database using the provided files.

Step 3: Connect to Wi-Fi and MQTT

Establish Wi-Fi and MQTT broker connections for real-time communication.

Step 4: Install MQTT Client

  • Create a folder named umqtt in the /lib directory on your Pico W.
  • Copy simple.py (and optionally robust.py) into /lib/umqtt/.
  • Verify firmware includes: from umqtt.simple import MQTTClient.

Step 5: Register Device

Register the device with the API to begin automating.

Need help? Visit Homatica’s contact page or check our blog for IoT tutorials.

🌱 Homatica’s Philosophy

This project reflects Homatica’s ethos: build with intention, clarity, and respect for privacy. Using open protocols and reproducible logic, you control your home automation.

❓ FAQ: Common Pico W IoT Questions

How do I troubleshoot Wi-Fi connection issues?

Check your SSID/password in config.yaml, ensure signal strength, and review the firmware log for errors.

Can I use this firmware with other IoT platforms?

Yes, any platform supporting MQTT (e.g., Node-RED) can integrate with this firmware.

What GPIO pins are supported?

The firmware supports all Pico W GPIO pins, configurable via the database for inputs (e.g., ADC, sensors) or outputs (e.g., LEDs, relays).