sicklinger.com

  • Increase font size
  • Default font size
  • Decrease font size
  • English (United States)
  • Deutsch (DE-CH-AT)
Start ATMEL AVR ATMEGA DS18x20 library in C

ATMEL AVR ATMEGA DS18x20 library in C

E-mail Print PDF
( 20 Votes )

 

Hello,

today I am releasing the first version of my c library for ds18x20 high-precision 1-wire digital thermometer.

Also the AVR Studio (4.18 SP2) project files are included. The WINAVR Toolchain version WinAVR-20100110 was used.

The driver routines have the following features:

  1. Temperature range: -55°C to 125°C
  2. For positive temperature values one can have 1 decimal place step size i. e. 0.1°C (however only 0.5°C measurement accuracy is guaranteed)
  3. For negative temperature values the step size is 0.5°C
  4. The return value of the ds1820_read_temp(uint8_t DS1820_pin) is float. This is not the most efficient way on a 8bit MCU but I think this is an easy way to get started.
  5. Only one sensor per ATMEGA Pin can be used
  6. For short wire length (less than one meter) from DS18x20 to ATMEGA MCU the internal pullup resistors work. For longer wires you need an external 4.7k pullup resistor

An example:

This short example should show how easy this library is to use. In this example 5 ds18s20 sensors are used.

 

#include "ds18x20lib.h"
//#########################################
//#########################################
//#########################################
// S T A R T  M A I N  P R O G R A M 
int main (void)
{
//-----------------------------------------
// Allocate memory
//----------------------------------------- 
unsigned char temp_po_str[8],temp_pm_str[8],temp_pu_str[8],temp_ke_str[8],temp_bo_str[8];
float temp_po,temp_pm,temp_pu,temp_ke,temp_bo;
//-----------------------------------------
// Init Stuff
//-----------------------------------------
ds1820_init(DS1820_pin_po);              //Initialize DS1820 "sensor #1"
ds1820_init(DS1820_pin_pm);              //Initialize DS1820 "sensor #2"
ds1820_init(DS1820_pin_pu);              //Initialize DS1820 "sensor #3"
ds1820_init(DS1820_pin_ke);              //Initialize DS1820 "sensor #4"
ds1820_init(DS1820_pin_bo);              //Initialize DS1820 "sensor #5"
for(;;){
//-----------------------------------------
// Read temperature
//-----------------------------------------
temp_po = ds1820_read_temp(DS1820_pin_po); //Get temperature from DS1820 "sensor #1"
temp_pm = ds1820_read_temp(DS1820_pin_pm); //Get temperature from DS1820 "sensor #2"
temp_pu = ds1820_read_temp(DS1820_pin_pu); //Get temperature from DS1820 "sensor #3"
temp_ke = ds1820_read_temp(DS1820_pin_ke); //Get temperature from DS1820 "sensor #4"
temp_bo = ds1820_read_temp(DS1820_pin_bo); //Get temperature from DS1820 "sensor #5"

sprintf(temp_po_str,"%.1f C",temp_po); //Convert temp. "sensor #1" to string
sprintf(temp_pm_str,"%.1f C",temp_pm); //Convert temp. "sensor #2" to string
sprintf(temp_pu_str,"%.1f C",temp_pu); //Convert temp. "sensor #3" to string
sprintf(temp_ke_str,"%.1f C",temp_ke); //Convert temp. "sensor #4" to string
sprintf(temp_bo_str,"%.1f C",temp_bo); //Convert temp. "sensor #5" to string
}
}
// E N D  M A I N  P R O G R A M 
//#########################################
//#########################################
//#########################################

 

You can download the source file under GNU LGPL v2.1 here.

Last Updated on Saturday, September 04 2010 17:05  

Comments  

 
0 #1 2011-01-26 20:27
Hi Stefan,

Thanks for this stuff. I have built it with DS1820 and it works fine however does not work with DS 18B20S+ (it shows about -40 degree). Can you please help? Thanks!
Quote
 

Add comment


Security code
Refresh


Headlines

There are no translations available.


Hallo,
habe soeben die überarbeitete Fassung der Latex Installationsanleitung unter Windows online gestellt. Es wird jetzt auch die Inkscapeversion 0.48 in Verbindung mit dem textext-Plugin unterstützt.
http://sicklinger.com/de/latex-installationsanleitung.html