When compiling the simple example with Generic Custom Component I got errors “‘INPUT’ was not declared in this scope”
Which header file should be included ?
I tried <Arduino.h> or <esp_system.h> byt without success.
esphome run test.yaml
INFO ESPHome 2023.8.3
INFO Reading configuration test.yaml...
INFO Generating C++ source...
INFO Compiling app...
************************************************************************************************************************
Obsolete PIO Core v6.1.9 is used (previous was 6.1.11)
Please remove multiple PIO Cores from a system:
https://docs.platformio.org/en/latest/core/installation/troubleshooting.html
************************************************************************************************************************
Processing klima (board: az-delivery-devkit-v4; framework: arduino; platform: platformio/[email protected])
------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/az-delivery-devkit-v4.html
PLATFORM: Espressif 32 (5.4.0) > AZ-Delivery ESP-32 Dev Kit C V4
HARDWARE: ESP32 240MHz, 520KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20005.220925 (2.0.5)
- tool-esptoolpy @ 1.40400.0 (4.4.0)
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ off, Compatibility ~ soft
Found 32 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pioenvs\klima\src\esphome\components\binary_sensor\automation.cpp.o
Compiling .pioenvs\klima\src\esphome\components\binary_sensor\binary_sensor.cpp.o
Compiling .pioenvs\klima\src\esphome\components\binary_sensor\filter.cpp.o
Compiling .pioenvs\klima\src\esphome\components\esp32\gpio.cpp.o
Compiling .pioenvs\klima\src\esphome\components\esp32\preferences.cpp.o
Compiling .pioenvs\klima\src\esphome\components\gpio\binary_sensor\gpio_binary_sensor.cpp.o
Compiling .pioenvs\klima\src\esphome\components\sensor\automation.cpp.o
Compiling .pioenvs\klima\src\esphome\components\sensor\filter.cpp.o
Compiling .pioenvs\klima\src\esphome\components\sensor\sensor.cpp.o
Compiling .pioenvs\klima\src\esphome\core\application.cpp.o
Compiling .pioenvs\klima\src\esphome\core\component.cpp.o
Compiling .pioenvs\klima\src\esphome\core\component_iterator.cpp.o
Compiling .pioenvs\klima\src\esphome\core\controller.cpp.o
Compiling .pioenvs\klima\src\esphome\core\entity_base.cpp.o
Compiling .pioenvs\klima\src\esphome\core\helpers.cpp.o
Compiling .pioenvs\klima\src\esphome\core\log.cpp.o
Compiling .pioenvs\klima\src\esphome\core\scheduler.cpp.o
Compiling .pioenvs\klima\src\esphome\core\string_ref.cpp.o
Compiling .pioenvs\klima\src\esphome\core\util.cpp.o
Compiling .pioenvs\klima\src\main.cpp.o
In file included from src/main.cpp:19:
src/my_custom_component.h: In member function 'virtual void MyCustomComponent::setup()':
src/my_custom_component.h:12:16: error: 'INPUT' was not declared in this scope
pinMode(5, INPUT);
^~~~~
src/my_custom_component.h:12:16: note: suggested alternative: 'INTSET'
pinMode(5, INPUT);
^~~~~
INTSET
src/my_custom_component.h:12:5: error: 'pinMode' was not declared in this scope
pinMode(5, INPUT);
^~~~~~~
src/my_custom_component.h:13:16: error: 'OUTPUT' was not declared in this scope
pinMode(6, OUTPUT);
^~~~~~
src/my_custom_component.h: In member function 'virtual void MyCustomComponent::loop()':
src/my_custom_component.h:18:9: error: 'digitalRead' was not declared in this scope
if (digitalRead(5)) {
^~~~~~~~~~~
src/my_custom_component.h:19:23: error: 'HIGH' was not declared in this scope
digitalWrite(6, HIGH);
^~~~
src/my_custom_component.h:19:7: error: 'digitalWrite' was not declared in this scope
digitalWrite(6, HIGH);
^~~~~~~~~~~~
*** [.pioenvs\klima\src\main.cpp.o] Error 1
============================================== [FAILED] Took 6.31 seconds ==============================================
here is my yaml
esphome:
name: klima
includes:
- my_custom_component.h
# libraries:
esp32:
board: az-delivery-devkit-v4
framework:
type: arduino
platform_version: 5.4.0
custom_component:
- lambda: |-
auto my_custom = new MyCustomComponent();
return {my_custom};
components:
- id: my_custom_id
and component:
#include "esphome.h"
using namespace esphome;
// #include <Arduino.h>
// #include <sdkconfig.h>
// #include <esp_system.h>
class MyCustomComponent : public Component {
public:
void setup() override {
// This will be called once to set up the component
// think of it as the setup() call in Arduino
pinMode(5, INPUT);
pinMode(6, OUTPUT);
}
void loop() override {
// This will be called very often after setup time.
// think of it as the loop() call in Arduino
if (digitalRead(5)) {
digitalWrite(6, HIGH);
// You can also log messages
ESP_LOGD("custom", "The GPIO pin 5 is HIGH!");
}
}
};