Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error ds18b20 with esp32 #57

Open
smacyas opened this issue Apr 23, 2018 · 5 comments
Open

Error ds18b20 with esp32 #57

smacyas opened this issue Apr 23, 2018 · 5 comments

Comments

@smacyas
Copy link

smacyas commented Apr 23, 2018

After using the latest Arduino-esp32 there is a problem with ds18b20

Device is preset on the bus, bur ROM data error

espressif/arduino-esp32#1335

@paulvha
Copy link

paulvha commented Dec 27, 2018

I found to have the same issue however ONLY THE FIRST time around after reset/reboot. The ESP32 library is using the fastmicroseconds() as mentioned in expressif link above. To get around that the IRAM_ATTR had to be added. As I use the library on different boards and want to keep one source the following 3 changes can be applied:

in Onewire.h (around line 99)
// Write a bit. The bus is always left powered at the end, see
// note in write() about that.
#if defined (ARDUINO_ARCH_ESP32)
void IRAM_ATTR write_bit(uint8_t v);
#else
void write_bit(uint8_t v);
#endif

// Read a bit.

#if defined (ARDUINO_ARCH_ESP32)
uint8_t IRAM_ATTR read_bit(void);
#else
uint8_t read_bit(void);
#endif

in onewire.cpp (around line 204):
change
void OneWire::write_bit(uint8_t v)
to
#if defined(ARDUINO_ARCH_ESP32)
void IRAM_ATTR OneWire::write_bit(uint8_t v)
#else
void OneWire::write_bit(uint8_t v)
#endif

in onewire.cpp (around line 236)
change
uint8_t OneWire::read_bit(void)
to
#if defined(ARDUINO_ARCH_ESP32)
uint8_t IRAM_ATTR OneWire::read_bit(void)
#else
uint8_t OneWire::read_bit(void)
#endif

@eos1d3
Copy link

eos1d3 commented Jul 8, 2019

I can confirm the problem for the first incorrect reading when using ESP32. It has been so long that the bug is still there. And the above fixes the problem.

@dlcflv
Copy link

dlcflv commented May 13, 2020

it works! I lost a day trying to understand why the "OneWireSerch" example does not work (it puts the search function in the setup, therefore it is performed only once after the reset, therefore ESP32 does not execute it)
why not integrate it in the official library?

@tysonmatanich
Copy link

tysonmatanich commented Feb 7, 2022

The solution offered in milesburton/Arduino-Temperature-Control-Library#168 (comment) works for me. Tested with 1, 2 and 3 sensors. A bit of a hack having to call sensors.begin() twice.

sensors.begin();
sensors.begin();

Used the same wiring setup as milesburton/Arduino-Temperature-Control-Library#85 (comment) on an ESP32­-PICO­-MINI-­02

EDIT: I contacted Maxim Integrated (manufacture of DS18B20 sensor) and found out my sensors are counterfeit, not sure if this is why they require the extra call or if the legit ones also have the same issue.

@blazoncek
Copy link

@PaulStoffregen could you merge one of the (similar) PRs addressing this issue on (multicore?) ESP32?
I've verified with several instances that using IRAM_ATTR solves any issue that I had using OneWire on ESP32 regarding reading bus data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants