-
-
Notifications
You must be signed in to change notification settings - Fork 26
Home
Note: Work is still in progress, wiki is incomplete
Avr-dallas1820
is a C library for AVR microcontrollers to control DS1820 temperature sensors.
It's pretty simple to use and should work with most of AVR family devices.
Below you'll find description of functions and code snippets, have fun!
DS1820 temperature sensor
Whole library contains 4 files:
-
onewire.c
- contains OneWire communication protocol related things -
onewire.h
- OneWire function prototypes etc. -
ds1820.c
- contains stuff for using DS1820 sensor -
ds1820.h
- Dallas1820 function prototypes and other boring things
You need to add *.c
files to project and include *.h
files in your main file using #include
directive.
It should look like this:
#include "ds1820.h"
Basic wiring is really, really simple:
For testing you can use breadboard, AVR, two resistors, and couple of wires.
Using this library shouldn't be a problem for anyone, because of its simplicity. Below you can find code example for reading ROM and Temperature from sensor.
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include "uart.h"
#include "../include/ds1820.h"
char txt[80];
OnewireConf thermo = { &DDRB, &PORTB, &PINB, ( 1 << 0 ), 0, NULL };
int main( )
{
uartInit( 9600 );
while ( 1 )
{
//Read temperature
ds1820request( &thermo );
sprintf( txt, "raw: %d\n", ds18b20read( &thermo ) );
uartSend( txt );
//Delay
_delay_ms( 1000 );
}
return 0;
}
Above code step by step:
- Create variable with sensor configuration (Direction register, output register, input register, mask, etc.)
- In loop:
- Begin temperature conversion.
- Use data
- Wait 1s
###Specification For more technical specification visit this wiki page.