Arduino Nano ESP32 - TWAI - fatal error: driver/twai.h: No such file or directory

Hi all,
it is driving me crazy and unfortunately I look for it in internet but I was not able to find the solution.

I want to start building a program with CAN communication in an Arduino NANO ESP32. For that I am using the TWAI library. I have used the TWAIRecieve.ino example in Arduino IDE and works as expected. But now I wanted to move to PlatformIO

I copied the code from TWAIRecieve.ino β†’ main.cpp
And I configure platformio.ini file as following

platform = espressif32
board = arduino_nano_esp32
framework = arduino

monitor_speed = 115200

Unfortunately when compiling I get following error

src/main.cpp:27:10: fatal error: driver/twai.h: No such file or directory
#include β€œdriver/twai.h”

It looks like the drivers are not correctly imported from Arduino

Anyone any ideas?

And what version of the Arduino-ESP32 core is that using? Look into Tools β†’ Boards β†’ Board Manager β†’ ESP32. 2.0.14 or 3.0.0 Alpha?

PlatformIO only supports the proper latest stable release, 2.0.14. If you need 3.0.0 Alpha, see this issue.

1 Like

Thanks @maxgerhardt for your quick support, I am using 2.0.14

But the issue was that I had an old version of Arduino-ESP32. After much looking I found your answer in this post freertos/FreeRTOS.h: No such file or directory

Additionally I added #include <Arduino.h> in the includes of my main.cpp

Thanks for your support!

1 Like

HI Juan,

Could you please share your setup and code? I’m trying to replicate the CAN transmission with the Arduino NanoESP32 and neither receive nor transmit seems to function.

Thanks in advance,