You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For certain boards (e.g. Arduino Nano ESP32), the Arduino functions (e.g. pinMode()) apply a remapping to match the pin labels printed on the board. However, this remapping is not considered by low-level functions used e.g. by OneWire. This causes the lib to not work properly when used with one of those boards.
For example, the pin labeled with D5 is actually connected to GPIO pin 8. This pin is accessed using Arduino function with 5, e.g. pinMode(5, INPUT) will configure D5 as input pin. But when using low-level functions, the pin needs to be addressed using 8.
This behavior can be disabled by setting "Pin Numbering" to "By GPIO number (legacy)" in the Tools menu in the Arduino IDE or adding -DBOARD_USES_HW_GPIO_NUMBERS to the build flags (e.g. in Platform IO). But by default, it is enabled, and thus OneWire doesn't work correctly.
I suggest to either apply the same pin remapping that is used by the Arduino functions, e.g. by using gpio_pin = digitalPinToPort(arduino_pin); or at least raise a compile time error if remapping is enabled, which can be detected using #if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS).
Description
For certain boards (e.g. Arduino Nano ESP32), the Arduino functions (e.g.
pinMode()
) apply a remapping to match the pin labels printed on the board. However, this remapping is not considered by low-level functions used e.g. by OneWire. This causes the lib to not work properly when used with one of those boards.For example, the pin labeled with D5 is actually connected to GPIO pin 8. This pin is accessed using Arduino function with
5
, e.g.pinMode(5, INPUT)
will configure D5 as input pin. But when using low-level functions, the pin needs to be addressed using8
.This behavior can be disabled by setting "Pin Numbering" to "By GPIO number (legacy)" in the Tools menu in the Arduino IDE or adding
-DBOARD_USES_HW_GPIO_NUMBERS
to the build flags (e.g. in Platform IO). But by default, it is enabled, and thus OneWire doesn't work correctly.I suggest to either apply the same pin remapping that is used by the Arduino functions, e.g. by using
gpio_pin = digitalPinToPort(arduino_pin);
or at least raise a compile time error if remapping is enabled, which can be detected using#if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS)
.References:
https://forum.arduino.cc/t/unable-to-get-ds18b20-to-read-on-nano-esp32/1165044
https://forum.arduino.cc/t/solved-ds18b20-not-working-reliably-on-nano-esp32/1320253
Steps To Reproduce Problem
pinMode(8, INPUT)
which is remapped to a wrong pinHardware & Software
Board: Arduino Nano ESP32
Shields / modules used: DS18B20 temperature sensor
Arduino IDE version: 2.3.3
Plattform IO version: 6.1.16
OneWire version: 2.3.8
DallasTemperature version: 3.9.0
Operating system & version: Ubuntu 22.04
Arduino Sketch
Not working variant:
Working variant:
Errors or Incorrect Output
In the not working version, the output is
In the working version, the output is
The text was updated successfully, but these errors were encountered: