Hi
I’m trying to add an Arduino Library ( u8g2 ) to an ESP-IDF with Arduino Core as component Project, but I’m having issues to do so.
First thing I did is I cloned the espidf-arduino-blink example (Link) and opened it as a new project in VSC PlatformIO.
I then went to the Library manager of PlatformIO, searched for the library and added it to the Project.
After that, I started the Setup process according to the Library wiki.
However, when I add the Constructor (for example,
VSCode marks it with issues and tells me the identifier is undefined. However, If I go to the reference link, VSCode goes to the correct Class.
I’m a newbie and I don’t know much about C/C++ and, yes, this is going over my head. I tried using Arduino Core instead of Arduino as component and it works, so I could continue using that, but I want to learn and understand what’s happening and why it’s happening.
So, basically, the Constructor shows error “identifier undefined”
My code basically looks like this:
/* Blink Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/gpio.h>
#include "sdkconfig.h"
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE,21,22)
#if !CONFIG_AUTOSTART_ARDUINO
#else
void setup() {
u8g2.begin();
}
void loop() {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0,24,"Hello World!");
} while ( u8g2.nextPage() );
}
#endif
Does the project build in PlatformIO? Does the error show up after that, too? (Intelliesense errors are not always build errors and a result of the library bein temporarily not yet there yet or IntelliSense paths not being updated yet). If yes, does a project tasks → Miscellaneous → Rebuild IntelliSense help?
@maxgerhardt
It doesn’t
Here’s the error: Compiling .pio/build/esp320/esp-idf/src/Blink.cpp.o src/Blink.cpp:29:1: error: 'U8G2_SSD1306_128X64_NONAME_F_HW_I2C' does not name a type U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 22, /* data=*/ 21);
You see, all these classes (types) are only defined if
and that is only defined if
But when building in ESP-IDF + Arduino mode, apparently the ARDUINO macro isn’t set and thus also not the U8X8_USE_PINS macro. (@valeros should that be fixed in the builder code maybe?)
Modify your project’s platformio.ini to use another build_flags directive like
Thank you for the research and answer @maxgerhardt
Would it be too much trouble if I asked you more about this?
I’ve done the same backwards path in an Arduino framework project and also found that there’s no #define ARDUINO
macro to be found, at least not in the project files. But the project builds without any build_flag
Why is this?
Ok, I’m getting in a rabbit hole. That might take me a while to understand, but thank you for the patience and for replying.
Getting back to the business, that’s why you asked @valeros if this needs to be added to the builder or not, correct?
It might be an overlook or could be intentional, correct?
The Arduino IDE encodes the version of itself, e.g. “1.8.5” in the ARDUINO macro as this integer, and since it’s passed to the compiler as a -DARDUINO=10805 flag macro value is globally visible in any file, so some libraries use this macro to determine in what environment they’re running in, nothing wild
Yes exactly, he’s a main developer of the platforms. It might be correct that a ARDUINO macro is not added, or it might not be. But for you this seems to be right thing to make the library happy.