OneWire devices not found when using platformio

When I compile and upload the “Multiple” example sketch from the Arduino DallasTemperature library using the Arduino IDE, my DS18B20 temperature sensors work fine. If I upload the same sketch with PlatformIO, no sensors are detected.

I have no idea what is going on… As long as the issue persists I will be forced to ditch PlatformIO for the regular Arduino IDE.

You get no error or missing library message at all? Sometimes I include <Arduino.h> just to force it…

Have you tried other pin numbers? Pin numbers may differ in platformio!
#define ONE_WIRE_BUS 2

I found out that I need to change code regularly to work within platformio while it works as-is from the Arduino IDE. I also have one sensor I cannot get working at all and it works fine with the Arduino IDE. So for 80% of my projects I get away with this MUCH better IDE but sometimes I still need the Arduino IDE.

I’m having the same problem. The identical code works when compiled and uploaded via the Arduino IDE and fails when compiled and uploaded with PlatformIO. Made sure to use the same library on both. No luck.

EDIT: Seems to have something to do with threads. When I scan the bus from the main setup/loop there’s no problem. I suspect the DallasTemperature library is also using a separate thread to do its work as well and this may be the root issue.

1 Like

After few hours of searching I found something.

I’m using stm32 board (STM32F104C8) it has OneWireSTM library in framework-arduinoststm32 package.
So to use it you have to manually edit DallasTemperature to include OneWireSTM.h, but it is not everything :frowning: as compiler will not see this lib till you will change platform to ststm32@~4.5.0 in platform.ini file.

build_flags=-D STM32_OFFICIAL_CORE
platform = ststm32@~4.5.0
board = genericSTM32F103C8
framework = arduino
upload_protocol = serial
upload_port = COM3


#include <inttypes.h>
#include <OneWireSTM.h>

// Model IDs
#define DS18S20MODEL 0x10 
#include <Arduino.h>
#include <OneWireSTM.h>
#define REQUIRESALARMS false
#include <DallasTemperature.h>

OneWire bus(PB9);
DallasTemperature ds(&bus);
void setup()
  // put your setup code here, to run once:
  Serial.println("Set up done");

void loop()
  // put your main code here, to run repeatedly:

  Serial.print("Number of devices found:");


--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Number of devices found:2
Number of devices found:2

I have same problem.
Device NodeMcu v3 use DS18B20 sensors no D2 port (GPI04)


platform = espressif8266
board = nodemcuv2
framework = arduino


#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define esp_birate 9600
#define one_wire_bus D2 // also try one_wire_bus 4 as GPI04

OneWire oneWire(one_wire_bus);
DallasTemperature sensors(&oneWire);

void setup() {

void loop() {
  Serial.print("Numbers of devices found: " + String(sensors.getDS18Count()) + "\n");

Serial Monitor:
Numbers of devices found: 0

And the same code using Arduino IDE produces what output?

1 Like

Do you have the pullup resistor on D2/GPIO2? 4.7k is the typically recommended value, but I’ve found in some instances lower values like 2.2k has worked better with the 3.3v ESP8266 stuff.

I’m also seeing this issue and cannot understand why it happens - I’ve even tried copying the core files from Arduino IDE into Platformio and vice-versa but the result is the same.

A workaround exists, however - either downgrade to OneWire v2.3.2 or “search” for the OneWire devices twice (e.g. if using the DallasTemperature library, call begin() twice).

This is also discussed here: DS18B20 always reading 85 or -127 · Issue #253 · platformio/platform-espressif32 · GitHub

Hi @photomoose,

I saw your code on the link you provided above. I don’t see a `#include “Arduino.h” anywhere, is there one? I think there should be, and possibly more.

The Arduino IDE goes through various hoops to identify any header files not explicitly included in the sketch. Under PlatformIO, it is your responsibility.

Arduino.h is needed when using the Arduino framework, setup() and loop(). It might be that including that file will pull in some configuration that the ESP needs? I don’t have one, so I’m not sure.

Having said/typed that, I’m pretty sure there would be compilation errors, but you never know.

It probably doesn’t explain why the ESP needs to begin() twice to find devices. :frowning_face:.

Good luck.


Hi @NormanDunbar,

Yes, when compiling/uploading with Platformio, I can confirm that the very first line was the include statement for Arduino.h.

It’s looks like some sort of weird behaviour between the version of the OneWire library and Platformio:

Arduino IDE + OneWire v2.3.5 —> works OK
Platformio + OneWire v2.3.5 —> does not work, requires two calls to begin()

Arduino IDE + OneWire v.2.3.2 --> works OK
Platformio + OneWire v.2.3.2 --> works OK

For what platformio.ini and example code exactly does this behavior occur? We can do a binary difference analysis…

Also please mention the Arduino IDE version and Arduino IDE platform / board package version (e.g. for AVR or ESP8266) that is being used here.

Hello again @photomoose,

I figured it was a long shot, but I had to ask!



platform = espressif32
board = featheresp32
framework = arduino
upload_port = /dev/cu.SLAB_USBtoUART
upload_speed = 921600
lib_deps =


#include <Arduino.h>
#include <OneWire.h>

OneWire oneWire(21);

void search() {
    uint8_t count = 0;

    Serial.println("Searching for devices...");
    byte deviceAddress[8];

    while ( {
        Serial.print("Found Device:");
        for (int i = 0; i < 8; i++) {
            Serial.write(' ');
            Serial.print(deviceAddress[i], HEX);


    Serial.printf("Found %d devices\r\n", count);

void setup() {


    // First call returns 0 devices when using Platformio

    // Second call works

void loop() {

Arduino IDE: v1.8.10
Board: Adafruit ESP32 Feather

Using board 'featheresp32' from platform in folder: /Users/photomoose/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4
Using core 'esp32' from platform in folder: /Users/photomoose/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4