PlatformIO Community

Problem with Adafruit_MCP23017 library, ESP32 and dependencies

Hi,
I’m quite new to PlatformIO and have generally found it quite easy to transition from the Arduino IDE, I migrated using the tool which leaves most of my libraries in their old Arduino IDE location. However, I’m having a problem with dependencies with the Adafruit_MCP23017 library, a new library I’ve just introduced to my project which I’ve added as PIO library.
The C pre-processor code (excerpt below) from Adafruit_MCP23017.h looks OK to me and I would expect it to just identify the Wire.h library as a dependency as I’m compiling for ESP32, so ARDUINO_AVR_GEMMA should not be defined.

#ifndef ARDUINO_AVR_GEMMA
                                    //TinyWireM is now part of
                                    //   Adafruit version of Wire Library, so this
                                    // will work with Adafruit ATtiny85's
                                    //But Arduino Gemma doesn't use that library
                                    // We do NOT want to include Wire if it's an arduino Gemma
  #include <Wire.h>
#else
 #include <TinyWireM.h>
 #define Wire TinyWireM
#endif

In fact it identifies both Wire.h and TinyWireM.h as dependencies and then goes on to fail as it can’t find the avr/interrupt.h library, which I wouldn’t expect it to.

If I comment out the pre-compiler conditionals and just leave in the #include Wire.h, everything compiles and links without problems.

The relevant bits of my platformio.ini look like this:

[platformio]
default_envs = Office

[common]
framework = arduino
arduino_ide_lib_dirs = ~/Documents/Arduino/libraries
lib_deps = Adafruit Unified Sensor
monitor_speed = 115200

[env:Office]
platform = espressif32
board = lolin32
framework = ${common.framework}
lib_extra_dirs = ${common.arduino_ide_lib_dirs}
lib_deps = ${common.lib_deps}
monitor_speed = ${common.monitor_speed}
build_flags = -D BUILD=\"zOffice.h\"
upload_protocol = espota
upload_port = 192.168.xx.yyy
upload_flags = --auth=zzzzzzz
  --port=3232

Any help much appreciated.
John

Preprocessor macros are only evaluated by the library dependency finder (LDF) for chain+ and deep+, see documentation and documentation. So I would try adding

lib_ldf_mode = chain+

or deep+.

1 Like

Hi Max,
thanks for the quick response, I tried both chain+ and deep+ and they did make a difference, they got rid of the TinyWireM library. Only problem was they also got rid of quite a few libraries I do need as well! I read the documentation thanks, but doesn’t really explain what I’m seeing, maybe because I’m passing the file that sets a lot of the defines itself as a directive from platformio.ini, so probably LDF isn’t aware of those defined directives:

build_flags = -D BUILD=“zOffice.h”

Though one of the missing libraries is WebServer.h from the “#elif defined ( ESP32 )” section, nothing to do with my build file. I did try “lib_compat_mode = strict” but that just seemed to make thiungs worse.

My library dependancies in main are quite complicated and cater for both ESP8266 and ESP32 and a range of sensors which can be present or absent. The include statement in my main .cpp file look like this:

/***********\
* Includes  *
\***********/
#include BUILD
#ifdef ESP8266
  #include <ESP8266WiFi.h>
  #include <WiFiUdp.h>
  #include <ESP8266mDNS.h>
  #include <ESP8266WebServer.h>
#elif defined ( ESP32 )
  #include <WiFi.h>
  #include <ESPmDNS.h>
  #include <WebServer.h>
#endif   // ESP type
#include <WiFiClient.h>
#include <PubSubClient.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#ifdef CFGEEPROM
  #include <EEPROM.h>
#endif
#include <stdio.h>
#include <FS.h>
#ifdef ESP32
  #include <SPIFFS.h>
  #include "esp_system.h"
  #include "esp_spi_flash.h"
#endif
#if defined(DHT11PIN) || defined(DHT22PIN)
  #include <DHT.h>
  #include <assert.h>
#endif
#ifdef ONEWIRE
  #include <OneWire.h>
  #include <DallasTemperature.h>
#endif
#ifdef I2C
  #include <Wire.h>
  #ifdef SSD1306DISP
    #include <SSD1306.h> // alias for `#include "SSD1306Wire.h"
  #endif // SSD1306DISP
  #ifdef BME280
    #include <BlueDot_BME280.h>
  #endif // BME280
  #ifdef ADS1115
    #include <Adafruit_ADS1015.h>
  #endif
  #ifdef MCP23017
    #include <Adafruit_MCP23017.h>
  #endif // MCP23017
#endif // I2C
#ifdef RX433PIN
  #include <Manchester.h>
#endif
#ifdef RS485
// #include <SoftwareSerial.h>
  #include <ModbusMaster.h>
#endif
#ifndef RDEBUG
  #define DEBUG_DISABLED = 1
#endif
#include <RemoteDebug.h>
#include "global.h"
#include "display.h"
#include "nettime.h"
#include "fileio.h"
#include "sensors.h"
#include "webserv.h"

the new dependecy graph looks like this, much shorter than previously:

Dependency Graph
|-- <Adafruit Unified Sensor> 1.0.3
|-- <SPIFFS> 1.0
|   |-- <FS> 1.0
|-- <FS> 1.0
|-- <Ticker> 1.1
|-- <PubSubClient> 2.7
|-- <Update> 1.0
|-- <ArduinoOTA> 1.0
|   |-- <Update> 1.0
|   |-- <ESPmDNS> 1.0
|   |   |-- <WiFi> 1.0
|   |-- <WiFi> 1.0
|-- <WiFi> 1.0
|-- <RemoteDebug> 3.0.5
|   |-- <WiFi> 1.0
Compiling .pio\build\Office\src\ESPMon_v0.6.cpp.o
Archiving .pio\build\Office\lib68a\libFS.a
Archiving .pio\build\Office\libb2e\libSPIFFS.a
Compiling .pio\build\Office\lib3df\Ticker\Ticker.cpp.o
Compiling .pio\build\Office\lib87d\PubSubClient\PubSubClient.cpp.o
src\ESPMon_v0.6.cpp:33:25: fatal error: WebServer.h: No such file or directory

Thanks for your help.