DS1820 Helloworld fails when MBED is updated

04 Sep 2016

Hi,

I can easily run my board with the DS1820_Helloworld example. I am using the parasitic power function, the code finds one device and reports 19.2C this morning. Found 1 device(s) Device 0 returns 19.4oC Device 0 returns 19.4oC Device 0 returns 19.4oC Device 0 returns 19.4oC Device 0 returns 19.4oC Device 0 returns 19.4oC

However, if I upgrade MBED then it fails. I have tried MBED.src and MBED.dev but also just upgrading from within the online compiler, all failed.

The hardware now reports "Found 0 device(s)"

The code jumps from 17k to 26k but finds no devices.

#define MULTIPLE_PROBES
#define DATA_PIN        PA_4


#ifdef MULTIPLE_PROBES

#include "mbed.h"
#include "DS1820.h"

#define ESC 0x1B

#define MAX_PROBES      4
 
DS1820* probe[MAX_PROBES];
Serial Usart1(PA_9,  PA_10);        // 115200 

int main() {  
    // Initialize the probe array to DS1820 objects
    
    Usart1.baud(115200);    
    Usart1.printf("%c[2J", ESC); //clear screen

    int num_devices = 0;
    while(DS1820::unassignedProbe(DATA_PIN)) {
        probe[num_devices] = new DS1820(DATA_PIN);
        num_devices++;
        if (num_devices == MAX_PROBES)
            break;
    }
    
    Usart1.printf("Found %d device(s)\r\n\n", num_devices);
    while(1) {
        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        for (int i = 0; i<num_devices; i++)
            Usart1.printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature());
        Usart1.printf("\r\n");
        wait(1);
    }
    
}

#else
#include "mbed.h"
#include "DS1820.h"
 
DS1820 probe(DATA_PIN); 
 
int main() {
    while(1) {
        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        Usart1.printf("It is %3.1foC\r\n", probe.temperature());
        wait(1);
    }
}

#endif
06 Jan 2017

ds18b20 not find devices :(

.

26 Jan 2018

Make shure that you'r using 4K7 PullUp resistor in the DATA line

02 Mar 2018

I have the same problem. The hello world as it is works, but when I try to use the library using mbed-os won't work. Any suggestion?

13 Apr 2018

I've been trying to get this library working for a while too.

I found out that from mbed rev #5571c4ff569f (released 17 Jan 2018) the DS1820 lib stops working - prints Found 0 Devices.

For now I reverted to mbed rev #7130f322cb7e and the example with multiple DS1820 sensors works. However the example with the single DS1820 sensor gives me the Found 0 Devices message. So I tried to change the multiple DS1820 sensors' example by changing the #define MAX_PROBES 16 to #define MAX_PROBES 1. Again, I get the Found 0 Devices message. For now, I'm using the multiple sensors example with MAX_PROBES 2

Also, I tried to use the library with mbed-os, but no luck yet. I'll try running the example with some earlier release versions to see if maybe it stopped working after a certain release.

Oh, and forgot to mention that I'm running this on a Nucleo F070RB board

14 Apr 2018

Ditto

Make sure that you're using 4K7 PullUp resistor in the DATA line

16 Apr 2018

I've got that pull-up on the Data line, so everything should be working fine :/ I was trying to find out what changed between releases that breaks this library. No luck yet..

16 Apr 2018

Domantas Cibas wrote:

I've got that pull-up on the Data line, so everything should be working fine :/ I was trying to find out what changed between releases that breaks this library. No luck yet..

Did you check the code line by line?

I am very interrested in your findings, because my setup didnt work even with that 4k7 pullup resistor. Please post the configuration, when you can. Thanks.

17 Apr 2018

Andras Pal Csokan wrote:

Did you check the code line by line?

I didn't have time to go through the changes between the releases, but that's the idea :)

Andras Pal Csokan wrote:

Please post the configuration, when you can.

I'm using a Windows 10 machine with Ubuntu WSL, and the mbed-CLI to work with mbed projects. My setup is quite straight forward: I create a new mbed project using the mbed new new-program-name --create-only. This will create only the program, and will download the mbed 2.0 SDK tools. Then, I download the mbed build #7130f322cb7e with the command mbed add https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e##.

Finally, I download the DS1820 library with the command mbed add https://os.mbed.com/users/Sissors/code/DS1820/#236eb8f8e73a . It will download the DS1820 library and the LinkedLists library, that is required by this DS1820 lib.

And then I copy/pasted the code for the main.cpp from here: https://os.mbed.com/users/Sissors/code/DS1820_HelloWorld/file/01060b5e01b4/main.cpp/

As I mentioned above, I only got it working with the multiple probes example, when the MAX_PROBES defined is greater than 1.

Hope that helps to get you started! Will share any of my further findings

19 Apr 2018

To me is working when I plug the sensor to 5v as v input, also it is working when I use parasite mode and I don't plug the vin at all.

mbed CLI is not working for me, maybe I have something wrong in my env. Online compiler is working, here is my test https://os.mbed.com/users/javibenjas/code/test_temperature_ds18b20/

I will try with the pull-up resistor.

20 Apr 2018

Javier Perez wrote:

To me is working when I plug the sensor to 5v as v input, also it is working when I use parasite mode and I don't plug the vin at all.

mbed CLI is not working for me, maybe I have something wrong in my env. Online compiler is working, here is my test https://os.mbed.com/users/javibenjas/code/test_temperature_ds18b20/

What board are you using?

20 Apr 2018

Domantas Cibas wrote:

Javier Perez wrote:

To me is working when I plug the sensor to 5v as v input, also it is working when I use parasite mode and I don't plug the vin at all.

mbed CLI is not working for me, maybe I have something wrong in my env. Online compiler is working, here is my test https://os.mbed.com/users/javibenjas/code/test_temperature_ds18b20/

What board are you using?

k22f

25 Apr 2018

Javier Perez wrote:

k22f

This issue must be related to STM boards then, I guess. Because I was testing this on a Nucleo F070RB board

25 Apr 2018

Give this demo a try with your NUCLEO-F070RB board. The schematic is available here.

26 Apr 2018

Zoltan Hudak wrote:

Give this demo a try with your NUCLEO-F070RB board. The schematic is available here.

I'll give it a try, cheers

05 Nov 2018

Did anyone solve it? I'm facing the same problem. Im using a NUCLEO F072. It only works when MBED is not updated. =(

19 Jan 2019

In case any one gets here, K22F target must have some timing anomalies, perhaps other targets too. The timing on the device is constant but different targets and libraries can effect the exact working delay timing. I have been using Erik's library for some time and does work well other than may require slight timing adjustments. It is not possible to overcome this by changing the library only address the situation if it arises when the MBED updates.

I have not found any adverse effect with long cables, mine range from 1 to 15 meters and I have had 8 devices connected.

I tweaked the part below (from 10 to 5) and now I can detect and read multiple devices on the same I/O pin. That was on todays MBED-DEV rev. 187.

For STM I would suggest this MBED-DEV revision as it overcomes the everlasting RTC issue:

https://os.mbed.com/users/maxxir/code/mbed-dev/

It does go back to rev. 177 but does work on STM F103, F401, F446, L152, L476 without timing changes, I've tried them. (that F446 is very fast!!)

DS1820.cpp snip

    bool DS1820::onewire_bit_in(DigitalInOut *pin) {
    bool answer;
    ONEWIRE_OUTPUT(pin);
    pin->write(0);
    ONEWIRE_DELAY_US(3);                 //  DXP modofied from 5
    ONEWIRE_INPUT(pin);
    ONEWIRE_DELAY_US(10);               //   DXP modified from 5  >>>>>>> put this back to 5 on K22F <<<<<<<<<<
    answer = pin->read();
    ONEWIRE_DELAY_US(45);                //  DXP modified from 50
    return answer;
}
20 Jan 2019

Give this library a try. The right sampling moment is now calculated based on the time needed to change the GPIO from output to input.

20 Jan 2019

Zoltan Hudak wrote:

Give this library a try. The right sampling moment is now calculated based on the time needed to change the GPIO from output to input.

Does not work for me. With mbed 2 and NUCLEO-L073RZ and rev 14:b02fa18 of the library.

20 Jan 2019

I have upated the library again. If it doesn't work then run the following test program and let me know the printout.
If delay1 is greater than 10us then you'll probably have to implement a reading method using STM's HAL library.

#include "mbed.h"

DigitalInOut    line(PA_10);
Timer           timer;

int main()
{
    line.output();
    timer.start();
    line.input();
    printf("delay1 = %dus\r\n", timer.read_us());
    timer.reset();
    line.read();
    printf("delay2 = %dus\r\n", timer.read_us());

    while (true) { }
}