Error compiling for board Arduino Nano Every

Hey all,

I'm converting from Arduino Uno to Nano, but having issues compiling. It compiled and uploaded fine on the Uno, but having trouble when I try to switch over. I'm working on an Uno Every, ATMEGA4809

Here's the error:

In file included from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:2:0,

                 from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_I2CRegister.h:1,

                 from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_VEML6075_Library/Adafruit_VEML6075.h:23,

                 from C:\Users\kriva\Downloads\graberLED_withLED\graberLED_withLED.ino:4:

C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:11:3: error: conflicting declaration 'typedef enum _BitOrder BitOrder'

 } BitOrder;

   ^~~~~~~~

In file included from C:\Users\kriva\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.4\cores\arduino/api/Interrupts.h:8:0,

                 from C:\Users\kriva\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.4\cores\arduino/api/ArduinoAPI.h:32,

                 from C:\Users\kriva\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.4\cores\arduino/Arduino.h:23,

                 from sketch\graberLED_withLED.ino.cpp:1:

C:\Users\kriva\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.4\cores\arduino/api/Common.h:28:3: note: previous declaration as 'typedef enum BitOrder BitOrder'

 } BitOrder;

   ^~~~~~~~

In file included from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:2:0,

                 from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_I2CRegister.h:1,

                 from C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_VEML6075_Library/Adafruit_VEML6075.h:23,

                 from C:\Users\kriva\Downloads\graberLED_withLED\graberLED_withLED.ino:4:

C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:33:27: error: could not convert 'SPI_BITORDER_MSBFIRST' from '_BitOrder' to 'BitOrder'

        BitOrder dataOrder=SPI_BITORDER_MSBFIRST,

                           ^~~~~~~~~~~~~~~~~~~~~

C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:39:27: error: could not convert 'SPI_BITORDER_MSBFIRST' from '_BitOrder' to 'BitOrder'

        BitOrder dataOrder=SPI_BITORDER_MSBFIRST,

                           ^~~~~~~~~~~~~~~~~~~~~

exit status 1
Error compiling for board Arduino Nano Every.

Any help is appreciated!

Best,
KR

The problem is that both the Nano Every’s Arduino megaAVR Board core and the Adafruit_BusIO library define _BitOrder, which causes the conflict. I think the best solution is to patch the Adafruit library:

Open C:\Users\kriva\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h in a text editor.

Change lines 2-26 from:

#ifndef Adafruit_SPIDevice_h
#define Adafruit_SPIDevice_h

// some modern SPI definitions don't have BitOrder enum
#if defined(__AVR__) || defined(ESP8266) || defined(TEENSYDUINO)
typedef enum _BitOrder {
  SPI_BITORDER_MSBFIRST = MSBFIRST,
  SPI_BITORDER_LSBFIRST = LSBFIRST,
} BitOrder;
#endif

// some modern SPI definitions don't have BitOrder enum and have different SPI mode defines
#if defined(ESP32)
typedef enum _BitOrder {
  SPI_BITORDER_MSBFIRST = SPI_MSBFIRST,
  SPI_BITORDER_LSBFIRST = SPI_LSBFIRST,
} BitOrder; 
#endif

// Some platforms have a BitOrder enum but its named MSBFIRST/LSBFIRST
#if defined(ARDUINO_ARCH_SAMD) || defined(__SAM3X8E__) || defined(NRF52_SERIES)
  #define SPI_BITORDER_MSBFIRST MSBFIRST
  #define SPI_BITORDER_LSBFIRST LSBFIRST
#endif

to:

#include <Arduino.h>

#ifndef Adafruit_SPIDevice_h
#define Adafruit_SPIDevice_h

// Some platforms have a BitOrder enum but its named MSBFIRST/LSBFIRST
#if defined(ARDUINO_ARCH_SAMD) || defined(__SAM3X8E__) || defined(NRF52_SERIES) || defined(ARDUINO_API_VERSION)
  #define SPI_BITORDER_MSBFIRST MSBFIRST
  #define SPI_BITORDER_LSBFIRST LSBFIRST
#else
// some modern SPI definitions don't have BitOrder enum
#if defined(__AVR__) || defined(ESP8266) || defined(TEENSYDUINO)
typedef enum _BitOrder {
  SPI_BITORDER_MSBFIRST = MSBFIRST,
  SPI_BITORDER_LSBFIRST = LSBFIRST,
} BitOrder;
#endif

// some modern SPI definitions don't have BitOrder enum and have different SPI mode defines
#if defined(ESP32)
typedef enum _BitOrder {
  SPI_BITORDER_MSBFIRST = SPI_MSBFIRST,
  SPI_BITORDER_LSBFIRST = SPI_LSBFIRST,
} BitOrder; 
#endif
#endif

Save the file.

After that, the error should be fixed.