Template: DHT11 Temperature-Humidity Sensor Pico Guide

From Waveshare Wiki
Jump to: navigation, search

Use with Raspberry Pico

Hardware Connection

Sensor Pico Description
VCC 3.3V Power input
GMD GND Power ground
DOUT GP15 Digital data output
DHT11-Temperature-Humidity-Pico 1.jpg

Download examples

Use Raspberry Pi as the host device. Open a terminal and run the following commands to download the example.

sudo apt-get install p7zip-full
cd ~
sudo wget  https://files.waveshare.com/upload/4/4a/Temperature-Humidity-Sensor-code.7z
7z x Temperature-Humidity-Sensor-code.7z -o./Temperature-Humidity-Sensor-code
cd ~/Temperature-Humidity-Sensor-code
cd Pico/c/build/

Examples

C codes

  • Go into the c directory.
cd ~/Temperature-Humidity-Sensor-code/Pico/c/build
  • Add the path of the SDK.
export PICO_SDK_PATH=../../pico-sdk
Note that if the path of your SDK is different, you need to modify the command and use the correct path to export.
  • Generate Makefile and build.
cmake ..
make -j9
  • After building, a uf2 file is generated.
  • Press and hold the button of Pico, connect it to Raspberry Pi then release the button.
  • Copy/Drag the uf2 file to the portable disk (RPI-RP2) recognized.
cp main.uf2 /media/pi/RPI-RP2/

Micropython codes

Use in Windows

  • 1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer through the Micro USB cable, and release the button after the computer recognizes a removable hard disk (RPI-RP2).
  • 2. Copy the Rp2-pico-20210418-v1.15 file in the python directory to the recognized removable disk (RPI-RP2).
  • 3. Open Thonny IDE (Note: Use the latest version of Thonny, otherwise there is no Pico support package, the latest version under Windows is v3.3.3).
  • 4. Click Tools -> Settings -> Interpreter, and select Pico and the corresponding port as shown in the figure.

Pico-lcd-0.96-img-config.png

  • 5. File -> Open -> the corresponding .py file, click to run, as shown in the following figure:

Pico-lcd-0.96-img-run.png

Use in Raspberry Pi

  • Flash the Micropython firmware first.
  • Open the Thonny IDE (Menu -> Programming -> Thonny Python IDE).
  • 【Optional】If the Thonny IDE in the Raspberry Pi is not the new version that supports Pico, please upgrade it first.
sudo apt upgrade thonny
  • Configure Interpreter, choose Tools->Options... -> Interpreter, choose MicroPython(Raspberry Pi Pico) and the ttyACM0 port.
400
  • Click File -> Open.. and browser the Micropython codes (Photo Interrupter Sensor.py) to run the codes.

Expected result

  • The humidity and temperature data are printed to the serial port.