AM2321 Temperature and Humidity Sensor mbed library

Dependents:   AM2321_Example mbed_vfd_thermometer

Embed: (wiki syntax)

« Back to documentation index

AM2321 Class Reference

AM2321 Class Reference

AM2321 (Aosong Guangzhou Electronics) Temperature and Humidity Sensor mbed library. More...

#include <AM2321.h>

Public Member Functions

 AM2321 (PinName sda, PinName scl)
 Constructor.
bool poll ()
 Read current temperature and humidity from AM2321.
float getTemperature (void) const
 Get last read temperature value.
float getHumidity (void) const
 Get last read humidity value.

Detailed Description

AM2321 (Aosong Guangzhou Electronics) Temperature and Humidity Sensor mbed library.

Example:

 #include "mbed.h"
 #include "AM2321.h"

 Serial pc(USBTX, USBRX);    // Tx, Rx
 AM2321 am2321(p28, p27);    // SDA, SCL

 int main()
 {
     while(1)
     {
        if(am2321.poll())
         {
             pc.printf(":%05u,%.1f,%.1f\n"
                 , count++
                 , am2321.getTemperature()
                 , am2321.getHumidity()
             );
         }
 
         wait(0.5);
     }
 }

Definition at line 39 of file AM2321.h.


Constructor & Destructor Documentation

AM2321 ( PinName  sda,
PinName  scl 
)

Constructor.

Parameters:
sda[in] I2C Pin name (SDA)
scl[in] I2C Pin name (SCL)

Definition at line 18 of file AM2321.cpp.


Member Function Documentation

float getHumidity ( void   ) const

Get last read humidity value.

Returns:
humidity value (RH)

Definition at line 113 of file AM2321.cpp.

float getTemperature ( void   ) const

Get last read temperature value.

Returns:
temperature value (degress)

Definition at line 108 of file AM2321.cpp.

bool poll ( void   )

Read current temperature and humidity from AM2321.

Returns:
result (true=success)

Definition at line 63 of file AM2321.cpp.