I have used the library mentioned above with a variety of ESP8266 and ESP32 devices, using platformIO. Recently, I loaded a project that was compiled, loaded to an ESP32 and has run for the past year. upon opening the project and with no changes made to the project code I got the following errror message in platformIO (VSC);
In file included from .pio/libdeps/esp32doit-devkit-v1/OneWire/OneWire.cpp:149:
.pio/libdeps/esp32doit-devkit-v1/OneWire/util/OneWire_direct_gpio.h: In function ‘uint32_t directRead(uint32_t)’:
.pio/libdeps/esp32doit-devkit-v1/OneWire/util/OneWire_direct_gpio.h:173:17: error: ‘GPIO’ was not declared in this scope
173 | return (GPIO.in >> pin) & 0x1;
| ^~~~
.pio/libdeps/esp32doit-devkit-v1/OneWire/util/OneWire_direct_gpio.h:175:17: error: ‘GPIO’ was not declared in this scope
175 | return (GPIO.in1.val >> (pin - 32)) & 0x1;
| ^~~~
Has anyone else seen this error and do they know what the fix is please? I am guessing it is a versioning issue. This sample error code came from using an ESP32 Dev kit v1
Seems like this error has been discussed quite a lot:
https://github.com/PaulStoffregen/OneWire/issues?q=is%3Aissue+GPIO+was+not+declared+in+this+scope+
The key point here is what version of the Arduino-ESP32 framework (and related to that, the espressif32 platform) you’re using. What’s the platformio.ini
of your project? You might just be missing to pin the platform
version.
The relevent part of the ini is as follows;
[env]
lib_deps =
knolleary/PubSubClient@^2.8
mikalhart/Streaming@^1.0.0
milesburton/DallasTemperature@^3.9.1
sstaub/TickTwo@^4.4.0
bodmer/TFT_eSPI @ ^2.3.58
gioblu/PJON@^13.0
bblanchon/ArduinoJson@^6.18.5
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_type = debug
lib_ignore = Time.h
lib_deps =
${env.lib_deps}
lib_extra_dirs =
C:/Users/Bob/OneDrive/Documents/PlatformIO/Projects/myPio_Libs
I also looked at the link you shared and the propsed solution was to include a GPIO .h file. In the onewire.cpp of the onewire library. In the version I am using that .h file is included.
On my ESP32-S3 project the ini is as follows;
[env:esp32-s3-devkitc-1]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
;build_type = debug
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
;board_build.partitions = default.csv
board_build.partitions = no_fs_4MB.csv
board_build.debug = 0
board_build.extra_flags =
-DBOARD_HAS_PSRAM
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
lib_deps =
bitbank2/bb_captouch@^1.2.2
bitbank2/bb_spi_lcd@^2.7.1
knolleary/PubSubClient@^2.8
sstaub/TickTwo@^4.4.0
gioblu/PJON@^13.0
bblanchon/ArduinoJson@^6.18.5
pstolarz/OneWireNg@^0.13.3
mikalhart/Streaming@^1.0.0
pstolarz/OneWireNg@^0.13.3
lib_extra_dirs =
C:/Users/Bob/OneDrive/Documents/PlatformIO/Projects/myPio_Libs
;upload_port = COM6
upload_protocol = espota
upload_port = 192.168.1.123
Both projects exhibit the same onewire library error.
Your error is reproducible when using / having the pioarduino platform installed (https://github.com/pioarduino/platform-espressif32), which uses Arduino-ESP32 3.x.
Do you really need this for the S3 to work, or for another library to work?
At the regular
platform = espressif32@6.9.0
(uses Arduino-ESP32 2.0.17) a minimal project with all these libraries works fine.
After reading further into the link you provided I found a link that suggested replacing the OneWire_direct_gpio.h in the downloaded library with what is likely a later version. I tried that and it worked for the ESP32 devkit 1. Now onewire compiles correctly on that device.
On the ESP32-S3 I am using the pioarduino platform because I need it to run the bb_spi_lcd library which requires the latest arduino ide version. So, are you saying that onewire will not run with the pioarduino platform?
I’ll try the espressif32@6.9.0 to see if that will work with the libraries I wan to use.
There is a patch for OneWire that makes it work with Arduino-ESP32 3.x: https://github.com/PaulStoffregen/OneWire/pull/149.
You can reference that fixed version of the library by setting
OneWire=https://github.com/promillen/OneWire/archive/refs/heads/patch-1.zip
in the lib_deps
. (You don’t need to do that for ESP32 if you keep platform = espressif32@6.9.0
)
E.g., for the ESP32-S3
(note that I commented out board_build.partitions = no_fs_4MB.csv
because I don’t have that file)
[env:esp32-s3-devkitc-1]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
;build_type = debug
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
;board_build.partitions = default.csv
;board_build.partitions = no_fs_4MB.csv
board_build.debug = 0
board_build.extra_flags =
-DBOARD_HAS_PSRAM
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
lib_deps =
bitbank2/bb_captouch@^1.2.2
bitbank2/bb_spi_lcd@^2.7.1
bodmer/TFT_eSPI @ ^2.3.58
knolleary/PubSubClient@^2.8
sstaub/TickTwo@^4.4.0
gioblu/PJON@^13.0
bblanchon/ArduinoJson@^6.18.5
OneWire=https://github.com/promillen/OneWire/archive/refs/heads/patch-1.zip
mikalhart/Streaming@^1.0.0
milesburton/DallasTemperature@^3.9.1
the minimal src/main.cpp
#include <Arduino.h>
#include <DallasTemperature.h>
#include <Streaming.h>
#include <TickTwo.h>
#include <TFT_eSPI.h>
#include <PJON.h>
#include <ArduinoJson.h>
#include <bb_spi_lcd.h>
#include <bb_captouch.h>
void setup () { }
void loop() { }
will compile fine.
Thanks Max, your speedy help is much appreciated. The project does compile with no issues and the libraries I want to use. I have marked the answer as the solution.
Just FYI, best to keep an eye on the pull request, because if it gets merged into OneWire, then the original branch and forked repo (https://github.com/promillen/OneWire/archive/refs/heads/patch-1.zip
) might be deleted again, by which point you would need to reference https://github.com/PaulStoffregen/OneWire/archive/refs/heads/master.zip
as the library URL.
Of course, you can also circumvent all of this by downloading a copy of the fixed OneWire library into the lib/
folder of the project. That prevents it having a broken build some time down the road again.
Fixing versions of platform and libraries to stable URLs / versions is always a good idea.
Thanks for the extra advice, I tried using platform = espressif32@6.9.0 without the patch and that works too. So, I guess that might be the way to go. I’ll keep a note of both options.
Would the ‘fixed’ version of the library be the one linked as the patch?