Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Bare Bones Sound Demo for Pico
Author | Message | ||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
After playing with Colour Maximite MMBasic a year or so ago, I finally got around to buying a couple of RPi Picos and installing the most recent excellent version of MMBasic. Blinking LEDs is pretty old at this point, so I tried demonstrating sounds. The manual (and others) indicate that a low-pass filter is needed, and rather than scrounge for coils and caps in my junk box, I just connected a small (4 cm) crappy speaker to pins GP0 and GP1 using jumper cables. It worked! I have a music background, so I wanted to test the (alleged) floating-point specification of frequencies in the PLAY TONE command to see if I could get "equal-tempered" tuning - that worked too! Here's the program. Enjoy! REM **************************************************************** REM ** Audio Demonstration on Raspberry Pi Pico with MMBasic ** REM ** Steve Johnson March 10, 2023 Newbury Park, California ** REM ** ** REM ** Requires running the following from command line once: ** REM ** OPTION AUDIO GP0, GP1 and OPTION POWER PWM ** REM ** Connect speaker leads to GP0 and GP1. No GND connection. ** REM **************************************************************** REM These data statements contain the frequencies for well-tuned notes DATA 32.70, 65.41, 130.81, 261.63, 523.25, 1046.50, 2093.00, 4186.01 'C nat DATA 34.65, 69.30, 138.59, 277.18, 554.37, 1108.73, 2217.46, 4434.92 'C# DATA 36.71, 73.42, 146.83, 293.66, 587.33, 1174.66, 2349.32, 4698.64 'D nat DATA 38.89, 77.78, 155.56, 311.13, 622.25, 1244.51, 2489.02, 4978.03 'D# DATA 41.20, 82.41, 164.81, 329.63, 659.26, 1318.51, 2637.02, 5274.04 'E nat DATA 43.65, 87.31, 174.61, 349.23, 698.46, 1396.91, 2793.83, 5587.65 'F nat DATA 46.25, 92.50, 185.00, 369.99, 739.99, 1479.98, 2959.96, 5919.91 'F# DATA 49.00, 98.00, 196.00, 392.00, 783.99, 1567.98, 3135.96, 6271.93 'G nat DATA 51.91, 103.83, 207.65, 415.30, 830.61, 1661.22, 3322.44, 6644.88 'G# DATA 55.00, 110.00, 220.00, 440.00, 880.00, 1760.00, 3520.00, 7040.00 'A nat DATA 58.27, 116.54, 233.08, 466.16, 932.33, 1864.66, 3729.31, 7458.62 'A# DATA 61.74, 123.47, 246.94, 493.88, 987.77, 1975.53, 3951.07, 7902.13 'B nat DIM FLOAT Tuning(8, 12) DIM INTEGER Octave, Note, Delay=50 FOR Note=1 To 12 : FOR Octave=1 To 8 Read Tuning(Octave, Note) NEXT Octave : NEXT Note DO FOR Octave = 4 To 8 : FOR Note = 1 To 12 PLAY TONE Tuning(Octave, Note), Tuning(12-Octave, 13-Note) : PAUSE Delay NEXT Note : NEXT Octave LOOP PLAY STOP Edited 2023-03-11 11:40 by NPHighview Live in the Future. It's Just Starting Now! |
||||
hitsware2 Guru Joined: 03/08/2019 Location: United StatesPosts: 713 |
PLAY SOUND works nicely also ... my site |
||||
Revlac Guru Joined: 31/12/2016 Location: AustraliaPosts: 1026 |
Great, this is something I would like to play with, perhaps a steam whistle sound and diesel loco horn sound. Cheers Aaron Off The Grid |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
DO NOT DO THIS... ... unless you are using a high impedance speaker or you insert a 220R resistor in series with an 8R speaker. There is a danger of overloading the IO pins and even exceeding the maximum IO current for the RP2040, causing damage to your PicoMite as an 8R load is *way* out of spec. The volume will be lower with the resistor, but it will bring peace of mind. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4256 |
The pico can play any sound recorded as a .WAV file from sd card. Even high quality CD music. PicomiteVGA PETSCII ROBOTS |
||||
PilotPirx Regular Member Joined: 03/11/2020 Location: GermanyPosts: 69 |
The low impedance speaker and inductive load can destroy your pico output. As Mixtel90 already said: not without protective resistor. Or better a high impedance speaker or use an amplifier. |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Thanks, everyone, for your sage advice and cautions. Fortunately, the speaker I'm using is a 200+ ohm membrane speaker that is working quite happily connected directly. My main intent was to ascertain the necessity for a low-pass filter, and I'm satisfied that, for the PLAY TONE statement at least, it's not necessary. In a continuation of my experimenting, I put together a variation on the above theme, using the two-sound combination of the PLAY TONE statement to achieve a functional DTMF dialer. At least in the U.S., just holding the mouthpiece of a desk phone over the speaker is enough to dial the phone! Listing below (that's the phone number for Directory Assistance in our area code, if such a thing still exists). My coding style yearns for the equivalent of C structs, but then this wouldn't be a dialect of BASIC. On a related note, I have been watching the excellent Cornell University course on the Raspberry Pi Pico 2040, and have a somewhat better understanding of how Geoff and Peter are working their miracles. However, sufficiently advanced technology is still indistinguishable from magic. REM *********************************************************************** REM ** ** REM ** DTMF Demonstration on Raspberry Pi Pico with MMBasic ** REM ** ** REM ** Steve Johnson March 12, 2023 Newbury Park, California ** REM ** ** REM ** https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling ** REM ** Requires running the following from command line once: ** REM ** OPTION AUDIO GP0, GP1 and OPTION POWER PWM ** REM ** Connect speaker leads to GP0 and GP1. No GND connection ** REM ** Hold the speaker near the phone mouthpiece. ** REM *********************************************************************** REM These data contain the frequencies for the DTMF tones DATA 697, 770, 852, 941, 1209, 1336, 1477, 1633 REM These data contain the combination indices for pairs of tones REM from 0-9, *, #, A, B, C, and D DATA "0", 4, 6, "1", 1, 5, "2", 1, 6, "3", 1, 7, "4", 2, 5 DATA "5", 2, 6, "6", 2, 7, "7", 3, 5, "8", 3, 6, "9", 3, 7 DATA "*", 4, 5, "#", 4, 7 DATA "A", 1, 8, "B", 2, 8, “C", 3, 8, "D", 4, 8 DIM FLOAT Tones(8), Tone DIM INTEGER Row, Column, Dtmf(16,2), Code DIM INTEGER Digit_Dur=175, Digit_Pause=50, Comma_Pause=500, Dash_Pause=100 DIM STRING Symbol(16), Phone_Number, Digit DIM INTEGER Debug = 0 SUB Load_DTMF FOR Tone = 1 To 8 : Read Tones(Tone) : NEXT Tone FOR Code = 1 To 16 Read Symbol(Code), Dtmf(Code, 1), Dtmf(Code, 2) NEXT Code END SUB SUB Dial_Phone Phone_Number As STRING IF Debug=1 THEN PRINT "Dialing "; Phone_Number FOR i = 1 To Len(Phone_Number) Dial_Digit Mid$(Phone_Number, i, 1) NEXT i END SUB SUB Dial_Digit Digit As STRING IF Digit = "," THEN PAUSE Comma_Pause ELSEIF Digit = "-" THEN PAUSE Dash_Pause ELSE FOR Code = 1 To 16 IF Digit = Symbol(Code) THEN Row = Dtmf(Code,1) : Column = Dtmf(Code,2) IF Debug=1 THEN PRINT Digit; Row; " ("; Tones(Row); "), "; PRINT Column;" ("; Tones(Column);")" ENDIF PLAY TONE Tones(Row), Tones(Column) : PAUSE Digit_Dur PLAY STOP : PAUSE Digit_Pause ENDIF NEXT Code ENDIF END SUB REM ************************************************************************ REM ** Main Loop ** REM ************************************************************************ Load_DTMF Dial_Phone "1,805-555-1212" Edited 2023-03-13 10:42 by NPHighview Live in the Future. It's Just Starting Now! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6814 |
Even at 200R you are exceeding the maximum load. You are driving the speaker in push-pull so there could up to 6.6V across it. That gives an output current of 33mA. The outputs from the RP2040 sag under load, but their maximum usable current is 12mA from any one pin. That's the current you should be trying not to exceed and would imply a minimum load of 550R. Even if you use a single output to ground that speaker will draw 16.5mA. The Pico has poor output current capability. The Arduino range are far better in this respect. You are probably getting away with this only because the two outputs are the only ones in use so the chip may be able to handle the excess dissipation. It's not a "good thing " to push the manufacturer's spec too far or the magic smoke can escape. It's possible that the sagging output voltage is also what is (for the moment anyway) protecting the outputs against back-emf spikes from the inductive coil of the speker. Because of the voltage drop on the outputs as the load increases you are probably not getting much (if any) more output from two outputs than you would from one to GND. A single output and a very simple one-transistor amplifier would be the way to go. That would allow you to use a higher voltage across the speaker and get more output. I like this "quick and dirty" approach to speaker driving, but it has problems. :( Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Print this page |