PRESTO Sounds

Looking at the schematic the piezo audio appears to be on GPIO43 so I would expect this code to produce a tone near middle C

from machine import PWM
from time import sleep
pwm = PWM(43, freq=262, duty_u16=8192)  # create a PWM object on a pin
                                        # and set freq and duty
pwm.duty_u16(32768)     # set duty to 50%
sleep(2)


pwm.deinit()

I cannot hear anything. What am I doing wrong? How can I get beeps from it?

Do you need to specify PWM(Pin(43), ... ?

Iā€™m not sure - I cannot find any PRESTO sound examples and all my attempts do not produce anything I can hear - even with with hearing aids in!

Nothing from this, either

# Tones on PRESTO

import machine
import time

buzzer = machine.PWM(machine.Pin(43))  # set pin 43 as PWM OUTPUT PRESTO

notes = [256,512,100,200,0]
for i in notes:
    if i == 0:
        buzzer.duty_u16(0)            # 0% duty cycle
    else:
        buzzer.freq(i)                # set frequency (notes)
        buzzer.duty_u16(32000)        
    time.sleep(1)

Iā€™ve got everything else working properly but not sounds.

I thought you got audio working yesterday with this post? PRESTO WiFi demo - #5 by Tonygo2

Our Ryan was working on a Piezo example yesterday, that will get merged in to the Presto repo some time soon.

Not really working - just a few very high pitched very low volume squeaks is all I get from this:

import machine
import utime
import array, time
from machine import Pin
import rp2
from rp2 import PIO, StateMachine, asm_pio

buzzer = machine.PWM(machine.Pin(43))

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

start = [E7, E7, 0, E7, 0, C7, E7, 0, G7, 0, 0, 0]
audio_left = machine.PWM(machine.Pin(43))
for i in start:
    if i == 0:
        audio_left.duty_u16(0)

    else:
        buzzer.freq(i)
        audio_left.duty_u16(19660)
    utime.sleep(0.15)

The same code on a Cytron Maker Pi Pico really blasts your ears.

That is odd. Iā€™ve shared this with our Ryan to see what he discovers.

I can confirm though that GPIO43 is the correct pin, and the Piezo schematic is identical to that we used on PicoSystem. It does differ from the Pico Explorer Base though, so code for that was originally written for that board may not work the same.

Our Ryan reports that all three pieces of code you posted in this thread work. He even recognised the third was Mario without having seen the mention in the other thread. Higher pitched than he expected, but that may be due to the tones used.

It may be that your unit has a faulty buzzer, though how that got through our testing I donā€™t know. Perhaps you can post videos of the audio your unit is playing so that we can confirm?

Here is a video. Needs sound right up to hear the Mario high beeps above PC fan, which is pretty quiet.

Here is code used:

# Tony Goodhew - poor sound output
import machine
import utime
import array, time
from machine import Pin
import rp2
from presto import Presto
# Setup for the Presto display
presto = Presto(full_res=True,ambient_light=True)
display = presto.display
buzzer = machine.PWM(machine.Pin(43))

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


BLACK = display.create_pen(0, 0, 0)


def clean(): # Clear the screen to Black
    display.set_pen(BLACK)
    display.clear()
    presto.update()

clean()
RED = display.create_pen(255,0,0)
display.set_pen(RED)
display.text("Mario - Starting ...",20,20,460,6)
presto.update()
mario = [E7, E7, 0, E7, 0, C7, E7, 0, G7, 0, 0, 0, G6, 0, 0, 0, C7, 0, 0, G6, 0, 0, E6, 0, 0, A6, 0, B6, 0, AS6, A6, 0, G6, E7, 0, G7, A7, 0, F7, G7, 0, E7, 0,C7, D7, B6, 0, 0, C7, 0, 0, G6, 0, 0, E6, 0, 0, A6, 0, B6, 0, AS6, A6, 0, G6, E7, 0, G7, A7, 0, F7, G7, 0, E7, 0,C7, D7, B6, 0, 0]
audio = machine.PWM(machine.Pin(43))

for i in mario:
    if i == 0:
        audio.duty_u16(0)

    else:
        buzzer.freq(i)
        audio.duty_u16(19660)
    utime.sleep(0.15)

BLUE = display.create_pen(0,0,255)
display.set_pen(BLUE)
display.text("....finished",20,250,460,6)
presto.update()
time.sleep(2)
clean()

1 Like

Okay, so itā€™s playing but quiet. I am unsure if that is the volume weā€™d expect from the device or not, but your earlier posts implied nothing was playing at all.

One thing I notice in your code is that you have two objects for controlling the same PWM, buzzer , and audio. I canā€™t imagine thatā€™s a good thing so maybe just try using one to see if that improves things?

Iā€™ve taken out buzzer and just use audio. It is still much quieter than I would expect. Not really loud enough for alarm beeps. I have to really listen to hear it - when played on the Cytron unit it is really loud, possibly too loud - you cannot ignore it.

Thanks, I have passed this feedback on. There are differences between the circuit used by Cytron and Prestoā€™s buzzer, but I wouldnā€™t have expected it to be that large a difference.

Iā€™ve got a buzzer somewhere. Would it be safe to drive it from the I2C port pins? Just to see how loud that would be.

Thanks Tony, for the sound demo.

I actually find it loud enough to have some systems sound, such as:

  • confirmation/buzzer sound on button press
  • hour beep for a clock
  • alarm clock (for the bedside table you donā€™t want to have it too loudā€¦)
  • melodies for simple games

I am happy with the volumeā€¦

Cheers

Glad you found it useful.

My PRESTO is so quiet that my wife, who normally complains telling me to, ā€œTo turn it off,ā€ when I play ā€˜tunesā€™ on similar buzzers, asked me to turn it up when I asked her to listen to Mario on the PRESTO. Mine is not loud enough for ā€˜you have touched itā€™ feed-back when using the touch screen or as a kitchen timer alarm - the food would burn!

Iā€™m still not sure why mine is so quiet.

The display with Picographics and touch system is wonderful - a delight, the backlights quirky but fun, the Wifi easy to use and there is plenty of memory. A pity about my sound. Perhaps I need to change the buzzer component.

You could connect a beeper of your liking to the Qu/ST port (using a connector to female DuPont cable) and use this one instead of the build-in beeperā€¦no?

Using that would knock out all I2C access - too much loss to get a buzzer. Itā€™s a pity there is not one spare IO pin available on the Presto or a switchable link/ trace to cut for to either a buzzer or IO pin.

Otherwise it is a terrific bit of kit.

Ok, true, if it cannot be set for just one dedicated port - I wasnā€™t aware of thatā€™s either or.

I was of the impression you could define GPIOs as per your likingā€¦regardless of they would be intended to, you would just redefine them and go with some other functionalityā€¦

You could reprogram the pins but then you would not have i2c access which is very useful. I have a qw/stpad and sensors in the port and do not want to give them up. The buzzer is of less priority to me - especially as the one fitted to my board is so quiet. I miss not having at least one GPIO pin I could use as I want - a string of Neopixels, a button, a potentiometer - all ADC pins used? or an interrupt line.