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. About DS18B20 onewire.

About DS18B20 onewire.

Scheduled Pinned Locked Moved Hardware
dallasone wireonewireds18b20
48 Posts 5 Posters 12.4k Views 10 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.
  • F Offline
    F Offline
    flopp
    wrote on last edited by
    #6

    First test with 3 temps is still OK.
    Second test is with 9 temps is still OK.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      flopp
      wrote on last edited by
      #7

      I have now 2 nodes, one with 27 temps, second with 17 temps.

      working with out problems since I started them 1 weeks ago

      I had some problem when adding more sensors, some of them seems not to work together that is why I have 2 nodes

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomasandersson
        wrote on last edited by
        #8

        How can I get this to work with 2.0 or 2.1.1
        I would so much have to help because I am a beginner

        rejoe2R 1 Reply Last reply
        0
        • T tomasandersson

          How can I get this to work with 2.0 or 2.1.1
          I would so much have to help because I am a beginner

          rejoe2R Offline
          rejoe2R Offline
          rejoe2
          wrote on last edited by
          #9

          @tomasandersson Did some work wrt. this some time ago, sketches for MySensors 2.0+ are available here: https://github.com/rejoe2/MySensors-Dallas-Address-ChildID-Consistency.

          Easiest to use may be the "stored id"-Version, based on a concept of leodesigner. This is designed für max. 20 DS18x20.

          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

          T 1 Reply Last reply
          1
          • rejoe2R rejoe2

            @tomasandersson Did some work wrt. this some time ago, sketches for MySensors 2.0+ are available here: https://github.com/rejoe2/MySensors-Dallas-Address-ChildID-Consistency.

            Easiest to use may be the "stored id"-Version, based on a concept of leodesigner. This is designed für max. 20 DS18x20.

            T Offline
            T Offline
            tomasandersson
            wrote on last edited by
            #10

            @rejoe2
            Thanks
            I have now tried the stored ID "version and it works much better than the previous.
            I still get the wrong values sometimes. Wonder if there is control domoticz which mixes the ID.

            0_1490085476002_Skärmavbild 2017-03-21 kl. 09.34.34.png

            rejoe2R 1 Reply Last reply
            0
            • T tomasandersson

              @rejoe2
              Thanks
              I have now tried the stored ID "version and it works much better than the previous.
              I still get the wrong values sometimes. Wonder if there is control domoticz which mixes the ID.

              0_1490085476002_Skärmavbild 2017-03-21 kl. 09.34.34.png

              rejoe2R Offline
              rejoe2R Offline
              rejoe2
              wrote on last edited by
              #11

              @tomasandersson I really doubt the controller to mix things up, nor the node doing so.
              What are the absolute values of the measured temperatures? The "faulty" values seem to be more or less identical, so this could indicate powering problems or may be related to cabeling or resistor size. Did you stick to the 30 seconds intervall or something else?
              Normally 750ms for conversion should be enought, but official (according to datasheet) seem to be a little longer, so trying to change line 69 may help: conversionTime = 1000 / (1 << (12 - resolution));).

              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

              T 1 Reply Last reply
              0
              • rejoe2R rejoe2

                @tomasandersson I really doubt the controller to mix things up, nor the node doing so.
                What are the absolute values of the measured temperatures? The "faulty" values seem to be more or less identical, so this could indicate powering problems or may be related to cabeling or resistor size. Did you stick to the 30 seconds intervall or something else?
                Normally 750ms for conversion should be enought, but official (according to datasheet) seem to be a little longer, so trying to change line 69 may help: conversionTime = 1000 / (1 << (12 - resolution));).

                T Offline
                T Offline
                tomasandersson
                wrote on last edited by
                #12

                @rejoe2
                I will try to change.
                Here is a picture where you see that the sensor ID picks temperature of another sensor0_1490096020397_Skärmavbild 2017-03-21 kl. 12.31.12.png

                rejoe2R 1 Reply Last reply
                0
                • T tomasandersson

                  @rejoe2
                  I will try to change.
                  Here is a picture where you see that the sensor ID picks temperature of another sensor0_1490096020397_Skärmavbild 2017-03-21 kl. 12.31.12.png

                  rejoe2R Offline
                  rejoe2R Offline
                  rejoe2
                  wrote on last edited by
                  #13

                  @tomasandersson This really looks strange.
                  Some additional remarks:

                  • Some values represent also failure codes, beside -127°, 85° (C), which are already filtered out by code I also suspect 0° to be one of these. This is the backgound of me asking above for absolute figures.
                  • There seem to be also fake chips on the market; they may have slightly different operation conditions esp. wrt. to timing (if they work at all; I don't have own experience on this).
                  • How are your cabeling conditions? I had some troubles when using nRF+PA+LNA modules together with the new (post 2.0.1-) MySensors-libs and more than 5 DS18B20 on one line (non-parasitic mode). This seems to be solved by the use of a small delay between temp-sends (wait(50) or so). With a lot of sensors and long lines and/or star topology, you may have to lower the pullup resistor value (e.g. 3.3k).

                  Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                  T 1 Reply Last reply
                  0
                  • rejoe2R rejoe2

                    @tomasandersson This really looks strange.
                    Some additional remarks:

                    • Some values represent also failure codes, beside -127°, 85° (C), which are already filtered out by code I also suspect 0° to be one of these. This is the backgound of me asking above for absolute figures.
                    • There seem to be also fake chips on the market; they may have slightly different operation conditions esp. wrt. to timing (if they work at all; I don't have own experience on this).
                    • How are your cabeling conditions? I had some troubles when using nRF+PA+LNA modules together with the new (post 2.0.1-) MySensors-libs and more than 5 DS18B20 on one line (non-parasitic mode). This seems to be solved by the use of a small delay between temp-sends (wait(50) or so). With a lot of sensors and long lines and/or star topology, you may have to lower the pullup resistor value (e.g. 3.3k).
                    T Offline
                    T Offline
                    tomasandersson
                    wrote on last edited by
                    #14

                    @rejoe2

                    Thanks so much for your help.
                    I think you're a little ahead of me in programming. Interesting with time delay between temp sends. How do I create it?

                    rejoe2R 1 Reply Last reply
                    0
                    • T tomasandersson

                      @rejoe2

                      Thanks so much for your help.
                      I think you're a little ahead of me in programming. Interesting with time delay between temp sends. How do I create it?

                      rejoe2R Offline
                      rejoe2R Offline
                      rejoe2
                      wrote on last edited by
                      #15

                      @tomasandersson You are welcome!
                      I am more feeling as a beginner also in most programming aspects. This is just some sort of copy/pasting in addition with some thoughts on how things may work and reading technical documentation and examples :simple_smile:; most of this is based on leodesigners work here somewhere in the forum (fride monitor). I had a hard time to find solutions working for me, so I'm happy if someone can learn from this.

                      Back to the answer: just add a wait(50); as new line 120 (somewhere within the reading/sending for-loop).

                      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                      T 1 Reply Last reply
                      0
                      • rejoe2R rejoe2

                        @tomasandersson You are welcome!
                        I am more feeling as a beginner also in most programming aspects. This is just some sort of copy/pasting in addition with some thoughts on how things may work and reading technical documentation and examples :simple_smile:; most of this is based on leodesigners work here somewhere in the forum (fride monitor). I had a hard time to find solutions working for me, so I'm happy if someone can learn from this.

                        Back to the answer: just add a wait(50); as new line 120 (somewhere within the reading/sending for-loop).

                        T Offline
                        T Offline
                        tomasandersson
                        wrote on last edited by
                        #16

                        @rejoe2

                        Now I have tried both of the programs. It works much the same. It pops up a fault sometimes.
                        Is it difficult to enter a line in the program, says that if the temperature has changed system than - + 5 degrees so it shall not be reported

                        rejoe2R 1 Reply Last reply
                        0
                        • T tomasandersson

                          @rejoe2

                          Now I have tried both of the programs. It works much the same. It pops up a fault sometimes.
                          Is it difficult to enter a line in the program, says that if the temperature has changed system than - + 5 degrees so it shall not be reported

                          rejoe2R Offline
                          rejoe2R Offline
                          rejoe2
                          wrote on last edited by
                          #17

                          @tomasandersson To me, this really seems to be hardware related, so triple check your wirings first.
                          If you really believe this to be a software problem, you may add an additional condition in line 119 with another "&&", (from memory something like abs(lastTemperature[i] - temperature < 5). I would have to test it myself and don't find this reasonable (s.o.), so feel free to finish this part of the job yourself.

                          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                          T 1 Reply Last reply
                          0
                          • rejoe2R rejoe2

                            @tomasandersson To me, this really seems to be hardware related, so triple check your wirings first.
                            If you really believe this to be a software problem, you may add an additional condition in line 119 with another "&&", (from memory something like abs(lastTemperature[i] - temperature < 5). I would have to test it myself and don't find this reasonable (s.o.), so feel free to finish this part of the job yourself.

                            T Offline
                            T Offline
                            tomasandersson
                            wrote on last edited by
                            #18

                            @rejoe2
                            Thank you for helping me in the right direction
                            I do not think there is anything wrong with the hardware because I have two identical sets. One to a spa and a heat pump. Maybe I'll try it with less resistance. Now i have 4.8kohm

                            I'm now trying with more or less distinction from the former transient temp.
                            I will reply when I got it to work.

                            Tomas

                            rejoe2R 1 Reply Last reply
                            0
                            • T tomasandersson

                              @rejoe2
                              Thank you for helping me in the right direction
                              I do not think there is anything wrong with the hardware because I have two identical sets. One to a spa and a heat pump. Maybe I'll try it with less resistance. Now i have 4.8kohm

                              I'm now trying with more or less distinction from the former transient temp.
                              I will reply when I got it to work.

                              Tomas

                              rejoe2R Offline
                              rejoe2R Offline
                              rejoe2
                              wrote on last edited by
                              #19

                              @tomasandersson Just 2 DS18B20 on each line should never cause trouble wrt current draw using a 4.8k resistor and 30 sec. intervals and no additional sensors drawing current from the arduino. If not already in place I would anyhow recommend using 3 wires for operation instead of parasitic mode.
                              Anyhow: Best way to identify these chips is using the addresses. Most likely you now are also prepared to do some small editing in sketches?
                              "My" array-sketch-version also prints the ID's as array information you need to serial. You may test it and then disable this feature once you have the info for both of your sketches (begin the respecting line with the #define with a "//"). Doing so will definitely eliminate any smallest risk of mixing data...

                              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                              1 Reply Last reply
                              0
                              • pepsonP Offline
                                pepsonP Offline
                                pepson
                                wrote on last edited by
                                #20

                                Is any chance to connect more than 16 dallas ? By change value 16 to example 20 ?

                                1 Reply Last reply
                                0
                                • F flopp

                                  I have modify the sketch so now if sensor B is disconnected A will be A and C will be C, as soon as B is connected again it will send the values again.

                                  /**
                                   * The MySensors Arduino library handles the wireless radio link and protocol
                                   * between your home built sensors/actuators and HA controller of choice.
                                   * The sensors forms a self healing radio network with optional repeaters. Each
                                   * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                   * network topology allowing messages to be routed to nodes.
                                   *
                                   * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                   * Copyright (C) 2013-2015 Sensnology AB
                                   * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                   *
                                   * Documentation: http://www.mysensors.org
                                   * Support Forum: http://forum.mysensors.org
                                   *
                                   * This program is free software; you can redistribute it and/or
                                   * modify it under the terms of the GNU General Public License
                                   * version 2 as published by the Free Software Foundation.
                                   *
                                   *******************************
                                   *
                                   * DESCRIPTION
                                   *
                                   * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                   * http://www.mysensors.org/build/temp
                                   */
                                  
                                  #include <MySensor.h>  
                                  #include <SPI.h>
                                  #include <DallasTemperature.h>
                                  #include <OneWire.h>
                                  
                                  #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
                                  
                                  #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                  #define MAX_ATTACHED_DS18B20 16
                                  unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                  OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                  DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
                                  
                                  byte D[3][8] = {
                                  { 0x28, 0xB1, 0x47, 0xB4, 0x04, 0x00, 0x00, 0x97 },
                                  { 0x28, 0xFF, 0x53, 0x78, 0x63, 0x15, 0x02, 0xC9 },
                                  { 0x28, 0xFF, 0xCD, 0x06, 0x52, 0x04, 0x00, 0x80 }
                                  };
                                  MySensor gw;
                                  float lastTemperature[MAX_ATTACHED_DS18B20];
                                  int numSensors=0;
                                  boolean receivedConfig = false;
                                  boolean metric = true; 
                                  // Initialize temperature message
                                  MyMessage msg(0,V_TEMP);
                                  
                                  void setup()  
                                  { 
                                    // Startup up the OneWire library
                                    sensors.begin();
                                    // requestTemperatures() will not block current thread
                                    sensors.setWaitForConversion(false);
                                  
                                    // Startup and initialize MySensors library. Set callback for incoming messages. 
                                    gw.begin();
                                  
                                    // Send the sketch version information to the gateway and Controller
                                    gw.sendSketchInfo("Temperature Sensor", "1.1");
                                  
                                    // Fetch the number of attached temperature sensors  
                                    //numSensors = sensors.getDeviceCount();
                                  
                                    // Present all sensors to controller
                                    for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {   
                                       gw.present(i, S_TEMP);
                                    }
                                  }
                                  
                                  
                                  void loop()     
                                  {     
                                    
                                  Serial.println(millis()); 
                                    // Process incoming messages (like config from server)
                                    gw.process(); 
                                  
                                    // Fetch temperatures from Dallas sensors
                                    sensors.requestTemperatures();
                                  
                                    // query conversion time and sleep until conversion completed
                                    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                    // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                    gw.sleep(conversionTime);
                                  
                                    // Read temperatures and send them to controller 
                                    for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {
                                   
                                      // Fetch and round temperature to one decimal
                                   //   float temperature = static_cast<float>(static_cast<int>((sensors.requestTemperaturesByAddress(D[i])) * 10.)) / 10.;
                                        float temperature = sensors.getTempC(D[i]);
                                      // Only send data if temperature has changed and no error
                                      #if COMPARE_TEMP == 1
                                      if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                                      #else
                                      if (temperature != -127.00 && temperature != 85.00) {
                                      #endif
                                   
                                        // Send in the new temperature
                                        gw.send(msg.setSensor(i).set(temperature,1));
                                        // Save new temperatures for next compare
                                        lastTemperature[i]=temperature;
                                      }
                                    }
                                    //gw.sleep(SLEEP_TIME);
                                  }
                                  

                                  first you need to use this sketch to get the correct addresses for all your DS18B20

                                  #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(3);  // on pin 10 (a 4.7K resistor is necessary)
                                  int count=0;
                                  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;
                                    
                                    if ( !ds.search(addr)) {
                                      //Serial.println("No more addresses.");
                                      Serial.println();
                                      ds.reset_search();
                                      delay(250);
                                      Serial.println(count);
                                      Serial.println();
                                      count=0;
                                      return;
                                    }
                                    
                                    //Serial.print("ROM =");
                                    Serial.print("{");
                                    for( i = 0; i < 8; i++) {
                                    Serial.print(" 0x");
                                      //Serial.write(' ');
                                      //int a = (addr[i], DEC);
                                      //Serial.print(a);
                                      if (addr[i] <= 15){
                                      
                                        Serial.print("0");
                                      }
                                      
                                      Serial.print(addr[i], HEX);
                                      if (i < 7){
                                        Serial.print(",");
                                      }
                                      else 
                                      Serial.print(" },");
                                    }
                                  
                                    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;
                                  
                                    //Serial.print("  Temperature = ");
                                    //Serial.print(celsius);
                                    //Serial.println(" Celsius, ");
                                  
                                    count++;
                                  }
                                  

                                  you will get the address like this format

                                  { 0x28, 0xB1, 0x47, 0xB4, 0x04, 0x00, 0x00, 0x97 }

                                  pepsonP Offline
                                  pepsonP Offline
                                  pepson
                                  wrote on last edited by
                                  #21

                                  @flopp

                                  Hi
                                  i try use your sketch but it is not working... I add in this to use serial gateway but also i get error why ?

                                  /**
                                   * The MySensors Arduino library handles the wireless radio link and protocol
                                   * between your home built sensors/actuators and HA controller of choice.
                                   * The sensors forms a self healing radio network with optional repeaters. Each
                                   * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                   * network topology allowing messages to be routed to nodes.
                                   *
                                   * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                   * Copyright (C) 2013-2015 Sensnology AB
                                   * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                   *
                                   * Documentation: http://www.mysensors.org
                                   * Support Forum: http://forum.mysensors.org
                                   *
                                   * This program is free software; you can redistribute it and/or
                                   * modify it under the terms of the GNU General Public License
                                   * version 2 as published by the Free Software Foundation.
                                   *
                                   *******************************
                                   *
                                   * DESCRIPTION
                                   *
                                   * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                   * http://www.mysensors.org/build/temp
                                   */
                                  
                                  #define MY_GATEWAY_SERIAL
                                  
                                  #include <MySensors.h>  
                                  #include <SPI.h>
                                  #include <DallasTemperature.h>
                                  #include <OneWire.h>
                                  
                                  #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
                                  
                                  #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                  #define MAX_ATTACHED_DS18B20 16
                                  unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                  OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                  DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
                                  
                                  byte D[3][8] = {
                                  { 0x28, 0xC6, 0xCA, 0xA0, 0x05, 0x00, 0x00, 0x30 }
                                  };
                                  MySensor gw;
                                  float lastTemperature[MAX_ATTACHED_DS18B20];
                                  int numSensors=0;
                                  boolean receivedConfig = false;
                                  boolean metric = true; 
                                  // Initialize temperature message
                                  MyMessage msg(0,V_TEMP);
                                  
                                  void setup()  
                                  { 
                                    // Startup up the OneWire library
                                    sensors.begin();
                                    // requestTemperatures() will not block current thread
                                    sensors.setWaitForConversion(false);
                                  
                                    // Startup and initialize MySensors library. Set callback for incoming messages. 
                                    gw.begin();
                                  
                                    // Send the sketch version information to the gateway and Controller
                                    gw.sendSketchInfo("Temperature Sensor", "1.1");
                                  
                                    // Fetch the number of attached temperature sensors  
                                    numSensors = sensors.getDeviceCount();
                                  
                                    // Present all sensors to controller
                                    for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {   
                                       gw.present(i, S_TEMP);
                                    }
                                  }
                                  
                                  
                                  void loop()     
                                  {     
                                    
                                  Serial.println(millis()); 
                                    // Process incoming messages (like config from server)
                                    gw.process(); 
                                  
                                    // Fetch temperatures from Dallas sensors
                                    sensors.requestTemperatures();
                                  
                                    // query conversion time and sleep until conversion completed
                                    int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                    // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                    gw.sleep(conversionTime);
                                  
                                    // Read temperatures and send them to controller 
                                    for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {
                                   
                                      // Fetch and round temperature to one decimal
                                   //   float temperature = static_cast<float>(static_cast<int>((sensors.requestTemperaturesByAddress(D[i])) * 10.)) / 10.;
                                        float temperature = sensors.getTempC(D[i]);
                                      // Only send data if temperature has changed and no error
                                      #if COMPARE_TEMP == 1
                                      if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                                      #else
                                      if (temperature != -127.00 && temperature != 85.00) {
                                      #endif
                                   
                                        // Send in the new temperature
                                        gw.send(msg.setSensor(i).set(temperature,1));
                                        // Save new temperatures for next compare
                                        lastTemperature[i]=temperature;
                                      }
                                    }
                                    //gw.sleep(SLEEP_TIME);
                                  }
                                  

                                  But when try compile i get error:

                                  dallas_with_address_ok:45:1: error: 'MySensor' does not name a type
                                  
                                   MySensor gw;
                                  
                                   ^
                                  
                                  C:\Users\Piotrek\Desktop\Arduino\dallas_with_address_ok\dallas_with_address_ok.ino: In function 'void setup()':
                                  
                                  dallas_with_address_ok:61:3: error: 'gw' was not declared in this scope
                                  
                                     gw.begin();
                                  
                                     ^
                                  
                                  C:\Users\Piotrek\Desktop\Arduino\dallas_with_address_ok\dallas_with_address_ok.ino: In function 'void loop()':
                                  
                                  dallas_with_address_ok:81:3: error: 'gw' was not declared in this scope
                                  
                                     gw.process(); 
                                  
                                     ^
                                  
                                  exit status 1
                                  'MySensor' does not name a type
                                  

                                  Please help me...

                                  mfalkviddM 1 Reply Last reply
                                  0
                                  • pepsonP pepson

                                    @flopp

                                    Hi
                                    i try use your sketch but it is not working... I add in this to use serial gateway but also i get error why ?

                                    /**
                                     * The MySensors Arduino library handles the wireless radio link and protocol
                                     * between your home built sensors/actuators and HA controller of choice.
                                     * The sensors forms a self healing radio network with optional repeaters. Each
                                     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                     * network topology allowing messages to be routed to nodes.
                                     *
                                     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                     * Copyright (C) 2013-2015 Sensnology AB
                                     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                     *
                                     * Documentation: http://www.mysensors.org
                                     * Support Forum: http://forum.mysensors.org
                                     *
                                     * This program is free software; you can redistribute it and/or
                                     * modify it under the terms of the GNU General Public License
                                     * version 2 as published by the Free Software Foundation.
                                     *
                                     *******************************
                                     *
                                     * DESCRIPTION
                                     *
                                     * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                     * http://www.mysensors.org/build/temp
                                     */
                                    
                                    #define MY_GATEWAY_SERIAL
                                    
                                    #include <MySensors.h>  
                                    #include <SPI.h>
                                    #include <DallasTemperature.h>
                                    #include <OneWire.h>
                                    
                                    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
                                    
                                    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                    #define MAX_ATTACHED_DS18B20 16
                                    unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
                                    
                                    byte D[3][8] = {
                                    { 0x28, 0xC6, 0xCA, 0xA0, 0x05, 0x00, 0x00, 0x30 }
                                    };
                                    MySensor gw;
                                    float lastTemperature[MAX_ATTACHED_DS18B20];
                                    int numSensors=0;
                                    boolean receivedConfig = false;
                                    boolean metric = true; 
                                    // Initialize temperature message
                                    MyMessage msg(0,V_TEMP);
                                    
                                    void setup()  
                                    { 
                                      // Startup up the OneWire library
                                      sensors.begin();
                                      // requestTemperatures() will not block current thread
                                      sensors.setWaitForConversion(false);
                                    
                                      // Startup and initialize MySensors library. Set callback for incoming messages. 
                                      gw.begin();
                                    
                                      // Send the sketch version information to the gateway and Controller
                                      gw.sendSketchInfo("Temperature Sensor", "1.1");
                                    
                                      // Fetch the number of attached temperature sensors  
                                      numSensors = sensors.getDeviceCount();
                                    
                                      // Present all sensors to controller
                                      for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {   
                                         gw.present(i, S_TEMP);
                                      }
                                    }
                                    
                                    
                                    void loop()     
                                    {     
                                      
                                    Serial.println(millis()); 
                                      // Process incoming messages (like config from server)
                                      gw.process(); 
                                    
                                      // Fetch temperatures from Dallas sensors
                                      sensors.requestTemperatures();
                                    
                                      // query conversion time and sleep until conversion completed
                                      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                      gw.sleep(conversionTime);
                                    
                                      // Read temperatures and send them to controller 
                                      for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {
                                     
                                        // Fetch and round temperature to one decimal
                                     //   float temperature = static_cast<float>(static_cast<int>((sensors.requestTemperaturesByAddress(D[i])) * 10.)) / 10.;
                                          float temperature = sensors.getTempC(D[i]);
                                        // Only send data if temperature has changed and no error
                                        #if COMPARE_TEMP == 1
                                        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                                        #else
                                        if (temperature != -127.00 && temperature != 85.00) {
                                        #endif
                                     
                                          // Send in the new temperature
                                          gw.send(msg.setSensor(i).set(temperature,1));
                                          // Save new temperatures for next compare
                                          lastTemperature[i]=temperature;
                                        }
                                      }
                                      //gw.sleep(SLEEP_TIME);
                                    }
                                    

                                    But when try compile i get error:

                                    dallas_with_address_ok:45:1: error: 'MySensor' does not name a type
                                    
                                     MySensor gw;
                                    
                                     ^
                                    
                                    C:\Users\Piotrek\Desktop\Arduino\dallas_with_address_ok\dallas_with_address_ok.ino: In function 'void setup()':
                                    
                                    dallas_with_address_ok:61:3: error: 'gw' was not declared in this scope
                                    
                                       gw.begin();
                                    
                                       ^
                                    
                                    C:\Users\Piotrek\Desktop\Arduino\dallas_with_address_ok\dallas_with_address_ok.ino: In function 'void loop()':
                                    
                                    dallas_with_address_ok:81:3: error: 'gw' was not declared in this scope
                                    
                                       gw.process(); 
                                    
                                       ^
                                    
                                    exit status 1
                                    'MySensor' does not name a type
                                    

                                    Please help me...

                                    mfalkviddM Offline
                                    mfalkviddM Offline
                                    mfalkvidd
                                    Mod
                                    wrote on last edited by
                                    #22

                                    @pepson that sketch is for MySensors 1.x. It needs to be updated to work with 2.x. There is a guide, see if you can find it by searching (I’m on mobile now so I can’t search easily)

                                    pepsonP 1 Reply Last reply
                                    0
                                    • pepsonP Offline
                                      pepsonP Offline
                                      pepson
                                      wrote on last edited by pepson
                                      #23

                                      I correct this sketch But for me dont read temp.....
                                      standard sketch from mysensors looks similary like this read with no problem.
                                      https://www.mysensors.org/build/temp

                                      /**
                                       * The MySensors Arduino library handles the wireless radio link and protocol
                                       * between your home built sensors/actuators and HA controller of choice.
                                       * The sensors forms a self healing radio network with optional repeaters. Each
                                       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                       * network topology allowing messages to be routed to nodes.
                                       *
                                       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                       * Copyright (C) 2013-2015 Sensnology AB
                                       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                       *
                                       * Documentation: http://www.mysensors.org
                                       * Support Forum: http://forum.mysensors.org
                                       *
                                       * This program is free software; you can redistribute it and/or
                                       * modify it under the terms of the GNU General Public License
                                       * version 2 as published by the Free Software Foundation.
                                       *
                                       *******************************
                                       *
                                       * DESCRIPTION
                                       *
                                       * Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
                                       * http://www.mysensors.org/build/temp
                                       */
                                      
                                      #define MY_GATEWAY_SERIAL
                                      
                                      #include <MySensors.h>  
                                      #include <SPI.h>
                                      #include <DallasTemperature.h>
                                      #include <OneWire.h>
                                      
                                      #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
                                      
                                      #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                      #define MAX_ATTACHED_DS18B20 16
                                      unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
                                      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                      DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
                                      
                                      byte D[3][8] = {
                                      { 0x28, 0xFB, 0x8F, 0x77, 0x91, 0x15, 0x02, 0x32 },
                                      { 0x28, 0xFF, 0x37, 0x77, 0x91, 0x18, 0x02, 0x16 }
                                      };
                                      //MySensor gw;
                                      float lastTemperature[MAX_ATTACHED_DS18B20];
                                      int numSensors=0;
                                      boolean receivedConfig = false;
                                      boolean metric = true; 
                                      // Initialize temperature message
                                      MyMessage msg(0,V_TEMP);
                                      
                                      void before()  
                                      { 
                                        // Startup up the OneWire library
                                        sensors.begin();
                                      }
                                      
                                      void setup() 
                                      {
                                        // requestTemperatures() will not block current thread
                                        sensors.setWaitForConversion(false);
                                      
                                        // Startup and initialize MySensors library. Set callback for incoming messages. 
                                      //  begin();
                                      }
                                      void presentation() {
                                        // Send the sketch version information to the gateway and Controller
                                        sendSketchInfo("Temp. Sensor", "1.1");
                                      
                                        // Fetch the number of attached temperature sensors  
                                        numSensors = sensors.getDeviceCount();
                                      
                                        // Present all sensors to controller
                                        for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {   
                                           present(i, S_TEMP);
                                        }
                                      }
                                      
                                      
                                      void loop()     
                                      {     
                                        
                                      Serial.println(millis()); 
                                        // Process incoming messages (like config from server)
                                        //process(); 
                                      
                                        // Fetch temperatures from Dallas sensors
                                        sensors.requestTemperatures();
                                      
                                        // query conversion time and sleep until conversion completed
                                        int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                        // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                        sleep(conversionTime);
                                      
                                        // Read temperatures and send them to controller 
                                        for (int i=0; i<3 && i<MAX_ATTACHED_DS18B20; i++) {
                                       
                                          // Fetch and round temperature to one decimal
                                       //   float temperature = static_cast<float>(static_cast<int>((sensors.requestTemperaturesByAddress(D[i])) * 10.)) / 10.;
                                            float temperature = sensors.getTempC(D[i]);
                                          // Only send data if temperature has changed and no error
                                          #if COMPARE_TEMP == 1
                                          if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                                          #else
                                          if (temperature != -127.00 && temperature != 85.00) {
                                          #endif
                                       
                                            // Send in the new temperature
                                            send(msg.setSensor(i).set(temperature,1));
                                            // Save new temperatures for next compare
                                            lastTemperature[i]=temperature;
                                          }
                                        }
                                        //gw.sleep(SLEEP_TIME);
                                      }
                                      
                                      1 Reply Last reply
                                      0
                                      • mfalkviddM mfalkvidd

                                        @pepson that sketch is for MySensors 1.x. It needs to be updated to work with 2.x. There is a guide, see if you can find it by searching (I’m on mobile now so I can’t search easily)

                                        pepsonP Offline
                                        pepsonP Offline
                                        pepson
                                        wrote on last edited by
                                        #24

                                        @mfalkvidd
                                        Hi
                                        I am not programmer and i dont know how. Is any chance to you can help me convert it to working with MySensors 2.x ?
                                        This sketch looks similary as standard sketch from mysensors:
                                        https://www.mysensors.org/build/temp

                                        Standard sketch works but i want use sketch with ID Dallas to write in my Home assistant to specify number child.... and when dallas destroy i replace ID in sketch write to arduino and in Home Assistant automaticaly replace it and show still correct temp to my room.

                                        1 Reply Last reply
                                        0
                                        • F Offline
                                          F Offline
                                          flopp
                                          wrote on last edited by flopp
                                          #25

                                          @pepson said in About DS18B20 onewire.:

                                          #define MAX_ATTACHED_DS18B20 16
                                          

                                          this should be how many DS18B20 you have attached

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


                                          25

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 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