ModularSensors > Classes > Sensor > MaximDS18
ModularSensors > Modules > Maxim DS18 > MaximDS18


MaximDS18 class

The Sensor sub-class for the DS18 one-wire temperature sensors.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

MaximDS18(DeviceAddress OneWireAddress, int8_t powerPin, int8_t dataPin, uint8_t measurementsToAverage = 1)
Construct a new Maxim DS18 with a known sensor address.
MaximDS18(int8_t powerPin, int8_t dataPin, uint8_t measurementsToAverage = 1)
Construct a new Maxim DS18 for a single sensor with an unknown address.
~MaximDS18()
Destroy the Maxim DS18 object.

Public functions

bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
String getSensorLocation(void ) override
Get the pin or connection location between the mcu and the sensor.
bool startSingleMeasurement(void ) override
Tell the sensor to start a single measurement, if needed.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

MaximDS18(DeviceAddress OneWireAddress, int8_t powerPin, int8_t dataPin, uint8_t measurementsToAverage = 1)

Construct a new Maxim DS18 with a known sensor address.

Parameters
OneWireAddress The unique address of the sensor. Should be an array of 8 values. To get the address of your sensor, plug a single sensor into your device and run the oneWireSearch example or the Single example provided within the Dallas Temperature library. The sensor address is programmed at the factory and cannot be changed.
powerPin

The pin on the mcu controlling power to the DS18, if using a separate power pin. Use -1 if the DS18 is continuously powered or you are using "parasitic" power.

  • Requires a 3.0 - 5.5V power source
dataPin The pin on the mcu of the OneWire bus.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Use this version for more than one sensor attached to the OneWire bus.


MaximDS18(int8_t powerPin, int8_t dataPin, uint8_t measurementsToAverage = 1)

Construct a new Maxim DS18 for a single sensor with an unknown address.

Parameters
powerPin

The pin on the mcu controlling power to the DS18, if using a separate power pin. Use -1 if the DS18 is continuously powered or you are using "parasitic" power.

  • Requires a 3.0 - 5.5V power source
dataPin The pin on the mcu of the OneWire bus.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Use this version of the constructor when there is only one temperature sensor attached to the OneWire bus and the address of that sensor is not known.


boolsetup(void ) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets the pin modes and verifies the DS18's address. It also verifies that the sensor is connected, reporting maximum resolution, and operating in ASYNC mode and updates the _sensorStatus. The sensor must be powered for setup.


StringgetSensorLocation(void ) override

Get the pin or connection location between the mcu and the sensor.

Returns String Text describing how the sensor is attached to the mcu.

boolstartSingleMeasurement(void ) override

Tell the sensor to start a single measurement, if needed.

Returns bool True if the start measurement function completed successfully. successfully.

This also sets the _millisMeasurementRequested timestamp.


booladdSingleMeasurementResult(void ) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.