ESP32 GATEWAY - Wire.h library malfunction

Started by erphillips28, May 26, 2018, 12:26:04 AM

Previous topic - Next topic

erphillips28

Im getting errors regarding SDA and SCL when trying to #include <Wire.h> library.
-> I am using Arduino IDE
-> I am using Olimex ESP32 Gateway board

Heres the code

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:


Heres the error

QuoteArduino: 1.8.5 (Mac OS X), Board: "OLIMEX ESP32-GATEWAY, 80MHz, 115200"

/Users/eruss28/Documents/Arduino/hardware/espressif/esp32/libraries/Wire/src/Wire.cpp: In member function 'void TwoWire::begin(int, int, uint32_t)':
/Users/eruss28/Documents/Arduino/hardware/espressif/esp32/libraries/Wire/src/Wire.cpp:51:34: error: 'SDA' was not declared in this scope
             if(sda==-1) sdaPin = SDA; //use Default Pin
                                  ^
/Users/eruss28/Documents/Arduino/hardware/espressif/esp32/libraries/Wire/src/Wire.cpp:63:34: error: 'SCL' was not declared in this scope
             if(scl==-1) sclPin = SCL; // use Default pin
                                  ^
exit status 1
Error compiling for board OLIMEX ESP32-GATEWAY.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Curious if I can use a #define somewhere in the code to define pins on the Gateway as SCL and SDA, or if I have to rewrite part of the library itself.

Thanks for the help!

Stanimir5F

Hello erphillips28!

I managed to replicate the problem and figured out what cause it. Although I'm not sure I can give you an appropriate suggestion how to solve it. From what I can see it's the issue that in the GATEWAY variant of the Espressif package SCL and SDA are not defined. For example on the ESP32-EVB there is such definitions:
Quote#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS        40
#define NUM_ANALOG_INPUTS       16

#define analogInputToDigitalPin(p)  (((p)<20)?(esp32_adc2gpio[(p)]):-1)
#define digitalPinToInterrupt(p)    (((p)<40)?(p):-1)
#define digitalPinHasPWM(p)         (p < 34)


static const uint8_t KEY_BUILTIN = 34;

static const uint8_t TX = 1;
static const uint8_t RX = 3;

static const uint8_t SDA = 13;
static const uint8_t SCL = 16;


static const uint8_t SS    = 17;
static const uint8_t MOSI  = 2;
static const uint8_t MISO  = 15;
static const uint8_t SCK   = 14;

#define BOARD_HAS_1BIT_SDMMC

#endif /* Pins_Arduino_h */
And thus on ESP32-EVB I2C module works.

The problem is on ESP32-GATEWAY you can't simply add them in the "pins_aruino.h" file and expect to work. It's because the I2C functions have to be mapped somehow to certain pins and then you can add them into the variant file.

Stan, Olimex
May the Source be with You!

LubOlimex

Technical support and documentation manager at Olimex