Test Setup
I have wired an DS18B20+ to an RPI Pico and used a 4.7K pullup. The RPI Pico is a stand-in for your board. It uses the arduino:mbed_rp2040:pico
core rather than the arduino:mbed_nano:nanorp2040connect
that yours does. However, I'm guessing they're similar enough.
Test result
When I attempt the to use the matmonk DS18B20 library you mention, I see similar pattern on the RPI Pico's onboard LED. Just the attempt to construct the object was sufficient to crash. Construction fairly directly defers to the OneWire library. So, I tried the OneWire library's own example for reading the DS18B20 (with some appropriate modification) and it crashes in the same manner. This lead to searching for and finding issues for the RP2040 on the OneWire github page resulting in (among others) this find. The answer mentions OneWireNG.
Or rather, it's the library that works. But, this is the relevant example for it that works for me. I made the following modifications.
All Serial
usages were replaced with SerialUSB
because I am using the USB connection for the Serial Monitor (well, a terminal emulator).
I changed the one wire object to use GPIO28 because it was conveniently close to the pins where I was picking up 3.3V and GND: OneWire ds(28);
It seems plausible that you could change the #include <DS18B20.h>
usages in the two libraries you cited to #include "OneWireNg_CurrentPlatform.h"
and find that they then work fine. I have not tried this yet. If that's of particular interest to you I will try it and update(Update below). However, this stock example from the OneWireNG library is not crashing and is printing temperatures that rise and fall expected when I manipulate the temperature of the sensor.
OneWireNg with Matmunk and DallasTemperature libraries
In general
It turns out that it is unnecessary to modify libraries that were using the original OneWire, not even just changing the #include
. Despite the OneWireNg example using "OneWireNg_CurrentPlatform.h"
it also provides a OneWire.h header. It is sufficient to have OneWireNg installed but the original OneWire library must uninstalled (or moved out of the libraries directory) so as not to confuse the build process into selecting the original library based on the header name over the OneWireNg library. The OneWireNg authors may have used the OneWireNg specific header in the examples to avoid this problem wit their examples when both libraries were installed. They've gone out of their way to make it compatible with the original, but below are reports of specific tests with the two libraries mentioned anyway.
Matmunk library with OneWireNg
With OneWireNg installed and the original OneWire not installed, the Multiple example form the matmunk library worked with the same minor modifications mentioned before (I used pin 28 rather than 2 and SerialUSB
rather than Serial
). In case your wondering the only reason why I switched from testing Single to Multiple is the latter didn't require that I first find and enter my part's address. That example is printing temperatures that rise and fall in accordance with manipulation of the sensor.
DallasTemperature with OneWireNg
Likewise I tested with the Multiple example from the DallasTemperature library. Same kind of modifications to the example. I changed ONE_WIRE_BUS
to 28
for my setup. I changed Serial
to SerialUSB
. And runs normally and prints expected temperatures under manipulation of the sensor.
begin()
method for DallasTemperature.