Template: Sound Sensor Pico Guide

From Waveshare Wiki
Jump to: navigation, search

Configure Pico

MicroPython and C examples are provided for this sensor, to use it with Pico, you need to first flash firmware to the Pico according to the example.
Please refer to the guides of Raspberry Pi about how to flash the firmware. We recommend you use the firmware from the Demo codes archive.

Hardware connection

Hardware Connection
Sound Pico Description
VCC 3.3V Power input
GND GND Ground
AOUT GP26 Analog data output
DOUT GP22 Digital data output

Examples

Download the example

Open the terminal of Raspberry Pi and run the following command to download the example:

sudo apt-get install p7zip-full
cd ~
sudo wget  https://files.waveshare.com/upload/b/bc/Sound-Sensor-code.7z
7z x Sound-Sensor-code.7z -o./Sound-Sensor-code
cd ~/Sound-Sensor-code
cd Pico/c/build/

C

  • The following tutorial is for operation on Raspberry Pi, but due to the multi-platform and portable nature of CMake, it can also be compiled successfully on a PC, but the operation is slightly different and needs to be judged by the user.

To compile, make sure that in the c directory:

cd ~/Sound-Sensor-code/Pico/c/

Create and enter the build directory in the folder, and add the SDK.
Where ... /... /pico-sdk is the directory of your SDK.
Our sample application has a build in it, so go directly to it.

cd build
export PICO_SDK_PATH=../../pico-sdk
(Note: Be sure to write the right path to your own SDK)

Execute cmake to automatically generate the Makefile file.

cmake ..

Execute make to generate the executable file, the first compilation time is longer.

make -j9

When the compilation is complete, the uf2 file will be generated.
Press and hold the button on the Pico board, connect the Pico to the USB port of the Raspberry Pi via the micro USB cable, and then release the button. Once connected, the Raspberry Pi will automatically recognize a removable disk (RPI-RP2), and copy the main.uf2 file from the build folder to the recognized removable disk (RPI-RP2).

cp main.uf2 /media/pi/RPI-RP2/

Python examples

In Windows PC
  • Hold the BOOTSET button of the PICO board, and connect the Pico board to Raspberry Pi by USB cable
    • After connecting, release the button, and a portable disk (RPI-RP2) is recognized.
  • Copy the rp2-pico-20210418-v1.15.uf2 file to the portable disk (RPI-RP2).
  • Open the Thonny IDE (Please install the newest version that supports the Pico board or update).
  • Choose Tools -> Options -> Interpreter, and choose the Pico and the port.
Pico-lcd-0.96-img-config.png
  • Download the demo codes, unzip and find the MicroPython example.
  • Choose File -> Open -> Sound_Sensor.py and run it.
Pico-lcd-0.96-img-run.png
In Raspberry Pi
  • Flash the uf2 file to the Pico board just like in the Windows PC.
  • Open the Thonny IDE of Pi, make sure that it is the newest version, or update it.
  • Choose Tools -> Options... -> Interpreter.
    • Choose Pico and the Port.
Pico-lcd-0.96-img-config2.png
  • If your Thonny IDE cannot support the Pico board, you can update it and try again.
sudo apt upgrade thonny
  • Choose File -> Open... -> python/Sound_Sensor.py and run it.

Expected result

  • The indicator lights up when the microphone of the module is near the source and goes off when it is far from the sound source.
  • As the distance between the sensor and the sound source changes, the serial port output data changes accordingly.