2022-01-06 06:08:13 -05:00
|
|
|
//
|
|
|
|
// FILE: AM2315_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: Demo for AM2315 I2C humidity & temperature sensor
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "AM2315.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
|
|
|
AM2315 sensor(&Wire);
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
sensor.begin();
|
2023-01-21 09:19:08 -05:00
|
|
|
// adjust your offsets if needed
|
|
|
|
// sensor.setTempOffset(-0.8);
|
|
|
|
// sensor.setHumOffset(1.2);
|
2022-01-06 06:08:13 -05:00
|
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("AM2315_LIB_VERSION: ");
|
|
|
|
Serial.println(AM2315_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
delay(2000);
|
|
|
|
|
|
|
|
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
if (millis() - sensor.lastRead() >= 2000)
|
|
|
|
{
|
2023-01-21 09:19:08 -05:00
|
|
|
// READ DATA
|
2022-01-06 06:08:13 -05:00
|
|
|
Serial.print("AM2315, \t");
|
|
|
|
int status = sensor.read();
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case AM2315_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case AM2315_ERROR_CHECKSUM:
|
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case AM2315_ERROR_CONNECT:
|
|
|
|
Serial.print("Connect error,\t");
|
|
|
|
break;
|
|
|
|
case AM2315_MISSING_BYTES:
|
|
|
|
Serial.print("Bytes error,\t");
|
|
|
|
break;
|
|
|
|
default:
|
2023-01-21 09:19:08 -05:00
|
|
|
Serial.print("error <");
|
|
|
|
Serial.print(status);
|
|
|
|
Serial.print(">,\t");
|
2022-01-06 06:08:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2023-01-21 09:19:08 -05:00
|
|
|
// DISPLAY DATA, sensor has only one decimal.
|
2022-01-06 06:08:13 -05:00
|
|
|
Serial.print(sensor.getHumidity(), 1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.println(sensor.getTemperature(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 09:19:08 -05:00
|
|
|
// -- END OF FILE --
|
|
|
|
|