ModularSensors > Classes > Sensor > MPL115A2
ModularSensors > Modules > Freescale Semiconductor MPL115A2 > MPL115A2


MPL115A2 class

The Sensor sub-class for the Freescale Semiconductor MPL115A2 sensor.

Base classes

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

Constructors, destructors, conversion operators

MPL115A2(TwoWire* theI2C, int8_t powerPin, uint8_t measurementsToAverage = 1)
Construct a new MPL115A2 using a secondary hardware I2C instance.
MPL115A2(int8_t powerPin, uint8_t measurementsToAverage = 1) explicit
Construct a new MPL115A2 using the primary hardware I2C instance.
~MPL115A2()
Destroy the MPL115A2 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 addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

MPL115A2(TwoWire* theI2C, int8_t powerPin, uint8_t measurementsToAverage = 1)

Construct a new MPL115A2 using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the MPL115A2 Use -1 if it is continuously powered.

  • The MPL115A2 requires a 2.375 - 5.5V power source
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

MPL115A2(int8_t powerPin, uint8_t measurementsToAverage = 1) explicit

Construct a new MPL115A2 using the primary hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the MPL115A2 Use -1 if it is continuously powered.

  • The MPL115A2 requires a 2.375 - 5.5V power source
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

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 begins the Wire library (sets pin modes for I2C), reads coefficients from the MPL115A2, and updates the _sensorStatus. The sensor must be powered for setup. This doesn't return anything to indicate failure or success, we just have to hope it worked.


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.

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.