Testing Audio Ports
Welcome to the Audio Port Test
In this lab, you will test your left and right audio connections by sending a tone to each one. This makes sure both channels are wired correctly before you try playing real audio files.
What This Lab Does
This program sends a 1,000 Hz (1 kHz) square wave to the left audio channel for one second, then to the right audio channel for one second. If you hear a beep from each side, your wiring is correct.
The Test Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
What Each Section Does
AUDIO_LEFT_PIN = 18— the GPIO pin number for the left audio channel. Change this to match your wiring.AUDIO_RIGHT_PIN = 19— the GPIO pin number for the right audio channel.left_speaker = PWM(Pin(AUDIO_LEFT_PIN))— creates a PWM object on the left pin.left_speaker.duty_u16(1000)— turns the tone on. The value 1000 gives a low but audible volume.left_speaker.freq(1000)— sets the pitch to 1,000 Hz.sleep(1)— keeps the tone playing for 1 second.left_speaker.duty_u16(0)— silences the left channel before testing the right.sleep(1)— waits 1 second so you can hear the gap between the two tests.
Monty's Tip
If you only have one speaker (mono audio), connect it to one of the two pins and confirm it beeps. Then move it to the other pin and run the program again.
Watch Out!
Always set duty_u16(0) at the end of each channel test. If you skip this step, the tone keeps playing on that pin even after the program moves to the next step.
References
Wikipedia — Phone Connector (Audio)
Great Work!
Both audio channels are tested and working. You are ready to play real WAV files through your stereo output!