GithubHelp home page GithubHelp logo

pico-pwm-audio's Introduction

pico-pwm-audio

Raspberry Pi Pico PWM Audio Project

This code goes with a YouTube video which demonstrates PWM audio out with a simple cicruit on a raspberry pi pico.

Raspberry Pi Pico Audio Output

Building

Sync

git clone https://github.com/rgrosset/pico-pwm-audio.git

Make

Build project using cmake. This requires Raspberry Pi Pico C/C++ SDK to be installed.

mkdir build
cd build
cmake ..
make

Then copy pico-pwm-audio.uf2 to your Raspberry Pi Pico!

The Circuit

The circuit is based on the reference design from the raspberry-pi-foundation. We will just need one channel and the connector, as well as the logic buffer, is up to you.

circuit-diagram

You will need:

  • 1.8 kΩ resistor
  • 220 Ω resistor
  • 100 Ω resistor
  • 100 nF capacitor
  • 47 µF capacitor
  • an Audiojack

Using the Audito Converter Notebook.

The conventer is a Jupyter Notebook so you need to install Jupyter Notebooks for this to work. These instructions work on MacOS and Linux. For Windows the proess is the same simply follow instructions to install Python and related items for that platform.

Installing

  • First you need a working install of Python preferably a 3.x verson. To install python if you don't have it already go here https://www.python.org/downloads/

  • Second you need pip which is the python package manager, install this using the following

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
  • Install the notebook dependancies. These are the python libraries the notebook needs to run.
pip install soundfile 
pip install matplotlib
pip install samplerate
  • Next you need to install Jupyter Notebooks you can find instructions and many ways to install here https://jupyter.org/install my favoured way to do this is simply
pip install notebook

Usage guide

Launch the notebook user interface by issueing the command below in the same folder as this project. This will open the Jupyter user interface. Open the notebook file in the user interface.

jupyter notebook

The notebook itself is fairly self explanatory. Run each cell in order using the run buttons in the UI. The final cell will create a data array that you can copy and paste into your project. The notebook is configured to convert just about any WAV file to a mono 11Khz data which you can then use in your projects!

Have fun! Let me know if you have any feedback or questions.

pico-pwm-audio's People

Contributors

mrsmoer avatar rgrosset avatar robin7g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pico-pwm-audio's Issues

Any chance you could upload the pico-pwm-audio.uf2

... so I can check my circuit works, before battling with getting the compiler working. I usually use the Arduino IDE, so I don't have the Raspberry Pi Pico SDK installed. If it works, I could try and port it to the Arduino IDE. Thanks.

Won't compile sample larger then 15 seconds at 11 mhz

I'm trying to compile with a sample.h file that is larger then 15 seconds at 11 mhz.
I keep getting this message when trying to compile the file for my pi pico.
I don't know cmake, or make very well. I have compile c/c++ but it's been a long time.

I get a message stating that there is not enough space in RAM but don't know where I would go to increase the reserved ram so I can just get the program compiled. I tried to increase the RAM section in the pico-pwm-audio.map file but it doesn't seem to make a difference.

Maybe I need to run cmake again after I adjust the map file? I'm not sure and just home I can get more then 15 seconds of audio to play. If this is the max amount of time, that is all I need to know.

Let me know if you need more information regarding my issue.

Thank you in advance for any assistance.

Wrap vs. levels in sample data

Thanks a lot for sharing this project!

You set the PWM wrap to 250 but amplitude levels in e.g. sample.h go up to 256, doesn't that mean that you slightly amplify the sound (by 256/250) and then clip the loudest parts of the waveform?

See this chart for the specs:

image

IIUC
wrap = top counter level = 250
level = end of duty cycle

so, that for all values >= 250 you get a full duty cycle / voltage.

Using the converter

Hello Robin,

Could you add a few instructions on how to use the converter please?

Thanks

CMakeLists.txt has hardcoded location

Hi, thanks for your example file for the PWM audio and supporting files. this has been a great help so far

1 minor snafu: your CMakeLists.txt file has your SDK location hardcoded, preventing cmake from running for everyone without a user called robin ;) . A quick '#' solved the issue

It was a quick and easy fix for myself, but might catch some newer users trying to build the software

Finally, you propose the clone git@github link for downloading the repository. I would recommend changing that to the https://github version as otherwise the clone command will fail for users without an account on most clean build environments.

Playing 16 bit audio using this sample

Hi could you please let me know how you chose the value 250 for this function in pico-pwm-audio.c
pwm_config_set_wrap(&config, 250);
I can understand how your clock divider and other values ultimately set a sampling frequency of 11000 Hz for the clock frequency you have chosen, but I wanted to understand how you chose those specific values.

The reason I ask this is because I want to take audio input from a "line-out" audio signal attached to the ADC and play it back in PWM in real time. I don't have experience with generating audio using PWM and your code is also serving as a tutorial for me. The ADC audio samples are 12-bits and I am storing them in a uint16 and the ADC values that I am getting are in the range 2030 to 2090. Since they are all bigger than 250, using your code as it is now and just using my ADC data as input for the PWM output does not generate any PWM signal. I have tried changing the 12-bits of ADC to 8 [doing something like this in pwm_interrupt_handler()]
pwm_set_gpio_level(AUDIO_PIN, (WAV_DATA[wav_position>>3]) >>4);
but that also adds a lot of noise to the output sound, so I think I may be going about this the wrong way.

So I am guessing it is better if I do not loose any bits of my audio samples and find out a way of playing them as 16 bit audio. Could you give me some ideas on how to do this, or at least what is the proper way to choose the pwm_config_set_wrap value, and the number of shifts in WAV_DATA[wav_position>>3]?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.