Skip to content

Instantly share code, notes, and snippets.

@topshed
Last active February 24, 2023 17:43
Show Gist options
  • Save topshed/f88d0b293ea68e3fb0f7d52865f2a012 to your computer and use it in GitHub Desktop.
Save topshed/f88d0b293ea68e3fb0f7d52865f2a012 to your computer and use it in GitHub Desktop.

Build an IOT sensor with Raspberry Pi Pico W

1. Plug the USB cable into the Pico W and your computer

4Npy-pico-top-plug VPVN-plug-in-pico

2. Open the Thonny Python editor on your computer

  • Look at the text in the bottom right-hand corner of the Thonny editor. It will show you the version of Python that is being used.

  • If it does not say ‘MicroPython (Raspberry Pi Pico)’ there, then click on the text and select ‘MicroPython (Raspberry Pi Pico)’ from the options.

thonny

3. Test your Pico W

  • Use the instructions here to test your Pico W.

  • Now type this code into a new program:

from picozero import pico_temp_sensor
from time import sleep
for _ in range(100):
    print(pico_temp_sensor.temp)
    sleep(1)
  • Click on View -> Plotter in Thonny and you should see the readings from the temperature sensor displayed. Warm up the Pico W with your hands and watch the plot change.

Snip20230223_3

4. Build your IOT sensor

  • Now open this project guide. You can skip to Step 3 ("Getting started with your Raspberry Pi Pico W").

  • Use the password rocksrocks to connect to the CDKU wifi network.

  • Follow the rest of the guide to create a web-server on your Pico W and use it to take a temperature reading and control the LED.

5. What else can you add to your Pico?

  • Take a look at some of the examples here. You can reproduce the circuits on a breadboard if you wish.
  • How about adding an RGB LED and changing the colour using buttons on your web-page?
  • Have a look at the examples in the picozero documentation.
  • Create a light sensor:

pico_ldr_bb

Here is some simple code to take a light reading. Can you display that value on your webpage? How about triggering an LED to light up when it gets dark?

from picozero import Pot

ldr = Pot(26)

print(ldr.value*1000)
@topshed
Copy link
Author

topshed commented Feb 23, 2023

thonny-select-interpreter

@topshed
Copy link
Author

topshed commented Feb 23, 2023

Snip20230223_3

@topshed
Copy link
Author

topshed commented Feb 23, 2023

4Npy-pico-top-plug
VPVN-plug-in-pico

@topshed
Copy link
Author

topshed commented Feb 24, 2023

pico_ldr_bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment