BUZZER in use error

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tonygo
 
Posts: 108
Joined: Fri Apr 13, 2018 11:09 am

BUZZER in use error

Post by Tonygo »

Code: Select all

# Pico:ed V2 Graphics demonstration using CircuitPython
# Tony Goodhew 27th September 2022

import board
import digitalio
import pwmio  # for Buzzer
import time
from picoed import *

W = display.width
H = display.height

def blit(s,x,y,w,h,v): # Insert image in frame
    for xx in range(w):
        for yy in range(h):
            c = s[xx+yy*w]*v
            display.pixel(x+xx,y+yy,c)

# Titles and Buzzer demo
#display.scroll("Tony Goodhew")

piezo = pwmio.PWMOut(board.BUZZER_GP3,duty_cycle=0, frequency=440, variable_frequency=True) # ERROR !!!
def play_note(note):
    piezo.frequency = note
    piezo.duty_cycle = 65535 // 2
    time.sleep(0.25)
    piezo.duty_cycle = 0
    time.sleep(0.05)
for i in range(2):
    play_note(494)
    time.sleep(0.2)
    play_note(262)
    time.sleep(0.2)
    play_note(294)
    time.sleep(0.2)
piezo.deinit()
display.scroll("Graphics test of Pico:ed V2")

#Brightness
display.fill(1) # Fill display with dimmest pixels
time.sleep(2)
display.fill(10) # Fill display with brighter pixels
time.sleep(2)
=====================================

Traceback (most recent call last):
File "<stdin>", line 22, in <module>
ValueError: BUZZER in use

Cannot get this to run. I halted program while buzzer was active and reset button and unplugging to not appear to reset the processor.

Suggestions please.
Last edited by dastels on Wed Sep 28, 2022 9:08 am, edited 1 time in total.
Reason: add code tag

User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: BUZZER in use error

Post by dastels »

That's because the board.BUZZER pin is already used in the picoed module (https://github.com/elecfreaks/circuitpython_picoed)

Either don't use the picoed module, or use its music support: https://github.com/elecfreaks/circuitpython_ef_music. The picoed module makes an instance of Music available as picoed.music

Dave

User avatar
Tonygo
 
Posts: 108
Joined: Fri Apr 13, 2018 11:09 am

Re: BUZZER in use error

Post by Tonygo »

Thank you. I will give that a try.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”