Home Hardware A Raspberry Pi Pico Speaker Expansion Board

A Raspberry Pi Pico Speaker Expansion Board

by rp2040guy71

In this article we look at a speaker expansion board for your Raspberry Pi Pico. This board has an on board speaker and also a headphone jack.

This is a picture of the board

The main audio chip on this board after closer examination was found to be a NS8002 power amplifier – not one I had ever heard of.

Here is a little bit of information about this chip

This NS8002 is a bridged audio power amplifier. When 5V working voltage, maximum drive power is 3W (3ΩBTL negative Load, THD + N <10%). Device application circuit is simple, just a handful of peripheral devices; NS8002 output without external Coupling capacitors or bootstrap capacitors and snubber networks.

Device using SOP package, is particularly suitable for large-volume, small weight portable systems; NS8002 by Control goes into sleep mode, thereby reducing power consumption; NS8002 internal overheating Automatic shutdown protection mechanism; NS8002 work Stable. By configuring the external resistor voltage gain amplifier can be adjusted to facilitate application.

Features

1. High output power (THD + N <10%): 3W (3Ω load)
2. Power-down mode leakage current: 0.6μA (typical)
3. High Shut Down
4. External adjustable gain
5. Wide operating voltage range 2.2V ~ 5.5V
6. Without drive output coupling capacitors, bootstrap capacitors and snubber networks
7. Using SOP package.

ns8002

ns8002

Product Page

Available from the link below from about $3

speaker board

Code Example

The code example uses pwm on GPIO15 and defines a variety of notes.

from machine import Pin, PWM
from utime import sleep
buzzer = PWM(Pin(15))
 
tones = {
"B0": 31,
"C1": 33,
"CS1": 35,
"D1": 37,
"DS1": 39,
"E1": 41,
"F1": 44,
"FS1": 46,
"G1": 49,
"GS1": 52,
"A1": 55,
"AS1": 58,
"B1": 62,
"C2": 65,
"CS2": 69,
"D2": 73,
"DS2": 78,
"E2": 82,
"F2": 87,
"FS2": 93,
"G2": 98,
"GS2": 104,
"A2": 110,
"AS2": 117,
"B2": 123,
"C3": 131,
"CS3": 139,
"D3": 147,
"DS3": 156,
"E3": 165,
"F3": 175,
"FS3": 185,
"G3": 196,
"GS3": 208,
"A3": 220,
"AS3": 233,
"B3": 247,
"C4": 262,
"CS4": 277,
"D4": 294,
"DS4": 311,
"E4": 330,
"F4": 349,
"FS4": 370,
"G4": 392,
"GS4": 415,
"A4": 440,
"AS4": 466,
"B4": 494,
"C5": 523,
"CS5": 554,
"D5": 587,
"DS5": 622,
"E5": 659,
"F5": 698,
"FS5": 740,
"G5": 784,
"GS5": 831,
"A5": 880,
"AS5": 932,
"B5": 988,
"C6": 1047,
"CS6": 1109,
"D6": 1175,
"DS6": 1245,
"E6": 1319,
"F6": 1397,
"FS6": 1480,
"G6": 1568,
"GS6": 1661,
"A6": 1760,
"AS6": 1865,
"B6": 1976,
"C7": 2093,
"CS7": 2217,
"D7": 2349,
"DS7": 2489,
"E7": 2637,
"F7": 2794,
"FS7": 2960,
"G7": 3136,
"GS7": 3322,
"A7": 3520,
"AS7": 3729,
"B7": 3951,
"C8": 4186,
"CS8": 4435,
"D8": 4699,
"DS8": 4978
}
 
song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"]
 
def playtone(frequency):
    buzzer.duty_u16(1000)
    buzzer.freq(frequency)
 
def bequiet():
    buzzer.duty_u16(0)
 
def playsong(mysong):
    for i in range(len(mysong)):
        if (mysong[i] == "P"):
            bequiet()
        else:
            playtone(tones[mysong[i]])
            sleep(0.3)
            bequiet()
playsong(song)

Link

github repo

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More