2017-12-12 07:23:41 -05:00
|
|
|
//
|
|
|
|
// FILE: AM2320.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-02-03 11:20:20 -05:00
|
|
|
// VERSION: 0.1.2
|
2017-12-12 07:23:41 -05:00
|
|
|
// PURPOSE: AM2320 demo sketch for AM2320 I2C humidity & temperature sensor
|
|
|
|
//
|
|
|
|
// HISTORY:
|
2021-02-03 11:20:20 -05:00
|
|
|
// 0.1.0 2017-12-11 initial version
|
|
|
|
// 0.1.1 2020-05-03 updated to 0.2.0 version of lib.
|
|
|
|
// 0.1.2 2021-01-28 added begin() ++
|
|
|
|
|
|
|
|
// Bottom view
|
|
|
|
// +---+
|
|
|
|
// VDD |o |
|
|
|
|
// SDA |o |
|
|
|
|
// GND |o |
|
|
|
|
// SCL |o |
|
|
|
|
// +---+
|
2017-12-12 07:23:41 -05:00
|
|
|
//
|
2021-02-03 11:20:20 -05:00
|
|
|
// do not forget pull up resistors between SDA, SCL and VDD.
|
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
|
|
|
|
#include <AM232X.h>
|
|
|
|
|
|
|
|
AM232X AM2320;
|
|
|
|
|
2021-02-03 11:20:20 -05:00
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(AM232X_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
|
2021-02-03 11:20:20 -05:00
|
|
|
if (! AM2320.begin() )
|
|
|
|
{
|
|
|
|
Serial.println("Sensor not found");
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
|
|
|
|
}
|
|
|
|
|
2021-02-03 11:20:20 -05:00
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// READ DATA
|
2017-12-12 10:43:02 -05:00
|
|
|
Serial.print("AM2320, \t");
|
2017-12-12 07:23:41 -05:00
|
|
|
int status = AM2320.read();
|
|
|
|
switch (status)
|
|
|
|
{
|
2021-02-03 11:20:20 -05:00
|
|
|
case AM232X_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.print(status);
|
|
|
|
Serial.print("\t");
|
|
|
|
break;
|
2017-12-12 07:23:41 -05:00
|
|
|
}
|
|
|
|
// DISPLAY DATA, sensor only returns one decimal.
|
2020-05-07 03:53:25 -04:00
|
|
|
Serial.print(AM2320.getHumidity(), 1);
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.print(",\t");
|
2020-05-07 03:53:25 -04:00
|
|
|
Serial.println(AM2320.getTemperature(), 1);
|
2017-12-12 07:23:41 -05:00
|
|
|
|
|
|
|
delay(2000);
|
|
|
|
}
|
|
|
|
|
2020-05-07 03:53:25 -04:00
|
|
|
// -- END OF FILE --
|