Interfacing DS7505

The DS7505 digital thermometer and thermostat is a very versatile temperature sensor. It offers 9 to 12-bit digital temperature readings between -55 and +125 Celsius with an accuracy of 0.5 degree. It can be used with any MCUs that has I2C support or can be pre-programmed and used in standalone applications as digital thermostats.

In this article, I will introduce a C++ library I created to interface DS7505 with Arduino. This library exposes all the functions of the DS7505 and at the mean time provides a simplified interface for temperature reading and thermostat setting. For those who are impatient, the code library and sample code can be downloaded at the end of this article.

Overview

The following image shows the pinout of the DS7505 chip. Up to eight DS7505’s can be placed on the same I2C bus by changing the 3-bit address pin settings (A2, A1 and A0).

DS7505 pinout

DS7505 pinout

Since the maximum Vdd for DS7505 is 3.6V, voltage level shifting would be required if the standard 5V Arduino board is used. I used a customized Arduino board (see picture below) with the supply voltage set to 3.3V.

DS7505 connected to a customized Arduino board

DS7505 connected to a customized Arduino board

Using the DS7505 library, basic temperature measurement in either Celsius or Fahrenheit can be done as follows:

#include <Wire.h>
#include <DS7505.h>

DS7505 ds7505;

void setup()
{
    Serial.begin(9600);
    
    Wire.begin();

    //initializes temp sensor with 12 bit resolution
    //the I2C address is 0 0 0 in this case 
    //(pin 5, 6, 7 are tied to ground)
    ds7505.init(0,0,0,12);
}

void loop()
{
  delay(500);
  
  //print the current temperature in Fahrenheit
  Serial.println(ds7505.getTempF());

  //print the current temperature in Celsius 
  Serial.println(ds7505.getTempC());
}

Here is another example (included in the download) that shows how to use the library to set the thermostat trip point and hysteresis temperatures. The setting can be either temporary or written to the non-volatile memory depending on whether CMD_COPY_DATA command is sent after the changes are made.

#include <Wire.h>
#include <DS7505.h>

DS7505 ds7505;

void setup()
{
    Serial.begin(9600);
    
    Wire.begin();
    
    //initializes temp sensor with 12 bit resolution
    //the I2C address is 0 0 0 in this case 
    //(pin 5, 6, 7 are tied to ground)
    ds7505.init(0,0,0,12);
    
    //set the thermostat at 32.45 (Celsius) with a hysteresis of 30.14 degree
    ds7505.setThermostatC(32.45f, 30.14f, DS7505::FT_6);
    
    //the temperatures read back will be slightly off depending on the resolution
    //settings
    Serial.println(ds7505.getTempC(DS7505::P_TOS));    
    Serial.println(ds7505.getTempC(DS7505::P_THYST));
    
    //make the settings permanent (write to NV memory)
    ds7505.sendCommand(DS7505::CMD_COPY_DATA);
}

void loop()
{
  delay(500);
  
  //print the current temperature in Fahrenheit
  Serial.println(ds7505.getTempF());
}

Library References

Constants definitions

All constants defined here can be accessed in programs via DS7505::{constant_name}.

  //Resolution Definition
  //R1 R0
  static const byte RES_09 = 0x0; // 9 bit res;
  static const byte RES_10 = 0x1; //10 bit res;
  static const byte RES_11 = 0x2; //11 bit res;
  static const byte RES_12 = 0x3; //12 bit res;

The above constants define the available resolutions (9 bit to 12 bit)

  //Fault Tolerance Configuration
  //F1 F0
  static const byte FT_1 = 0x0; //fault tolerance consecutive out of limits 1
  static const byte FT_2 = 0x1; //fault tolerance consecutive out of limits 2
  static const byte FT_4 = 0x2; //fault tolerance consecutive out of limits 4
  static const byte FT_6 = 0x3; //fault tolerance consecutive out of limits 6

FT setting defines fault tolerance. The thermostat is tripped at the trip point temperature only when the number of pre-defined consecutive out-of-limit temperature readings are reached.

  //Register Pointer Definition
  //P1 P0
  static const byte P_TEMP = 0x0; //temperature
  static const byte P_CONF = 0x1; //configuration
  static const byte P_THYST = 0x2; //Thyst
  static const byte P_TOS = 0x3; //Tos

These constants define the chip functions that can be used. The meaning of the following byte(s) sent depending on the value of register pointer.

  //command set
  static const byte CMD_RECALL_DATA = 0xB8;
  static const byte CMD_COPY_DATA = 0x48;
  static const byte CMD_POR = 0x54;

These are the commands that can be issued to DS7505. These commands are used to load/save the thermostat settings. CMD_POR is used to reset the device.

Available Functions

void init(byte a2, byte a1, byte a0, byte res)

The three addresses passed in (a2, a1, a0) corresponds to the pin states of pin 5, pin 6 and pin 7 of DS7505 (either grounded or tied to Vdd). They take values of either 0 (low) or 1 (high).

//Celsius
float getTempC()
float getTempC(byte regPdef)

//Fahrenheit
float getTempF()
float getTempF(byte regPdef) 

These two groups of four functions read back the temperature measurements or settings, capable of providing both Celsius and Fahrenheit readings. The two functions without any parameters retrieve the current temperature reading. And the two functions with the parameter regPdef return the temperature settings depending on the register pointer definition:

    P_TEMP:   same as calling without the parameter, returning the current temperature measurement.
    P_THYST: returns the current hysteresis temperature setting. 
    P_TOS:     returns the current trip point temperature setting.
//Celsius
void setThermostatC(float t)
void setThermostatC(float tos, float thyst)
void setThermostatC(float tos, float thyst, byte ft)

//Fahrenheit
void setThermostatF(float t)
void setThermostatF(float tos, float thyst)
void setThermostatF(float tos, float thyst, byte ft) 

These two groups of six functions are overloaded functions that set the thermostat temperatures. If only t is supplied, the trip point is set to the value supplied and the hysteresis is set to be 5 degrees below the trip point. When both tos and thyst are supplied, these values are used to set the trip point temperature and hysteresis temperature set accordingly. When fault tolerance value is supplied (see the constant section for value definitions), the tolerance is set with the supplied value. And when fault tolerance value is not supplied, it remains unchanged.

  void setConfigRegister(byte configByte)

For temperature measurements, most of DS7505’s functionalities can already be accessed using the getTemp or setThermostat functions listed above. The setConfigRegister function is provided to cover the remaining functionalities such as setting the thermostat output polarity, changing the operating mode and the shutdown mode. please refer to the datasheet for more detailed information.

void sendCommand(byte cmdSet)

Download DS7505 Arduino Library

Be Sociable, Share!

3 Comments

  1. Adrian says:

    Can you please tell me what values those resistors have?
    Thank you,

Leave a Reply