Raspberry Pi Pico Audio output

  Рет қаралды 38,155

Robin Grosset

Robin Grosset

Күн бұрын

Пікірлер: 64
@hellcoreproductions
@hellcoreproductions 3 жыл бұрын
Nice, going to have a play and try some bytebeat streaming. That blog is gold.
@PATRIK67KALLBACK
@PATRIK67KALLBACK 2 жыл бұрын
Cool project! Thank you for showing.
@ogmrneat
@ogmrneat 2 жыл бұрын
Amazing tutorial! Thank you for posting :-)
@HighfireX
@HighfireX 3 жыл бұрын
Thanks to your work, I'm learning quite a bit about how to get audio to work on a pico. I found directly plugging a speaker to Pin 28 (PWM) / Ground gave a larger boost in volume at the cost of the audio artifacts. I want to follow your circuit if I decide to line out / amplify the speaker.
@kahnzo
@kahnzo 3 жыл бұрын
Oh, man, this is cool!
@WACkZerden
@WACkZerden Жыл бұрын
Thanks for sharing. great video. it sounds pretty cool too
@Sam-tg4ii
@Sam-tg4ii 2 жыл бұрын
1:10 so pico has a built-in speaker? Where is the sound coming from exactly?
@plasmamac
@plasmamac 3 жыл бұрын
immedealatly bought a pico ! thx for the explanation
@mmikse3
@mmikse3 3 жыл бұрын
I'm sorry...
@dlese9641
@dlese9641 3 жыл бұрын
great lesson ! works also under the Arduino IDE. thx
@S-MKim
@S-MKim 3 жыл бұрын
HI Robin, Amazing sound. Could you do it similarly for the sound input from a microphone, without using a dedicated sound card? Thanks in advance for your tip.
@zappyad
@zappyad 3 жыл бұрын
Is there an explanation anywhere about what the hardware components are actually doing? Like why have each resistor / capacitor and what happens if you take them away? I can follow the software explanation to understand what is going on there, but the circuit side of it just 'appears' and it would be great to get an understanding of what is happening. Or is that a case of 'learn electronics and then it is obvious?' :)
@robingrosset6941
@robingrosset6941 3 жыл бұрын
The Pico output is fed into an analogue filter called an RC filter (Low Pass Filter) this is the 220 ohm resistor and 100nF capacitor. then you have the 100 ohm resistor which effective acts as a voltage divider to get the voltage down to 1v ish for the audio levels. You could leave out the next bit too if you want and just have 3 components. The next capacitor 47 uF a.c. couples the analog signal in the audible frequency range. which we can then connected to an amp or headphones. The a.c. coupling is the last stage and you can omit it and it still works.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
This is based on the original Raspberry Pi Foundation hardware design circuit here datasheets.raspberrypi.org/rp2040/hardware-design-with-rp2040.pdf page 22 has the audio circuit and an explanation. It's not as detailed as above. The other place to look for background is this link. Which is a written blog describing RC filter for PWM audio gregchadwick.co.uk/blog/playing-with-the-pico-pt3/
@zappyad
@zappyad 3 жыл бұрын
@@robingrosset6941 Thanks for the extra information. I was able to look up low pass / high pass filter online and now understand how it works. I'm even going to have a go at building it!👍
@kennethcate3263
@kennethcate3263 3 жыл бұрын
Please fix the link for "Audio jack breakout board", part of it ended up as plain text.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
link in description fixed, here it is here too www.amazon.ca/Breakout-Headset-Stereo-Socket-Extension/dp/B0183KF5KI
@AleksandrIvin
@AleksandrIvin 2 жыл бұрын
Cool project! How do you think, would this audio scheme with capacitors and resistors work for ATtiny chips?
@robingrosset6941
@robingrosset6941 2 жыл бұрын
Yes I think it will. Attiny chips clock up to about 20MHz with tiny RAM 2K, 4K or 8k. You can certainly generate various wave forms and they support PWM, trouble will be getting more than a fraction of a second of sampled audio from RAM. Also single core so will need tight code and maybe an SD card? There are enough pins to have SD card and PWM audio.
@AleksandrIvin
@AleksandrIvin 2 жыл бұрын
@@robingrosset6941 Thank you. I tried to use PWM as simple beeper for my locomotive. It even works. But using another timer for IR receiving and detecting NEC contorol signals, something goes wrong with sound. I think to try using your way :)
@robingrosset6941
@robingrosset6941 2 жыл бұрын
@@AleksandrIvin The IR receiver will be time sensitive and the PWM sound generation is too... so you would have to do something to slice time between them.
@trichlingable
@trichlingable 2 жыл бұрын
Hey, thanks for the great tutorial. I try to output audio sampled from a microphone trhoug pwm, and i need to build the filter you added behind the pwm output. I am not really an expert in this, but are you sure about the 47uF capaditor? I can not even find one in ceramic and they are not included in the common sortiments. Is is it more like 4.7uF, becuase these semm to be much more common. Just try to buy the right things :-)
@takiktos1265
@takiktos1265 10 ай бұрын
You can use electrolite capacitor. Just make sure polarity is good
@_..---
@_..--- 3 жыл бұрын
THATS_COOL.H, I wonder if it can do FM transmission since the overclock can go that high.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
176MHz is not that high either someone managed to overclock a Pico to 270 MHz ! www.raspberrypi.org/forums/viewtopic.php?t=301902&p=1810769
@jeroentaverne8232
@jeroentaverne8232 Жыл бұрын
Why do you need to set the same PWM duty cycle 8 times for every audio sample? Overclocking is not required when you set it only one time per sample I guess.
@AbdullahKahramanPhD
@AbdullahKahramanPhD 3 жыл бұрын
Could this be done via DMA?
@patrickworking3065
@patrickworking3065 3 жыл бұрын
Wow, really interesting project. I am looking to borrow this design for a project I am currently developing. I'm curious what the buffer is doing in the original schematic and why you could just remove it and still get good results.
@spinal_cord
@spinal_cord Жыл бұрын
I realise this is a couple of years old now, but is it possible to play 16bit samples using pwm with this code?
@robingrosset6941
@robingrosset6941 11 ай бұрын
Yes you can. So inside the interrupt handler there is a call to a function pwm_set_gpio_level (uint gpio, uint16_t level). the second paramter is the level and this is from the WAV_DATA so you can setup the WAV_DATA to be 16 bit integers uint_16_t instead of 8 bit . It should work fine. Do you have a 16 bit sample you want to play as 16 bit or is it that you want to covert the 16 bit sample to 8 bit? The reason for this being 8 bit to begin with was to reduce the memory size needed to store the WAV data and make it more compact. But you can use 16 bit its just your sample memory with twice as big.
@spinal_cord
@spinal_cord 11 ай бұрын
​@@robingrosset6941 I tried this sort of thing... int offset = wav_position>>3; uint16_t c = (WAV_DATA[offset + 1]
@spinal_cord
@spinal_cord 11 ай бұрын
After experimenting a bit, it seems impossible to have any better than 12bit pwm for audio, anything higher makes too much noise, it seems it can't do the timing properly.@@robingrosset6941
@МихаилШакаев-ю1г
@МихаилШакаев-ю1г 7 ай бұрын
@@robingrosset6941 Hello! Tell me pls, it's will be a background noise if I connect pin0 directly to the audio out? I'm makin a pocket sample-based synth on RP2040-Plus by Waveshare electronics (pico rp2040 clone) and Mozzy library. Now pin0 connected directly to the audio out, and it's worked for arduino nano, but with rp2040 it's bring a background noise, like an white noise. I try to understand, will this scheme resolve my issue, or I need to look further. Thank you!
@M0XYM
@M0XYM 3 жыл бұрын
Hi, do you think this could be done in micropython? I don't suppose you have tried?
@kevinwalters2076
@kevinwalters2076 3 жыл бұрын
I spend more time in CircuitPython which can do PWM audio, I've not looked at RP2040 MicroPython for this. The 6.2.0-beta.4 release was a touch buggy for wav playback under certain conditions but I'm sure it'll be fixed soon. Several examples of audio on my channel with links to source code in the description.
@iC3mdbN
@iC3mdbN 3 жыл бұрын
Have you tried in in Micropython, does it work?
@kevinwalters2076
@kevinwalters2076 3 жыл бұрын
@@iC3mdbN Haven't tried sound samples there so far, I spend most of my time in CircuitPython unless I'm coding for the BBC micro:bit.
@peterguthrie9924
@peterguthrie9924 3 жыл бұрын
Why are you using a TRRS audio jack is it purely for the convenience of the breakout board?
@robingrosset6941
@robingrosset6941 3 жыл бұрын
Yes its just an easy way to wire up an audit jack on a breadboard.
@peterguthrie9924
@peterguthrie9924 3 жыл бұрын
@@robingrosset6941 I'm a bit new to Python and programming but I have a raspberry pi 3 with the code: if GPIO.input os.system('omxplayer -o local /file1.wav &') I'm just not sure how to modify this for the pico and to this circuit you created.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
@@peterguthrie9924 did you get the circuit with the pico to run the demo code and make sound? The code here that you have pasted takes a wav file and plays but it requires the Raspberry Pi Rspbian Operating System to work, this won’t work on a pico as it has no operating. You have to use the pico SDK or libraries to do things. To play your wav file you need to convert it to from a wav file to a header file using the python code in the example I gave. I hope this helps. Let me know which part is not working for you.
@peterguthrie9924
@peterguthrie9924 3 жыл бұрын
@@robingrosset6941 I've only built my button pushing project with pi 3b so far, waiting on parts for the pico.
@peterguthrie9924
@peterguthrie9924 3 жыл бұрын
@Robin Grosset my ultimate goal is to have a board that has 15 input push buttons which when each is pushed play a different sound file ("Help required in ...Department). So far I have working code for pi3 but ultimately using pico would a cool way to do it integrating it all on one PCB.
@cheapnoiseinthehouse5578
@cheapnoiseinthehouse5578 2 жыл бұрын
Hi. I would like to create a sampling keyboard a little bit like the Casio SK-1. I would like to have at least 4 voices. The thing is I'm blind so coding the Pico will be impossible so I wondered if some one can help me with this.
@JeremyCook
@JeremyCook 2 жыл бұрын
As the clip says, "that's cool." Nice work! Your audio circuit is a form of band pass filter, correct? If I wanted to use this code with the Arduino IDE, where would I get the needed libraries, e.g. stdio.h
@mrlobbyist2061
@mrlobbyist2061 2 жыл бұрын
Hey Robin, I'm working on implementing this code for continuous outdoor-garden-area usage. Is it fine to overclock the pico with a PIR sensor and your code running side by side at outside temps reaching 35 Celsius? Either way, is there a way to not overclock it and use it at 22Khz instead of 44Khz?
@grantkobe9
@grantkobe9 3 жыл бұрын
hello, can you tell me what is name of the audio out ? i am beginner . so i know a little. i can buy the capacitor, resistance, but i do not know how to got the audio output like you show in the video. i want try this way in your video. thanks in advance.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
Here is a link to a breakout board for a 3.5mm audio jack. This is the jack I was using. www.sparkfun.com/products/11570
@grantkobe9
@grantkobe9 3 жыл бұрын
@@robingrosset6941 thank you very much :)
@nathancusson467
@nathancusson467 Жыл бұрын
Hey, I am building a Raspberry Pico Gameboy Emulator, would this solution work for me? I am using Pico-GB from YouMakeTech
@olafschermann1592
@olafschermann1592 9 ай бұрын
Awesome easy
@sCealt
@sCealt 3 жыл бұрын
awesome :) would love to know what would happen if you had a function that shifts and rearranges the content of header files :)
@yiqiujia4587
@yiqiujia4587 3 жыл бұрын
Very good, can you record and send it?
@BI1LWM
@BI1LWM 3 жыл бұрын
will this work on raspberry pi 4b?
@skellious
@skellious 3 жыл бұрын
very nice :)
@robingrosset6941
@robingrosset6941 3 жыл бұрын
Thanks! :)
@markday3145
@markday3145 3 жыл бұрын
What is the PWM frequency relative to the sample frequency? I image you want that to be much higher, so that you get multiple cycles per sample.
@robingrosset6941
@robingrosset6941 3 жыл бұрын
Yeah much higher at least 2x the sample frequency is normal. I had it at ~80kHz for an 11kHz sample. Making it super high also helps avoid hearing artifacts from it. Human hearing can hear 20kHz so I went with 4x that. The code is capable of 41kHz CD quality output with that too.
@suki4410
@suki4410 4 ай бұрын
@@robingrosset6941 Only children are able to hear 20khz.
@manuelr7121
@manuelr7121 2 жыл бұрын
this is so hard to do lol
Raspberry Pi Pico 2: a RISC-V bet!
8:05
Jeff Geerling
Рет қаралды 313 М.
Raspberry Pi Pico VGA video output using only resistors
11:10
Robin Grosset
Рет қаралды 93 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
The Raspberry Pi Pico WAS Overrated! But that changed!
10:18
GreatScott!
Рет қаралды 625 М.
What is VGA and How to Use it With a Raspberry Pi Pico
18:28
Gary Explains
Рет қаралды 57 М.
Pi Pico + KMK = the perfect combo for Custom Keyboards
7:41
Jan Lunge
Рет қаралды 84 М.
Raspberry Pi 500: Best Linux Keyboard PC?
23:23
ExplainingComputers
Рет қаралды 80 М.
this tiny computer is changing my life
8:50
afk steph
Рет қаралды 16 М.
R-Pi Pico 2: 10 Things You Must Know Before Buy!
6:50
ToP Projects Compilation
Рет қаралды 25 М.
I Made a Tool to Debloat Windows in 2 Clicks
15:01
TotallyNotK0
Рет қаралды 278 М.