This project demonstrates how to connect a Raspberry Pi Pico W to AWS IoT Core using MicroPython and MQTT.
- Hardware
- Raspberry Pi Pico W x1
- Push buttons x4
- Software
- AWS IoT Core
- MicroPython
- Thonny IDE
Using AWS IoT Core’s message broker, this setup enables secure message transmission between AWS IoT Core and the Pico W.
The application:
- Publishes button status to the
picow/button
topic when buttons are pressed or released. - Subscribes to the
pico/led
topic to control the Pico W’s onboard LED based on received messages (on
,off
,toggle
).
- Connect each button between the GND and GP3 pins on the Raspberry Pi Pico W.
-
Create an AWS Account and Access IoT Core
- Sign in to AWS, search for IoT Core, and open it.
-
Configure Policies
- Go to Security > Policies and create a policy to control access.
- Add the necessary policy actions, including the ability to publish and subscribe.
- AWS IoT Core Policies Documentation
-
Register Your Device
- Go to All devices > Things > Create thing to register your Pico W device.
- Name the thing and generate a new certificate for authentication.
- Download the certificates for later use.
-
Endpoint Configuration
- Under Settings, note the Endpoint URL, as it will be used to set up the MQTT connection.
-
Upload Certificate and Key Files
- In Thonny IDE, navigate to
View -> Files
and locate the AWS IoT Core certificate and key files you downloaded earlier. - Upload them to the Pico W using
Upload to /
.
- In Thonny IDE, navigate to
-
Update Code with AWS Information
- Use the AWS IoT Endpoint URL and certificate filenames in your MicroPython code to configure the MQTT client.
-
Download the mainAWS.py file
- Move to Raspberry Pico or prefered location in Computer and open in Thonny.
- Run script.