Skip to content

Cannot Build with Wire.h on Arduino #4077

Closed
@eggsactly

Description

@eggsactly

Basic Infos

Hardware

Hardware: ?Arduino?
Core Version: ?2.4.0?

Description

I cannot build a sketch that includes both the Wire.h and EP8266WiFi.h libraries. I am trying to build for an Arduino Uno Wifi. Using Arduino 1.8.5 on Debian 9.3.

Settings in IDE

Module: ?Arduino?
Flash Size: ?4MB/(1MB SPIFFS)?
CPU Frequency: ?80Mhz?
Flash Mode: ?N/A?
Flash Frequency: ?115200?
Upload Using: ?SERIAL?
Reset Method: ?N/A?

Sketch

#include <ESP8266WiFi.h>
#include <Wire.h>

void setup() {
  // Do Nothing
}

Debug Messages

/home/$USER/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/Wire/Wire.cpp:48:30: error: 'SDA' was not declared in this scope
 static int default_sda_pin = SDA;
                              ^
/home/$USER/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/libraries/Wire/Wire.cpp:49:30: error: 'SCL' was not declared in this scope
 static int default_scl_pin = SCL;
                              ^
exit status 1
Error compiling for board Arduino.

Activity

pieman64

pieman64 commented on Jan 3, 2018

@pieman64
igrr

igrr commented on Jan 3, 2018

@igrr
Member

Which board do you have selected?

eggsactly

eggsactly commented on Jan 4, 2018

@eggsactly
Author

@pieman64, I'm assuming you mean that I should call Wire.begin(0, 2). Regardless, adding it produces the same result. I don't believe it is necessary to add that begin call because the SDA and SCL lines should default to pins 4 and 5 respectively.

Modifying esp8266/2.4.0/libraries/Wire/Wire.cpp to use

static int default_sda_pin = 4;
static int default_scl_pin = 5;

Instead causes this code to compile (I modified the following code below from my code in the first post because it won't work on the generic esp8266 board, but this will because it has the loop() function).

#include <ESP8266WiFi.h>
#include <Wire.h>

void setup() {
  // Do nothing 
}

void loop(){
  //Do Nothing
}

It appears these values are defined in esp8266/2.4.0/variants/generic/pins_arduino.h, but I don't know enough about how your project is configured to try to include it.

@igrr To try to answer your question I have selected the Arduino under ESP8266 Modules, and selected Uno WiFi as the model.

igrr

igrr commented on Jan 4, 2018

@igrr
Member

Thanks @eggsactly, this looks like an issue with Uno WiFi board variant.

Other board variant header files define SDA and SCL constants for the default I2C pin names, e.g.:

#define PIN_WIRE_SDA (4)
#define PIN_WIRE_SCL (5)
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

These definitions are missing from the variant header file for Uno WiFi:

https://github.com/esp8266/Arduino/blob/master/variants/arduino_uart/pins_arduino.h

added this to the 2.5.0 milestone on Jan 4, 2018
WereCatf

WereCatf commented on Jan 5, 2018

@WereCatf
Contributor

@igrr I would assume that the reason those pins aren't defined is because all the GPIO-pins except GPIO5 are already in use for something else on the board, at least according to https://eu.mouser.com/pdfdocs/Arduino-UNO-WiFi-V4_AF1.pdf Given that they're already in use, I don't think it's a good idea to define any I2C-pins in the first place, or if one really insists on defining some, GPIO5 and GPIO14 seem safe to use (though pointless) on the Arduino Uno WiFi, but then one would have to check that they're safe on the Primo and Star OTTO, too.

WereCatf

WereCatf commented on Jan 5, 2018

@WereCatf
Contributor

Couldn't find a schematic for Star OTTO, so no idea if the pins are in use there or not.

igrr

igrr commented on Jan 5, 2018

@igrr
Member

Alternatively, we could have something like this in Wire.cpp:

#if !defined(PIN_WIRE_SDA) || !defined(PIN_WIRE_SCL)
#error Wire library is not supported on this board
#endif

Not sure whether this is what @eggsactly wants...

JAndrassy

JAndrassy commented on Jan 7, 2018

@JAndrassy
Contributor

@eggsactly, on Uno WiFi the esp8266 has no pin headers. why do you try to use the Wire library?

JAndrassy

JAndrassy commented on Jan 7, 2018

@JAndrassy
Contributor

@WereCatf, not all pins are used. GPIO0 is connected to enable pulling low for bootloader mode, GPIO2 is connected, only to a soldering point, 4 controls the direct serial connection for Atmega flashing from esp, 5 is not connected, 12 is to Atmega reset pin, 13 is not connected, 14 is LED, 15 is not connected only pulled down, ,

eggsactly

eggsactly commented on Jan 8, 2018

@eggsactly
Author

@WereCatf and @JAndrassy perhaps I'm not understanding something, but it appears that on the Uno and Uno Wifi, the I2C pins are located on the same pins, Pins 27 and 28 on ZU4 on both devices.
Uno Rev 3 Diagram
Uno Wifi Diagram

I believe I should be able to attach an I2C device to the A4 and A5 pins. I was able to compile the code below using the vanilla Arduino AVR Board "Arduino Uno WiFi", but the same code does not compile with the ESP8266 Module "Arduino". This code is different from above because it does not include the ESP8266WiFi.h library so it should compile regardless of which device I have selected.

#include <Wire.h>

void setup() {
  // Do nothing 
}

void loop(){
  //Do Nothing
}

My perception as a user is this code should compile for both the Arduino AVR Board "Arduino Uno WiFi" and the ESP8266 Module "Arduino". My perception is based on the assumption that the normal Arduino library for Wire is the same as the library for ESP8266.

Perhaps I made a mistake in assuming that pins 4 and 5 correspond to A4 and A5, perhaps these pins are different, I am unsure because the Arduino's API for Wire does not allow you to choose output pins, you're glued on A4 and A5.

@JAndrassy to answer your question about why I would like to use the Wire library, I would like to hook this shield https://www.adafruit.com/product/772 up to the Arduino Wifi, while also being able to get wifi BSSIDs without being connected to a network, demonstrated on this project. It appears that the Arduino WiFi library does not have this capability but ESP8266WiFi does.

WereCatf

WereCatf commented on Jan 8, 2018

@WereCatf
Contributor

@eggsactly Yes, A4 and A5 are brought out, but A4 and A5 are the Atmega328P-pins, not ESP8266-pins. The ESP8266 and the Atmega328P are separate microcontrollers, you can't program the Atmega's I2C-pins with this ESP8266-core.

Also, the pins on the ESP8266 seemingly haven't been brought out on any pin-headers, so you couldn't use them anyways, unless you actually went and modified the board itself.

13 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @igrr@d-a-v@WereCatf@pieman64@JAndrassy

        Issue actions

          Cannot Build with Wire.h on Arduino · Issue #4077 · esp8266/Arduino