Library for reading temperature from DS1820, DS18B20 and DS1822

Dependencies:   LinkedList

Dependents:   heatmap BLE_Temperature BLE_Temperature_Exercise F334andDS18B20 ... more

Fork of DS1820 by David Pairman

Embed: (wiki syntax)

« Back to documentation index

DS1820 Class Reference

DS1820 Dallas 1-Wire Temperature Probe. More...

#include <DS1820.h>

Public Member Functions

 DS1820 (PinName data_pin, PinName power_pin=NC, bool power_polarity=0)
 Create a probe object connected to the specified pins.
int convertTemperature (bool wait, devices device=all_devices)
 This routine will initiate the temperature conversion within one or all DS1820 probes.
float temperature (char scale='c')
 This function will return the probe temperature.
bool setResolution (unsigned int resolution)
 This function sets the temperature resolution for the DS18B20 in the configuration register.

Static Public Member Functions

static bool unassignedProbe (PinName pin)
 Function to see if there are DS1820 devices left on a pin which do not have a corresponding DS1820 object.

Detailed Description

DS1820 Dallas 1-Wire Temperature Probe.

Example:

 #include "mbed.h"
 #include "DS1820.h"

 DS1820 probe(DATA_PIN);
  
 int main() {
     while(1) {
         probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
         printf("It is %3.1foC\r\n", probe.temperature());
         wait(1);
     }
 }

Definition at line 52 of file DS1820.h.


Constructor & Destructor Documentation

DS1820 ( PinName  data_pin,
PinName  power_pin = NC,
bool  power_polarity = 0 
)

Create a probe object connected to the specified pins.

The probe might either by regular powered or parasite powered. If it is parasite powered and power_pin is set, that pin will be used to switch an external mosfet connecting data to Vdd. If it is parasite powered and the pin is not set, the regular data pin is used to supply extra power when required. This will be sufficient as long as the number of probes is limitted.

Parameters:
data_pinDigitalInOut pin for the data bus
power_pinDigitalOut (optional) pin to control the power MOSFET
power_polaritybool (optional) which sets active state (0 for active low (default), 1 for active high)

Definition at line 39 of file DS1820.cpp.


Member Function Documentation

int convertTemperature ( bool  wait,
devices  device = all_devices 
)

This routine will initiate the temperature conversion within one or all DS1820 probes.

Parameters:
waitif true or parisitic power is used, waits up to 750 ms for conversion otherwise returns immediatly.
deviceallows the function to apply to a specific device or to all devices on the 1-Wire bus.
Returns:
milliseconds untill conversion will complete.

Definition at line 304 of file DS1820.cpp.

bool setResolution ( unsigned int  resolution )

This function sets the temperature resolution for the DS18B20 in the configuration register.

Parameters:
anumber between 9 and 12 to specify resolution
Returns:
true if successful

Definition at line 359 of file DS1820.cpp.

float temperature ( char  scale = 'c' )

This function will return the probe temperature.

Approximately 10ms per probe to read its RAM, do CRC check and convert temperature on the LPC1768.

Parameters:
scale,maybe either 'c' or 'f'
Returns:
temperature for that scale, or DS1820::invalid_conversion (-1000) if CRC error detected.

Definition at line 384 of file DS1820.cpp.

bool unassignedProbe ( PinName  pin ) [static]

Function to see if there are DS1820 devices left on a pin which do not have a corresponding DS1820 object.

Returns:
- true if there are one or more unassigned devices, otherwise false

Definition at line 130 of file DS1820.cpp.