Same value from 2 different placed DS18B20



  • Hi,

    I'm having a hard time figuring out, why i'm getting the same value from 2 different DS18B20 from the same node. Both DS18 are on Pin 3.

    I know for SURE, that the values/readings can never be the same, as they are placed 2 different places. It's ALWAYS the second DS that somehow get the first DS's value, and that is then transmitted. The node is monitoring a DIY solar water heating system. 1 DS18B20 (S=1) is placed in the collection tank (55 gal water), and the other is placed inside the waterhose to monitor the heat in the panel.

    Sketch:

    // Running DS temperature sensor(s) and relay(s) on one mysensor arduino node
        // Combines Onewire and Relay code
        // 2014-10-14 Pego: Tested and Running on Uno/Clone and MQTT gateway
        
        // Example sketch showing how to send in OneWire temperature readings
        // Example sketch showing how to control physical relays. 
        // This example will remember relay state even after power failure.
        
        #include <MySensor.h>  
        #include <SPI.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        
        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
        #define MAX_ATTACHED_DS18B20 16
        
        #define RELAY_1  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
        #define RELAY_ON 1  // GPIO value to write to turn on attached relay
        #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
        
        unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) 30000 orig
        OneWire oneWire(ONE_WIRE_BUS);
        DallasTemperature sensors(&oneWire);
        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 OneWire 
          sensors.begin();
        
          // Startup and initialize MySensors library. Set callback for incoming messages. 
          //gw.begin(); 
          gw.begin(incomingMessage, AUTO, true);
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Temp and Relays", "1.0");
        
          // Fetch the number of attached temperature sensors  
          numSensors = sensors.getDeviceCount();
        
          // Present all sensors to controller
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
             gw.present(i, V_TEMP);
          }
        
          // Fetch relay status
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
            // Register all sensors to gw (they will be created as child devices)
            gw.present(sensor, S_LIGHT);
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);   
            // Set relay to last known state (using eeprom storage) 
            digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
          }
        
        }
        
        
        void loop()     
        {     
          // Process incoming messages (like config from server)
          gw.process(); 
        
          // Fetch temperatures from Dallas sensors
          sensors.requestTemperatures(); 
        
          // Read temperatures and send them to controller 
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
         
            // Fetch and round temperature to one decimal
            float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
         
            // Only send data if temperature has changed more then 1 degC and no error
            if ((lastTemperature[i]) != temperature && temperature != -127.00 && temperature != 85.00) { //added integer
         
              // Send in the new temperature
              gw.send(msg.setSensor(i).set(temperature,1));
              lastTemperature[i]=temperature;
            }
          delay(1000);
          }
          //gw.sleep(SLEEP_TIME); //no sleep for relays!!!!
        }
        
        void incomingMessage(const MyMessage &message) {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_LIGHT) {
             // Change relay state
             digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
             // Store state in eeprom
             gw.saveState(message.sensor, message.getBool());
             // Write some debug info
             Serial.print("Incoming change for sensor:");
             Serial.print(message.sensor);
             Serial.print(", New status: ");
             Serial.println(message.getBool());
           } 
        }
    

    Readings on node serial port:

    repeater started, id 41
    send: 41-41-33-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
    send: 41-41-33-0 s=255,c=3,t=6,pt=1,l=1,st=ok:33
    read: 0-33-41 s=255,c=3,t=6,pt=0,l=1:M
    send: 41-41-33-0 s=255,c=3,t=11,pt=0,l=15,st=ok:Temp and Relays
    send: 41-41-33-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 41-41-33-0 s=0,c=0,t=0,pt=0,l=5,st=ok:1.4.1
    send: 41-41-33-0 s=1,c=0,t=0,pt=0,l=5,st=ok:1.4.1
    send: 41-41-33-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 41-41-33-0 s=2,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.0
    read: 0-33-41 s=2,c=1,t=2,pt=0,l=1:1
    Incoming change for sensor:2, New status: 1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.6
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:31.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:31.0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.8
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.9
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.8
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.6
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.2
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:29.2
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.7
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.3
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.5
    read: 0-33-41 s=2,c=1,t=2,pt=0,l=1:0
    Incoming change for sensor:2, New status: 0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:26.0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.3
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.4
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:26.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.5
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.6
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.7
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:26.8
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:26.9
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.3
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.4
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.6
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.7
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.8
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.9
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.3
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.6
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:28.7
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.8
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:28.9
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:28.9
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:29.0
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.2
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:29.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.3
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.4
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:29.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.5
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.6
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.7
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.8
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:29.9
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.1
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.2
    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:30.3
    read: 0-33-41 s=2,c=1,t=2,pt=0,l=1:1
    Incoming change for sensor:2, New status: 1
    

    As you can see, every once in a while S=1 reports the same value as S=0. I've tried to add a delay in the loop section, but without any luck. So now I'm stuck :(


  • Contest Winner

    @Hausner

    send: 41-41-33-0 s=0,c=1,t=0,pt=7,l=5,st=ok:27.0
    send: 41-41-33-0 s=1,c=1,t=0,pt=7,l=5,st=ok:24.1
    

    Even though you are converting to floats, these sensors still return integers, so you may be seeing the (not so obvious) limitations of the precision of the sensors.

    the numbers (if different) are close, so you should put a heat source near one (hair dryer?) to get them to be at a much bigger differential.

    Or return fahrenheit for one of the two like this:

    if (i == 0)
    {
      float temperature = static_cast<float>(static_cast<int>sensors.getTempCByIndex(i)* 10.) / 10.;
    }
    else
    {
      float temperature = static_cast<float>(static_cast<int>sensors.getTempFByIndex(i)* 10.) / 10.;
    }
    

    So you can really see what's happening.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.