TOP Contributors

  1. MIKROE (2653 codes)
  2. Alcides Ramos (351 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (112 codes)
  5. Chisanga Mumba (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (136668 times)
  2. FAT32 Library (69902 times)
  3. Network Ethernet Library (55920 times)
  4. USB Device Library (46248 times)
  5. Network WiFi Library (41882 times)
  6. FT800 Library (41128 times)
  7. GSM click (28973 times)
  8. PID Library (26406 times)
  9. mikroSDK (26344 times)
  10. microSD click (25350 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
Library

DS18X20 One Wire Library

Rating:

5

Author: Richard Lowe

Last Updated: 2013-09-19

Package Version: 1.0.0.3

Category: Measurement

Downloaded: 3207 times

Followed by: 1 user

License: MIT license  

Easily add DS18x20 sensor functions to your project.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "DS18X20 One Wire Library" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "DS18X20 One Wire Library" changes.

Do you want to report abuse regarding "DS18X20 One Wire Library".

  • Information
  • Comments (0)

Library Blog


This is the first version.  This library assumes that it is the only sensor on the bus.  Sensor addressing is not yet supported.


Requirements: stdbool ( boolean definition file ) found on libstock


To use this library, you will need to edit the header file and define your port and pin.

Example:
//#define DS18X20_BASE_ADDRESS    &PORTA
//#define DS18X20_PIN             3
#define DS18X20_BASE_ADDRESS    &GPIOA_BASE
#define DS18X20_PIN             3

The example file included shows 2 different methods the library supports, polled and immediate.

Temp sensors are SLOW.  On a 8Mhz AVR with resolution set at 10 you will achieve 5-6 readings per second.  If the reading is not critical, then using the polled method works best.

There is also a formatted string function: ds18x20_get_str_temp( DS18X20_MODE_C ); that produces a formatted string based on MODE_C or MODE_F.

UPDATE:

Forgot about compiling into a library and macros....

This new version has a different initialization:

Example:

#include "ds18x20.h"

#define msg( txt ) UART1_Write_Text( txt )

void main() 
{
    ds18x20_config_t sensor;
    char txt_buffer[50];
    
    sensor.port = &PORTA;
    sensor.pin = 7;
    sensor.resolution = RES12;
    sensor.alarm_high = 0x22;
    sensor.alarm_low = 0x01;
    
    UART1_Init( 38400 );
    Delay_ms( 100 );
    
    ds18x20_init( &sensor );
    
    while(1)
    {
        sprintf( txt_buffer, "Temp is: %f\r\n", ds18x20_get_temp() );
        msg( txt_buffer );
        Delay_ms( 1000 );
    }

}

ALSO FROM THIS AUTHOR

AVR Webserver

0

AVR Webserver: Dependencies - FAT32 library, Ethernet library Will allow you to load any size website, including images, css, and js files from SD media. This is my first version, but the example project included will give you a starting point.

[Learn More]

Webserver - Full Featured

5

Example of what can be done with the Ethernet library. Server serves both dynamic / static content, retrieves time from NTP servers, downloads files from remote servers. Requires: Ethernet Library, FAT32 Library, Standard Bool Library

[Learn More]

STM DMA Library

15

This is the first of DMA functions that will be available for the ST line of ARM microcontrollers. The idea was born from a forum post. The idea worked so well I made it into a convenient MikroC library. So far.... memory to memory transfers is what is functional

[Learn More]