Go Down

Topic: DallasTemperature Library - sensor failure alarm? (Read 1 time) previous topic - next topic

scoobsalamander

Apr 18, 2012, 03:00 pm Last Edit: Apr 18, 2012, 03:04 pm by scoobsalamander Reason: 1
I need to read out seven ds18b20 temperature sensors and this is working pretty well. But if I unplug one or more of these sensors the output (serial monitor) is still ok, there is still a value written and it looks like it is the last value before being unplugged. If I plug the sensor back in then the measurement is back working again.
Somebody an idea how I can implement an error message if one of the sensors is not behaving as it should (breakdown, wire break, etc..)?
Thx


I'm using one of the (modified) examples from the DallasTemperature library..

Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

void setup(void)
{
 // start serial port
 Serial.begin(9600);

 // Start up the library
 sensors.begin();
}

void loop(void)
{
 requestTemp();// call sensors.requestTemp() to issue all temperatures
 delay(10);
 
 
}

void requestTemp(){
 
 sensors.requestTemperatures(); // Send the command to get temperatures
 for (int i=0 ;i<=6; i++){
 Serial.print("Sensor : ");
 Serial.println(i);
 Serial.println(sensors.getTempCByIndex(i));
 delay(150);
 }
}  

PeterH

Rather than use the device index, you would be better off using the device address for each sensor. Then you know you're explicitly addressing a specific physical sensor rather than whatever device happens to be at that index in the list of devices present.

Code: [Select]

void discoverSensors()
{
  byte addr[8];
 
  // zero all of the addresses
  for(int i = 0; i < MAX_SENSORS; i++)
  {
    memset(sensorAddresses[i], 0, sizeof(DeviceAddress));
  }
  sensorCount = 0;
 
  while((oneWire.search(addr)) && (sensorCount < MAX_SENSORS))
  {
    if ( OneWire::crc8(addr, 7) != addr[7])
    {
        printf("CRC is not valid!\n");
        return;
    }
    else
    {
      memcpy(sensorAddresses[sensorCount], addr, sizeof(DeviceAddress));
      printf("Discovered sensor at ");
      printDeviceAddress(sensorAddresses[sensorCount]);
      printf("\n");
      sensorCount ++;
    }
  }
  oneWire.reset_search();
}

void configureSensors()
{
  for(int i = 0; i < sensorCount; i++)
  {
    dallas.setResolution(sensorAddresses[i], 12); // select the maximum supported resolution
  }
}

void handleSensors()
{
  dallas.requestTemperatures();

  for(int i = 0; i < sensorCount; i++)
  {
    float tempC = dallas.getTempC(sensorAddresses[i]);
   
    if((tempC > 0) && (tempC < 85.0))
    {
      // handle a good temperature value
    }
    else
    {
      // handle a bad temperature value
    }
  }
}

scoobsalamander

#2
Apr 19, 2012, 10:10 am Last Edit: Apr 19, 2012, 02:13 pm by scoobsalamander Reason: 1
thx,

I checked all seven unique addresses by means of the OneWire example. These addresses I use now in the new code (mostly taken from the examples from the DallasTemperature library) and this is working fine.
I used also your routine to test for error sensor when the temperature is out of limits.

In the future I will need several of these units, all equipped with seven sensors. Now I'm thinking of a communication over RS485 with some protocol (MODbus or something) so all the temperatures can be requested by the Master unit which will have a display unit. The alarm setpoints and the status of all units will be controlled from the Master unit....

As I'm new into embedded programming I will have to return a lot to this forum I guess... :-)




Go Up