Loops mp3 and wav files, also generates coloured noise. A WS2812 LED can be configured as a night light.
The aim of this project is to use the Cytron Maker Pico board to create a noise generator that can be used at night, to aid sleep.
It is also an opportunity to demonstrate some of the features on the board. These include:
Used to hold the wav and mp3 files. Also used to persist the music and night light configuration data
A ping pong DMA is used to set the PWM levels in the GPs (GP18
, GP19
) connected to the audio jack on the board. This allows:
- Generation White, Pink and Brown (Red) noise
- Playing up to 3 separate mp3 and wav files from the SD card
All sounds are played through the audio jack on the board. Sounds loop continually until user intervention, either by changing the selection, or removing the power!
Cycle through the play options by pressing the on board button connected to GP20
The board is fitted with a single NeoPixel RGB LED (GP28
). This can be enabled to generate either Red, Orange, Yellow or White light. To cycle through the colours (plus off) press the button connected to GP20
, whilst holding down the PICO boot select button.
The intensity of the LED can be varied by pressing the buttons connected to GP21
(brighter) andGP22
(dimmer) whilst holding down the PICO boot select button.
The player will look for and play files named 1
, 2
and 3
in the root directory of the SD Card. Files can be either mp3
or wav
format. Mono or stereo files are supported.
Note: there should be no extension in the filename, the filename should consist of only a single digit in the range 1 to 3.
A selection of files to aid sleep can be found here
By default the volume level at the jack can be varied by use of the buttons connected to GP21
and GP22
. If the attached speakers have volume control then removing the definition of VOLUME
in picosounds.c
will lock the volume at 100%.
If this is done the intensity of the LED can be varied using the buttons connected to GP21
and GP22
without pressing the PICO boot select button.
Install the Pico SDK. This is described in the Getting Started Guide
git clone --recursive https://github.com/ikjordan/picosounds.git
cd picosounds
mkdir build
cd build
cmake ..
make
PWM is not disabled when a break point is reached. With the code stopped in the debugger, the interrupt routine to reconfigure the DMA will not execute, resulting in random sound being generated.
The code is configured so that an off-board button connected to GP7
can be used to disable the PWM to avoid the noise generation.
Two debug configurations are included in launch.json'
For use with the Raspberry Pi Debug Probe
For use with Raspberry Pi4 or earlier, with SWD connected through GPIO 24 and 25
The code uses two submodules:
- FatFS: https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico
- Mp3: https://github.com/ikjordan/picomp3lib
The volume and play state is stored on the sd card, and restored when the device is restarted.
The following sampling rates are supported:
8000 kHz
11000 kHz
11025 kHz
12000 kHz
16000 kHz
22000 kHz
22050 kHz
24000 kHz
32000 kHz
44000 kHz
44100 kHz
48000 kHz
MP3 ABR and CBR is supported, with bit rates up to 320kBit/s.
Sound is played with 12 bit accuracy. To support this at up to 48kHz sampling rates, the pico is overclocked to 180MHz