Problem compiling code for ESP32 Dev Module

I am having trouble compiling the following piece of code on Platform IO (it compiles just fine in Arduino IDE).

#include <Arduino.h>

#define MICROSECOND_FREQUENCY 1000000
const unsigned long interval1 = 1 * 1000 * 1000;     // 1 seconds

void IRAM_ATTR onTimer1() {
  Serial.println("Method called");
}

void setup() {
  hw_timer_t *timer1 = timerBegin(MICROSECOND_FREQUENCY); // Timer frequency
  timerAttachInterrupt(timer1, &onTimer1);
  timerAlarm(timer1, interval1, true, 0);
}

void loop() {
  delay(1);
}

The errors I get are:

error: too few arguments to function 'hw_timer_t* timerBegin(uint8_t, uint16_t, bool)'
error: too few arguments to function 'void timerAttachInterrupt(hw_timer_t*, void (*)(), bool)'
error: 'timerAlarm' was not declared in this scope

Other internet searches have led me to believe that this is due to using a different (i.e. older) version of the library. But I have no clue where to find the proper version, and how to download it, and install it within Platform IO.

Here is the content of my platformio.ini file

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

Any help is appreciated,
Thanks

There are no libraries involved in your code.

You will probably already be using the Arduino 3.x core from Espressif in the ArduinoIDE. This is not (yet) officially supported by PlatformIO.

There are breaking API changes between version 2.x and 3.x

See Migration from 2.x to 3.0 - - — Arduino ESP32 latest documentation

To get Arduino Core 3.0.3 you can try pioarduino:

platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
1 Like

You’re getting tricked by the fact that PlatformIO in the standard espressif32 platform still uses Arduino-ESP32 2.0.16 as its Arduino core. (due to politics).

As you can see per

the function timerBegin takes 3 arguments in Arduino-ESP32 2.0.16, but, in Arudino-ESP32 3.0 you have

A changed API in which that function only uses one argument.

Thus, you can either rewrite the code to use the Arduino-ESP32 2.x API and keep platform unchanged, or, make PlatformIO use Arduino-ESP32 3.x by using unofficial platforms or packages. See

1 Like

I tried the solution outlined in the post you linked. Platform IO just gets stuck.

Is there another step I need to take?

The installation of a framework takes a while. Even after the framework has been installed, further components are installed - which can also take some time.

Be patient and wait until PlatformIO has completed all tasks. Then restart VS-Code and open the project.