
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:
- Temperature range: -55°C to 125°C
- 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)
- For negative temperature values the step size is 0.5°C
- 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.
- Only one sensor per ATMEGA Pin can be used
- 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.
Comments
Thanks for this stuff. I have built it with DS1820 and it works fine
RSS feed for comments to this post.