problem with DS18B20

Posted on
of 2
/ 2
  • I wired the temperature sensor from the set up according to the instructions on , 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;
    //should return an array with one quite a big number, possibly negative. That is your device serial code
    var serialCode =[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 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 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
    var  l = false;
    setInterval(function() {
      l = !l;
    }, 1000);
    setWatch(function() {
      setTimeout(function() {
    }, BTN1, {repeat:true, edge:'rising'});
    var ow = new OneWire(A0);
    var sensor = require("DS18B20").connect(ow);
    id = setInterval(function() {
    }, 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 is not finding any devices? This info could be quite helpful I believe.

  • just checked, 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


    board that work



    /* board that not work



    /* board that work


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

    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

    Stm32f3discovery 2

    Espruino Board 1

    Espruino Board 2

    Espruino Board 3

    Espruino Board 4

    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.



    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",

    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

problem with DS18B20

Posted by Avatar for Kim @Kim