Avr/io.h: No such file or directory error when using Adafruit BNO08x library

Hello everybody,
I connected adafruit bno085 sensor to my ESP32-S3 devkit. And I am trying to upload a program where i can see the output of IMU rotation vector.

This is my ini file:

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
; change MCU frequency
board_build.f_cpu = 240000000L
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags = -I lib
upload_rate = 115200
lib_deps = Adafruit BNO08x@^1.2.5

This is my header file:

#include <Arduino.h>/
#include <Adafruit_BNO08x.h>

#define SDA         8
#define SCL         9
#define BNO08x_DEFAULT_I2CADDR 0x4A
extern Adafruit_BNO08x bno08x;
extern sh2_SensorValue_t sensorValue;
extern bool startProcess;
extern long intervalUs;
extern int deviceID;

This is my main.cpp:

#include <Adafruit_BNO08x.h>
#include <Wire.h>
#include <Arduino.h>
#include "main.h"

Adafruit_BNO08x bno08x(-1);
sh2_SensorValue_t sensorValue;
bool startProcess = false;
long intervalUs = 66666;
int deviceID = 0;

//Initialize I2C bus
TwoWire I2CBNO080 = TwoWire(0);

void setup() {
  I2CBNO080.begin(SDA,SCL,400000);
  if (bno08x.begin_I2C(BNO08x_DEFAULT_I2CADDR,&I2CBNO080,deviceID)) {
  delay(10);
  if(bno08x.enableReport(SH2_ARVR_STABILIZED_RV,intervalUs)){
    startProcess = true;
    }
  }
  else{
    //some other stuff
  }
}

void loop{
    runIMU();
    delay(50);
}

And this is my imu file:

void runIMU(){
  if (startProcess == true){
//do stuff
}
}

When i run this, i got this error

Processing esp32-s3-devkitc-1 (platform: espressif32; board: esp32-s3-devkitc-1; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1.html
PLATFORM: Espressif 32 (6.5.0) > Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20014.231204 (2.0.14) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 48 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 2.0.0
|-- ESP32 BLE Arduino @ 2.0.0
|-- Adafruit BNO08x @ 1.2.5
|-- Preferences @ 2.0.0
Building in release mode
Compiling .pio\build\esp32-s3-devkitc-1\src\main.cpp.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\coolant_control.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\eeprom.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\gcode.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\jog.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\limits.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\main.c.o
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\motion_control.c.o
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/coolant_control.c:21:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
Compiling .pio\build\esp32-s3-devkitc-1\liba92\grbl\nuts_bolts.c.o
C:/Users/HP/Documents/Arduino/libraries/grbl/eeprom.c:24:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\coolant_control.c.o] Error 1
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/gcode.c:22:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/jog.c:21:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\eeprom.c.o] Error 1
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\gcode.c.o] Error 1
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\jog.c.o] Error 1
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/limits.c:22:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/main.c:22:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/motion_control.c:22:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
In file included from C:/Users/HP/Documents/Arduino/libraries/grbl/nuts_bolts.c:22:
C:/Users/HP/Documents/Arduino/libraries/grbl/grbl.h:29:10: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\limits.c.o] Error 1
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\motion_control.c.o] Error 1
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\main.c.o] Error 1
*** [.pio\build\esp32-s3-devkitc-1\liba92\grbl\nuts_bolts.c.o] Error 1

What am i doing wrong?

A note in advance:

Please enclose code and log blocks with three backticks ```.
Otherwise your code / log will be difficult to read.

Example:

```
  Your code here
```

I have changed your post accordingly.

Now to your problem:

This will be the root cause of your problem.
This includes all libraries from this folder in the build process and the compiler tries to compile them.

The folder contains at least one library (probably grbl) which is only compatible to AVR but not to espressif32.

Do not use a global library folder for PlatformIO!
This works differently than in the ArduinoIDE.

Remove this line from your platformio.ini and this error should be solved.

There is another issue with your code:

What kind of file is this? Is it a header file or a cpp file?

For this to work you must have an imo.h and an imu.cpp:

imu.h:

#pragma once

void runIMU();

imu.cpp:

#include "imu.h"
#include "main.h" // include main.h to get access to startProcess

void runIMU() {
    if (startProcess == true) {
        // do stuff
    }
}

In addition, you must #include "imu.h" in your main.cpp

The structure of your project is very unusual.
The use of a “main.h” which is then included in other compilation units is very uncommon.

1 Like

Dear @sivar2311,
imu file is a cpp file and I declared it in a header file. I couldn’t post the whole structure of the project because it’s a company project. It was 4 am in the morning and I was debugging for hours. So, sorry for the incomplete post.

Your solution worked! Thank you very much and kudos :partying_face: