DS18B20 and (BLE or anything else)

Posted on
  • Is there any way to get OneWire and BLE reliably work together?
    Using a Pixl with 2v08.188, have three DS18B20 attached to A0. If Bluetooth is connected, mostly only 0 or 1 sensor are detected, and there are a bunch of null values returned when reading temperature.
    Tested with Pixl on serial, and with an Espruino Wifi, and all sensors are detected, and almost no null values returned.

    If I'm right, OneWire is done in software, and I assume BLE communication is interfering with that, right? Is there anything that could improve? Do the coding, and disconnect & disable BLE to run the code?

    And other question: Assuming I'm not using BLE while running the code, what are my chances of reading multiple DS18B20 and reading accelerometer and writing to SD card together? Ok, let's just try it :D

    Code is below:

    var ow = new OneWire(A0);
    //R: VCC, G: Gnd, Y: Data
    var sensors = [];
    function scan(){ sensors = ow.search().map(function (device) {  return require("DS18B20").connect(ow, device);}); }
    setInterval(function() {
      sensors.forEach(function (sensor, index) {
        sensor.getTemp(function (temp) {
          console.log(index, sensor.sCode, ": " + temp + "°C");
        });
      });
    }, 1000);
    
    setTimeout(scan, 1234);
    
  • Is there any way to get OneWire and BLE reliably work together?

    You're right - it's bluetooth jumping in and messing up the timings. It's a bit tricky in that the Bluetooth tasks are high enough priority that I don't believe I can interfere with them, and OneWire pretty much all has to be done in software. I did have a look a while back but didn't see much of a solution available.

    However what you're likely hitting is that when you have a BLE connection, normally if you've used it in the last minute it's in high-bandwidth mode. That means 7.5ms connection internal. If you force it to something slower with NRF.setConnectionInterval(200) then you can keep a connection open while making OneWire issues much less of a problem.

    It's also worth noting that nothing stops you just calling getTemp again if you get null the first time. The only one that really causes you problems is if ow.search() fails at startup (so you need to check that call it again as well).

    If you don't have a connection open and just want to advertise, you could use NRF.sleep() and NRF.wake() to stop advertising while you use OneWire.

    what are my chances of reading multiple DS18B20 and reading accelerometer and writing to SD card together?

    I think that'd all be fine - just depends how fast you want to do it!

  • Thanks Gordon!

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

DS18B20 and (BLE or anything else)

Posted by Avatar for AkosLukacs @AkosLukacs

Actions