problem with DS18B20

Posted on
Page
of 2
/ 2
Next
  • I wired the temperature sensor from the set up according to the instructions on http://www.espruino.com/DS18B20 , but all it returns is null. Nothing really that I can add as I've redone the wiring twice (power to 3.3V, ground to GND, data to A1, 4.7k resistor connecting power and data).

  • I use A0, and it works fine.
    blk -> gnd, red -> 3v3, wht -> A0 and 3v3 -> 4k7 -> A0

  • If you are using breadboard make sure that the data wire is connected between the resistor and sensor, or in other words that the resistor is not on the way between espruino and thermometer.

  • That is exactly how it is wired up. I didn't know about the resistor though, but even changing the position doesn't change the result of null.

    I changed boards though, to one with 1v43 on it, and then it magically works ... can you confirm the firmware version of your board?

  • Ok, I just verified my assumption.

    All wiring as is, I flashed older versions onto the board. Using 1v46 and 1v45 prevents me from reading the signal. Going back to 1v43 and the temperature is measured just fine.

  • I am running the latest 1V46

  • very odd ... it is reproducible though: if I flash 1v46 on there it all stops, and if I go back to 1v43 again the thermometer once again works ...

  • @Kim are you loading this module via the WebIDE or is it just copy+paste (the module itself)?

    I have just tried with the latest 1v47 build and the example code works fine, but I'm using HY board and not official Espruino.

    After uploading the example code could you please try to clearInterval() and then

    ow.search();
    //should return an array with one quite a big number, possibly negative. That is your device serial code
    
    var serialCode = ow.search()[0];
    serialCode - ((serialCode >> 8) << 8);
    //should return 40 which is a family code for DS18B20
    

    And sorry for the ugly code formatting, I don't really get how it works on this forum.

  • Oh and I should have add that I'm using this module for quite a long time now as it's the core for my project and I did not have any issues on previous firmware versions. But then the module itself has also changed in the meantime so it's hard to tell.

    Could you also give me the output of `process.env so I can try with the exact same version of firmware that you are using.

  • As far as I understand, DS18B20 is a serial device and A1/A0 are not serial ports, they are PMW/ADC, at least on Espruino Board.
    Anyway, on my Espruino I tested same with port B7, and its not working.
    Search failes to find the sensor.
    Upgraded to 1v46 did not help.
    Downgraded to 1v43 (r1.3) and it works, at least search works and I get a device back.
    But 1V43 seems to have problems somewhere around "this", get an error that EOF was found where } was expected (???)
    So this is not a solution for the problem.

  • @JumJum could you give me the exact version (build date) so I can flash my board with it and see what happens?

  • @graf don't worry about the code formatting, it's fine :).
    I tried the things you requested, and I got the following results:

    with version 1v43
    I indeed get 40 as a result, and the sensor is working as expected.
    The result of process.env is

    ={"VERSION":"1v43","BUILD_DATE":"Dec 10 2013","BUILD_TIME":"11:59:35","BOARD":"E­SPRUINOBOARD","CHIP":"STM32F103RCT6","CH­IP_FAMILY":"STM32F1","FLASH":262144,"RAM­":49152}
    

    with version 1v46
    ow.search returns [], thus the result of the next queries is undefined and 0. The result of process.env is

    ={"VERSION":"1v46","BUILD_DATE":"Jan 24 2014","BUILD_TIME":"17:28:16","BOARD":"E­SPRUINOBOARD","CHIP":"STM32F103RCT6","CH­IP_FAMILY":"STM32F1","FLASH":262144,"RAM­":49152}
    
  • Thanks. Just tried with 1v46 build on 24th January and it works fine, including on ADC/PWM pin. But again, I'm not using the official Espruino board. This can be helpful to Gordon.

    Also in your case OneWire.search() fails to find the device so all I know it's not a problem with the module. Unfortunately it doesn't help you much.. :)

  • I wonder wich board is @Frida using?

  • I am using rev. 1.3b that arrived on friday and my env is:

    {"VERSION":"1v46","BUILD_DATE":"Jan 24 2014","BUILD_TIME":"17:28:16","BOARD":"E­SPRUINOBOARD","CHIP":"STM32F103RCT6","CH­IP_FAMILY":"STM32F1","FLASH":262144,"RAM­":49152}
    
    // ds18b20
    // sig white
    // 3v3 red
    // gnd black
    // 3530822130496018984
    
    clearInterval();
    
    LED1.reset();
    LED2.reset();
    LED3.reset();
    
    var  l = false;
    setInterval(function() {
      l = !l;
      LED1.write(l);
    }, 1000);
    
    setWatch(function() {
      LED2.set();
      clearInterval(id);
      setTimeout(function() {
        LED2.reset();
      },2000);
    }, BTN1, {repeat:true, edge:'rising'});
    
    setBusyIndicator(LED3);
    
    var ow = new OneWire(A0);
    var sensor = require("DS18B20").connect(ow);
    id = setInterval(function() {
      console.log(sensor.getTemp());
    }, 1000);
    

    and that is my code

  • Just tried yours on my Espruino 1.3b, env is exactly the same.
    copied code, switched to 3.3V(was 5V before) and get no temperature, get null only.

  • It is weird. After I updated to 1v46, I done a reset() and a save() before I loaded and run the code.

  • @JumJum just to clarify, could you also confirm that in this last case ow.search() is not finding any devices? This info could be quite helpful I believe.

  • just checked, ow.search returns nothing
    Tried on A0 / A1 / B6 / B7, all the same
    With 1v43 I got an ID on B6 / B7

  • I have tried the other 3 boards I have, and 2 of them does not work either.
    I have tried a timing loop, and there are almost 1% in difference, between the board that work, and the board that not work.
    /* board that not work

    echo(0);
    1222.878175000000055661
    1224.138924999999971987
    =undefined

    /
    /
    board that work
    echo(0);
    7.64065
    8.912875
    =undefined

    */
    CODE
    clearInterval();
    clearWatch();

    print(getTime());
    for(i=0;i<10000;i++);
    print(getTime());
    END CODE


    /* board that not work
    sensor
    ={"bus":{"pin":A0},"sCode":undefined}

    7.34425
    7.34925

    */

    /* board that work
    sensor
    ={"bus":{"pin":A0},"sCode":3530822130496­018984}

    9.21675
    9.2449

    The timing here are before, and after the require.
    CODE
    print(getTime());
    var sensor = require("DS18B20").connect(ow);
    print(getTime());
    END CODE


    Maybe it has something with the timing to do.

  • @Frida, great job and good point.
    I will check my other boards next week, but have to solder them first

  • Stm32f3discovery 1
    106.5475338966%

    Stm32f3discovery 2
    105.9924543132%

    Espruino Board 1
    100%

    Espruino Board 2
    99.2454313225%

    Espruino Board 3
    98.9703281588%

    Espruino Board 4
    97.6832383572%

    With Espruino Board 1 as a reference, I can se that my discovery board's are a lot slower, and my espruino Board 2..4 are faster.

    And the DS18B20, that came with the kit, can run on my discovery, but my other DS18B20, can't run on the espruino's.

    It is tested with the following code.

    CODE
    clearInterval();
    clearWatch();

    print(getTime());
    for(i=0;i<10000;i++);
    print(getTime());
    END CODE

    I think we need a variable or something so we can adjust the time.

  • Argh. I'll have a look at this later today. So you're saying that some 1v46 Espruino Boards work and some don't?

    This is almost certainly an issue with the switch to using the RTC. OneWire support uses software to produce/read the signal. On startup the Espruino calibrates itself against the RTC but perhaps the internal oscillator hasn't settled down enough to produce an accurate reading at that point.

    @Frida: Sadly the internal RC oscillator used for the RTC is only ~2% accurate. I've been looking at ways to calibrate it using the high speed oscillator as a guide, but that's relatively low priority at the moment.

    Sorry about this - I actually gave a talk using the DS18B20 and the latest version of Espruino on wednesday, so I'm amazed this didn't come up then.

  • No problem, I got my espruino's Friday, and my discovery works.

  • @Gordon
    Now all 4 board's with both DS18B20, works with this rev.

    {"VERSION": "1v47", "BUILD_DATE": "January 27 2014","BUILD_TIME":"15:40:43",
    "BOARD":"ESPRUINOBOARD","CHIP":"STM32F10­3RCT6",
    "CHIP_FAMILY":"STM32F1","FLASH":262144,"­RAM":49152}
    

    I saw it with github, and it worked, changed path to the EABI, did a make and a make serialflash, you are the man of the day.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

problem with DS18B20

Posted by Avatar for Kim @Kim

Actions