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.
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 as compiler will not see this lib till you will change platform to ststm32@~4.5.0 in platform.ini file.
Result:
main.ccp
#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.begin(9600);
ds.begin();
ds.setResolution(9);
Serial.println("Set up done");
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.print("Number of devices found:");
Serial.println(ds.getDeviceCount());
delay(1500);
}
RESULT:
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Number of devices found:2
Number of devices found:2
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).
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. .
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