ModularSensors > Classes > Sensor > AOSongAM2315
ModularSensors > Modules > AOSong AM2315 > AOSongAM2315


AOSongAM2315 class

The Sensor sub-class for the AOSong AM2315.

Base classes

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

Constructors, destructors, conversion operators

AOSongAM2315(TwoWire* theI2C, int8_t powerPin, uint8_t measurementsToAverage = 1)
Construct a new AOSongAM2315 object using a secondary hardware I2C instance.
AOSongAM2315(int8_t powerPin, uint8_t measurementsToAverage = 1) explicit
Construct a new AOSongAM2315 object using the primary hardware I2C instance.
~AOSongAM2315()
Destroy the AOSongAM2315 object - no action needed.

Public functions

String getSensorLocation(void ) override
Report the I2C address of the AM2315 - which is always 0xB8.
bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

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

Construct a new AOSongAM2315 object 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 AOSong AM2315. Use -1 if it is continuously powered.

  • The AM2315 requires a 3.3 - 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.

This is only applicable to SAMD boards that are able to have multiple hardware I2C ports in use via SERCOMs.


AOSongAM2315(int8_t powerPin, uint8_t measurementsToAverage = 1) explicit

Construct a new AOSongAM2315 object using the primary hardware I2C instance.

Parameters
powerPin

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

  • The AM2315 requires a 3.3 - 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.

Because this is I2C and has only 1 possible address (0xB8), we only need the power pin.


StringgetSensorLocation(void ) override

Report the I2C address of the AM2315 - which is always 0xB8.

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

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. For the AOSong AM2315 the result will always be true.

This sets the _powerPin mode, begins the Wire library (sets pin levels and modes for I2C), and updates the _sensorStatus. No sensor power is required.


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.