WebbotLib AVR library
WebbotLib It just does it
C++documentationCdocumentation

Maxim/DS18B20.h

Adds support for the DS18B20 thermometer.
This thermometer should be connected to a one wire bus - see oneWireBus.h. It can measure temperatures in the range -55C to +125C and only requires about 1.5mA of power.
It can be connected in any one of two ways:-
DS18B20-2-PIN.jpg
'Parasitic' mode - whereby the device is powered via the bus. This requires less pins but takes longer to return temperate readings.
DS18B20-3-PIN.jpg
Requires an additional power line (3v to 5.5v) but returns temperature readings more quickly.
You can change between the two methods without having to modify your program because WebbotLib works out, at runtime, which method you have used.
The 'family code' of the ROM ID is 0x28.
It may be defined using:
DS18B20 sensor = MAKE_DS18B20(DS18B20_RESOLUTION_9_BIT);
The resolution can be any one of the following values where larger bit values give you better accuracy but are slower to calculate:
DS18B20_RESOLUTION_9_BIT
DS18B20_RESOLUTION_10_BIT
DS18B20_RESOLUTION_11_BIT
DS18B20_RESOLUTION_12_BIT
It must then be added to a one wire bus:-
// Create the list of devices in PROGMEM
// Each device should have '._wire1_' at the end
ONE_WIRE_DEVICE_LIST PROGMEM devices = { &sensor._wire1_ };
// Create the bus using pin C0 as the signal wire
ONE_WIRE_BUS bus = MAKE_ONE_WIRE_BUS( C0, &devices );
The sensor should be initialised in appInitHardware using:-
temperatureInit(sensor);
The sensor can then be read using:-
temperatureRead(sensor);
and then the temperature will be in sensor.temperature.celsius

Valid XHTML 1.0 Transitional