Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Trouble wiring a Dalla 18B20 to Arduino D1 Mini

Trouble wiring a Dalla 18B20 to Arduino D1 Mini

Scheduled Pinned Locked Moved Hardware
23 Posts 6 Posters 3.7k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • zboblamontZ zboblamont

    @sirzlimz I should explain that I have 12 of these devices daisy chained and addressed as a table of chip addresses, the direct power method is reliable and power efficient for such an arrangement, hence my preference.
    If you first check with a multimeter you are getting voltage at the Vdd and DQ pins it will first confirm you don't have a bad contact somewhere.
    Attached is a test script I used to establish chip addresses to a pro-mini, just needs the pin changed at OneWire ds (XX) to suit your own.

    #include <OneWire.h>
    
    // OneWire DS18S20, DS18B20, DS1822 Temperature Example
    //
    // http://www.pjrc.com/teensy/td_libs_OneWire.html
    //
    // The DallasTemperature library can do all this work for you!
    // http://milesburton.com/Dallas_Temperature_Control_Library
    
    OneWire  ds(16);  // on signal pin (a single 4.7K resistor is necessary)
    
    void setup(void) {
      Serial.begin(9600);
    }
    
    void loop(void) {
      byte i;
      byte present = 0;
      byte type_s;
      byte data[12];
      byte addr[8];
      float celsius, fahrenheit;
    
      if ( !ds.search(addr)) {
        Serial.println("No more addresses.");
        Serial.println();
        ds.reset_search();
        delay(250);
        return;
      }
    
      Serial.print("ROM =");
      for( i = 0; i < 8; i++) {
        Serial.write(' ');
        Serial.print(addr[i], HEX);
      }
    
      if (OneWire::crc8(addr, 7) != addr[7]) {
          Serial.println("CRC is not valid!");
          return;
      }
      Serial.println();
    
      // the first ROM byte indicates which chip
      switch (addr[0]) {
        case 0x10:
          Serial.println("  Chip = DS18S20");  // or old DS1820
          type_s = 1;
          break;
        case 0x28:
          Serial.println("  Chip = DS18B20");
          type_s = 0;
          break;
        case 0x22:
          Serial.println("  Chip = DS1822");
          type_s = 0;
          break;
        default:
          Serial.println("Device is not a DS18x20 family device.");
          return;
      }
    
      ds.reset();
      ds.select(addr);
      ds.write(0x44, 1);        // start conversion, with parasite power on at the end
    
      delay(1000);     // maybe 750ms is enough, maybe not
      // we might do a ds.depower() here, but the reset will take care of it.
    
      present = ds.reset();
      ds.select(addr);
      ds.write(0xBE);         // Read Scratchpad
    
      Serial.print("  Data = ");
      Serial.print(present, HEX);
      Serial.print(" ");
      for ( i = 0; i < 9; i++) {           // we need 9 bytes
        data[i] = ds.read();
        Serial.print(data[i], HEX);
        Serial.print(" ");
      }
      Serial.print(" CRC=");
      Serial.print(OneWire::crc8(data, 8), HEX);
      Serial.println();
    
      // Convert the data to actual temperature
      // because the result is a 16 bit signed integer, it should
      // be stored to an "int16_t" type, which is always 16 bits
      // even when compiled on a 32 bit processor.
      int16_t raw = (data[1] << 8) | data[0];
      if (type_s) {
        raw = raw << 3; // 9 bit resolution default
        if (data[7] == 0x10) {
          // "count remain" gives full 12 bit resolution
          raw = (raw & 0xFFF0) + 12 - data[6];
        }
      } else {
        byte cfg = (data[4] & 0x60);
        // at lower res, the low bits are undefined, so let's zero them
        if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
        else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
        else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
        //// default is 12 bit resolution, 750 ms conversion time
      }
      celsius = (float)raw / 16.0;
      fahrenheit = celsius * 1.8 + 32.0;
      Serial.print("  Temperature = ");
      Serial.print(celsius);
      Serial.print(" Celsius, ");
      Serial.print(fahrenheit);
      Serial.println(" Fahrenheit");
    }
    
    

    Hopefully it will help...

    SirZlimzS Offline
    SirZlimzS Offline
    SirZlimz
    wrote on last edited by
    #14

    @zboblamont So I'm looking for voltage across Vdd and DQ, or from ground to each? I have between 4.6-5V between Vdd and ground, and 3.something from Vdd to DQ I believe. Sorry, trying to recall from last night when I checked. I'll give that code a try tonight.

    zboblamontZ H 2 Replies Last reply
    0
    • SirZlimzS SirZlimz

      @zboblamont So I'm looking for voltage across Vdd and DQ, or from ground to each? I have between 4.6-5V between Vdd and ground, and 3.something from Vdd to DQ I believe. Sorry, trying to recall from last night when I checked. I'll give that code a try tonight.

      zboblamontZ Offline
      zboblamontZ Offline
      zboblamont
      wrote on last edited by
      #15

      @sirzlimz All you are establishing is that the device has voltages on both Vdd and DQ relative to it's ground pin so you know the jumpers you are using to the breadboard are working as they should (faulty ones are not unknown :) ). It does not mean the chip is working, only that the conditions are correct electrically where it should be able to 'talk' to your processor.

      The only aspect left should be the sketch and libraries referenced, although a faulty processor or even a faulty pin of a processor is not entirely unknown.
      If the sketch works, fine, at least you will be talking to the device, and you can then figure out the why from that point, good luck...

      1 Reply Last reply
      0
      • SirZlimzS SirZlimz

        @zboblamont So I'm looking for voltage across Vdd and DQ, or from ground to each? I have between 4.6-5V between Vdd and ground, and 3.something from Vdd to DQ I believe. Sorry, trying to recall from last night when I checked. I'll give that code a try tonight.

        H Offline
        H Offline
        hard-shovel
        wrote on last edited by
        #16

        @sirzlimz It may be stating the obvious but the photo shown is not a arduino processor but a ESP8266.
        Therefore the I/O pins listed in the sketch refer to the GPIO pin number on the ESP8266.
        So if PIN 2 is listed in the Sketch it refers to GPIO2 which is the pin marked D4 on the D1 mini module..

        The photo shows the Data jumper connected to D2, So trying moving this to D4 with the original sketch.

        SirZlimzS 1 Reply Last reply
        3
        • H hard-shovel

          @sirzlimz It may be stating the obvious but the photo shown is not a arduino processor but a ESP8266.
          Therefore the I/O pins listed in the sketch refer to the GPIO pin number on the ESP8266.
          So if PIN 2 is listed in the Sketch it refers to GPIO2 which is the pin marked D4 on the D1 mini module..

          The photo shows the Data jumper connected to D2, So trying moving this to D4 with the original sketch.

          SirZlimzS Offline
          SirZlimzS Offline
          SirZlimz
          wrote on last edited by
          #17

          @hard-shovel you are definitely not stating the obvious. As originally stated, I'm a complete noob at this stuff and I'm not aware of what all these acronyms mean yet haha I'll definitely have to remember that in the future when looking up pinouts and the like. I will let you know how this goes! Thanks again for all your help!

          H 1 Reply Last reply
          1
          • SirZlimzS SirZlimz

            @hard-shovel you are definitely not stating the obvious. As originally stated, I'm a complete noob at this stuff and I'm not aware of what all these acronyms mean yet haha I'll definitely have to remember that in the future when looking up pinouts and the like. I will let you know how this goes! Thanks again for all your help!

            H Offline
            H Offline
            hard-shovel
            wrote on last edited by
            #18

            @sirzlimz I have just tried this circuit out myself on a D1 module and the using the library listed from milesburton it does not work on the ESP8266 in parasitic mode.
            If you move the jumper over for powered mode it will work fine.

            Trying on an Arduino nano with the same device and breadboard it works fine in both modes.

            So testing again and reading the data sheet on the DS18B20 and the section on "Powering the DS18B20" page 7 some insight can be obtained.

            Anyway a quick fix is to put another 4.7K resistor in parallel with the first and the system should work with one sensor,

            so two possible ways of connection are shown

            Powered Mode with the Jumper to 5V, Recommended method, I always power my DS18B20's
            This works with multiple devices, (I have just tried with 10 devices on the D1 [with multiple device sketch])
            0_1520624348000_IMG_3652.JPG

            Parasitic Mode with two 4.7K resistors (this trick only works with one device on the bus)
            0_1520624437698_IMG_3653.JPG

            SirZlimzS P 3 Replies Last reply
            3
            • H hard-shovel

              @sirzlimz I have just tried this circuit out myself on a D1 module and the using the library listed from milesburton it does not work on the ESP8266 in parasitic mode.
              If you move the jumper over for powered mode it will work fine.

              Trying on an Arduino nano with the same device and breadboard it works fine in both modes.

              So testing again and reading the data sheet on the DS18B20 and the section on "Powering the DS18B20" page 7 some insight can be obtained.

              Anyway a quick fix is to put another 4.7K resistor in parallel with the first and the system should work with one sensor,

              so two possible ways of connection are shown

              Powered Mode with the Jumper to 5V, Recommended method, I always power my DS18B20's
              This works with multiple devices, (I have just tried with 10 devices on the D1 [with multiple device sketch])
              0_1520624348000_IMG_3652.JPG

              Parasitic Mode with two 4.7K resistors (this trick only works with one device on the bus)
              0_1520624437698_IMG_3653.JPG

              SirZlimzS Offline
              SirZlimzS Offline
              SirZlimz
              wrote on last edited by
              #19

              @hard-shovel Awesome, I'm excited to try this with my own setup when I get home. Thanks for explaining those nuances. I'm sure there will be many more stumbles as I get more into this stuff. There aren't really any "how to get started" guides for folks who aren't already programmers and electrical engineers (at least I haven't found any). I see a lot of copy/pasta in my future!

              1 Reply Last reply
              0
              • H hard-shovel

                @sirzlimz I have just tried this circuit out myself on a D1 module and the using the library listed from milesburton it does not work on the ESP8266 in parasitic mode.
                If you move the jumper over for powered mode it will work fine.

                Trying on an Arduino nano with the same device and breadboard it works fine in both modes.

                So testing again and reading the data sheet on the DS18B20 and the section on "Powering the DS18B20" page 7 some insight can be obtained.

                Anyway a quick fix is to put another 4.7K resistor in parallel with the first and the system should work with one sensor,

                so two possible ways of connection are shown

                Powered Mode with the Jumper to 5V, Recommended method, I always power my DS18B20's
                This works with multiple devices, (I have just tried with 10 devices on the D1 [with multiple device sketch])
                0_1520624348000_IMG_3652.JPG

                Parasitic Mode with two 4.7K resistors (this trick only works with one device on the bus)
                0_1520624437698_IMG_3653.JPG

                SirZlimzS Offline
                SirZlimzS Offline
                SirZlimz
                wrote on last edited by
                #20

                @hard-shovel It worked! I used pin 4 on the D1 Mini and did direct power and i'm reading temps now! Thank you so much! One final question about the pinouts. Is there some kind of guide that you know of to determine which pins to use? i.e. how did you know how to use pin 4 on the D1 Mini but keep 2 specified in the sketch? Please ELI5.

                H 1 Reply Last reply
                3
                • SirZlimzS SirZlimz

                  @hard-shovel It worked! I used pin 4 on the D1 Mini and did direct power and i'm reading temps now! Thank you so much! One final question about the pinouts. Is there some kind of guide that you know of to determine which pins to use? i.e. how did you know how to use pin 4 on the D1 Mini but keep 2 specified in the sketch? Please ELI5.

                  H Offline
                  H Offline
                  hard-shovel
                  wrote on last edited by
                  #21

                  @sirzlimz There are lots of pinout diagrams on the web like below.

                  For the the arduino use the GPIO number as the pin number

                  ie
                  GPIO5 --- marked D1 in Arduino IDE use 5
                  GPIO13-marked D7

                  0_1520633752967_esp8266-wemos-d1-mini-pinout.png

                  1 Reply Last reply
                  3
                  • H hard-shovel

                    @sirzlimz I have just tried this circuit out myself on a D1 module and the using the library listed from milesburton it does not work on the ESP8266 in parasitic mode.
                    If you move the jumper over for powered mode it will work fine.

                    Trying on an Arduino nano with the same device and breadboard it works fine in both modes.

                    So testing again and reading the data sheet on the DS18B20 and the section on "Powering the DS18B20" page 7 some insight can be obtained.

                    Anyway a quick fix is to put another 4.7K resistor in parallel with the first and the system should work with one sensor,

                    so two possible ways of connection are shown

                    Powered Mode with the Jumper to 5V, Recommended method, I always power my DS18B20's
                    This works with multiple devices, (I have just tried with 10 devices on the D1 [with multiple device sketch])
                    0_1520624348000_IMG_3652.JPG

                    Parasitic Mode with two 4.7K resistors (this trick only works with one device on the bus)
                    0_1520624437698_IMG_3653.JPG

                    P Offline
                    P Offline
                    Prakhar Birla
                    wrote on last edited by
                    #22

                    @hard-shovel Parasitic power mode uses only two wires i.e. Data & GND, the sensor "parasitically" takes power from the Data line. In the second picture, VCC is connected as well so it might not be the parasitic power mode.

                    H 1 Reply Last reply
                    0
                    • P Prakhar Birla

                      @hard-shovel Parasitic power mode uses only two wires i.e. Data & GND, the sensor "parasitically" takes power from the Data line. In the second picture, VCC is connected as well so it might not be the parasitic power mode.

                      H Offline
                      H Offline
                      hard-shovel
                      wrote on last edited by
                      #23

                      @prakhar-birla Please explain how the DS18B20 will not be parasitic mode when it only has GND connected on pins 1 and 3 and data (with pull-up) on pin 2?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      10

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular