Ruben Laguna's blog

DS1620 Temperature Sensor Library for Arduino

I talked about the DS1620 in a previous post. Now I created a DS1620 library for Arduino that has a more object oriented interface. The library has to be unpacked in the $arduino_home/hardware/libraries directory. After unzipping the library you should end up with a $ARDUINO_HOME/hardware/libraries/ds1620 directory.

The library contains an example that can be accessed through the File ⇒ Sketchbook ⇒ Examples ⇒ Library-ds1620 ⇒ ds1620.

library ds1620 example menu

The example looks like this:

/*
 ds1620 example
*/

#define ledPin 13

#include <stdlib.h>
#include <math.h>
//#include <Stdio.h>



#include "ds1620.h"


// set up ds1620
// this sets the pins as outputs
Ds1620 ds1620 = Ds1620(7/*rst*/,8/*clk*/,9/*dq*/);
 
void setup()
{
  
  // configure ds1620
  // this does sets cpu mode 1shot
  // see datasheet http://pdfserv.maxim-ic.com/en/ds/DS1620.pd 
  ds1620.config();

  Serial.begin(9600);
  delay(100);
  
  
  Serial.print("RST\r\n");  
}

void loop() 
{ 
   // start the temperature conversion
   // 1 shot mode
   ds1620.start_conv();
   
   // read the last temperature converson
   int raw_data = ds1620.read_data();
   
   // stop conversion not really needed since we are in 
   // 1 shot mode
   ds1620.stop_conv();
   float temp = raw_data / 2.0; 
   Serial.print((int)temp,DEC);
   Serial.print("\r\n");
}

References.

Comments