Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Build with Wire.h on Arduino #4077

Closed
eggsactly opened this issue Jan 3, 2018 · 18 comments
Closed

Cannot Build with Wire.h on Arduino #4077

eggsactly opened this issue Jan 3, 2018 · 18 comments

Comments

@eggsactly
Copy link

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.
@pieman64
Copy link

pieman64 commented Jan 3, 2018

@igrr
Copy link
Member

igrr commented Jan 3, 2018

Which board do you have selected?

@eggsactly
Copy link
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
Copy link
Member

igrr commented Jan 4, 2018

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

@igrr igrr added component: boards good first issue If you want to help, this is is a good place to start type: bug labels Jan 4, 2018
@igrr igrr added this to the 2.5.0 milestone Jan 4, 2018
@WereCatf
Copy link
Contributor

WereCatf commented Jan 5, 2018

@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
Copy link
Contributor

WereCatf commented Jan 5, 2018

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

@igrr
Copy link
Member

igrr commented Jan 5, 2018

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
Copy link
Contributor

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

@JAndrassy
Copy link
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
Copy link
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
Copy link
Contributor

WereCatf commented Jan 8, 2018

@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.

@JAndrassy
Copy link
Contributor

@eggsactly, you must write two sketches and program the communication between them. one for Armega and one for esp8266. if you need guidance with it, write a post on Arduino forum

@JAndrassy
Copy link
Contributor

@igrr, this is not a bug and not a 'good first', but the the #define check would help

@igrr
Copy link
Member

igrr commented Jan 8, 2018

I think it is a bug — if it fails, it should fail with a clear error message. Regarding "good first", okay, i will remove the label.

@igrr igrr removed the good first issue If you want to help, this is is a good place to start label Jan 8, 2018
@igrr igrr modified the milestones: 2.5.0, 2.4.1 Jan 16, 2018
@devyte
Copy link
Collaborator

devyte commented Jan 30, 2018

Closed via #4261

@Bagunda
Copy link

Bagunda commented Aug 18, 2018

I change place 'AppData' and etc.
Then i have error:
\libraries\Wire\Wire.cpp:37:2: error: #error Wire library is not supported on this board
#error Wire library is not supported on this board

I remove Arduino IDE. Then install Arduoino IDE from Microsoft Store.
Ver 1.8.5.
Error stil appears.

Board: ESP8266 or NodeMCU

Sketch:

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

#define pin_sda 5 // default sda pin
#define pin_scl 4 // default scl pin


void setup() {
  //
}

void loop(){
  //
}

How to fix?

@d-a-v
Copy link
Collaborator

d-a-v commented Aug 18, 2018

This looks like an installation problem.
Move every arduino installation directories in a backup directory and reinstall everything from scratch.
Do not use closed issues, please open a new one with your data in the issue template.

@JAndrassy
Copy link
Contributor

@Bagunda, esp8266 core version you use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants