Xinyuan-LilyGO / LilyGo-T-Call-SIM800

https://www.aliexpress.com/item/33045221960.html
472 stars 239 forks source link

Unable to control an Active Buzzer module #215

Open smurfolan opened 2 years ago

smurfolan commented 2 years ago

I know that there's a widely known issue ESP32 not being able to access tone() and noTone() functions from the Core Arduino.

So, I've been going through many articles on the internet trying to apply some workarounds for this such as explained here:

but whatever I do, my buzzer just doesn't stop beeping. Once I connect the Signal pin from the Buzzer to Pin 12 on the LilyGo-T-Call board it starts beeping and it never ends. I've tried everything but it keeps on beeping all the time.

Here's a code sample:

int freq = 2000;
int channel = 0;
int resolution = 8;

void setup() {

  Serial.begin(115200);
  ledcSetup(channel, freq, resolution);
  ledcAttachPin(12, channel);

}

void loop() {;
  noTone(12, 0);
}

void tone(uint8_t pin, unsigned int frequency, unsigned long duration, uint8_t channel)
{
    if (ledcRead(channel)) {
        log_e("Tone channel %d is already in use", channel);
        return;
    }
    ledcAttachPin(pin, channel);
    ledcWriteTone(channel, frequency);
    if (duration) {
        delay(duration);
        noTone(pin, channel);
    }    
}

void noTone(uint8_t pin, uint8_t channel)
{
    ledcDetachPin(pin);
    ledcWrite(channel, 0);
}

I have tried all kind of modifications of this code following the articles, I have switched PINs and everything but this buzzer just doesn't stop beeping. Whatever is the frequency of it. Just like this video. It keeps on beeping all the way. I just want to make it stop. And when needed - beep for 2 seconds and then completely stop. I started to wonder if I don't need to swap with a passive buzzer.

Fxplaysz commented 11 months ago

Hey so i dont think you should use the active buzzer because it already has an oscillator inside it which generates a signal so that's the the reason your buzzer is not working. I think you should try it with a passive buzzer and take a look at this GitHub post https://github.com/denyz427/ESP32-Buzzer-Tone-Codes/tree/main