Tone not working on espressif32 platform

Hello,

When using the regular Tone() and NoTone() on the espressif32 platform it generates an error saying these functions are not defined while the same code works fine on the espressif8266 platform.

In an earlier topic he same issue was reported for te Attiny85 and solved by an update of that platform. Could the same be true for this issue?

thanks,
Alex

Searching for tone() in the Arduino-ESP32 framework yields no results. The equivalent solution is to use the ledc driver (general PWM LED controller).

Also see ESP32 PWM with Arduino IDE (Analog Output) | Random Nerd Tutorials

Example code

// the number of the LED pin
const int ledPin = 16;  // 16 corresponds to GPIO16

// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
 
void setup(){
  // configure LED PWM functionalitites
  ledcSetup(ledChannel, freq, resolution);
  
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(ledPin, ledChannel);

  //output a Middle C
  ledcWriteTone(ledChannel, 261.626);
}
 
void loop(){
  //wait 5 secs
  delay(5000);
  //disable tone
  ledcWriteTone(ledChannel, 0);
}
2 Likes

Hi Maximilian,
Thanks for the quick response. Will try the code and share my result.

Alex

Hi,
Tested the ledc driver as described and this works off course. Thanks for the help!!

Alex