2017-12-12 07:23:41 -05:00
|
|
|
//
|
|
|
|
// FILE: AM2320_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: demo sketch for AM2320 I2C humidity & temperature sensor
|
|
|
|
//
|
2022-01-06 08:05:38 -05:00
|
|
|
// AM232X PIN layout AM2315 COLOR
|
|
|
|
// ============================================
|
|
|
|
// bottom view DESCRIPTION COLOR
|
2021-02-03 11:20:20 -05:00
|
|
|
// +---+
|
2022-01-06 08:05:38 -05:00
|
|
|
// |o | VDD RED
|
|
|
|
// |o | SDA YELLOW
|
|
|
|
// |o | GND BLACK
|
|
|
|
// |o | SCL GREY
|
2021-02-03 11:20:20 -05:00
|
|
|
// +---+
|
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
|
|
|
|
2022-01-06 08:05:38 -05:00
|
|
|
#include "AM232X.h"
|
2017-12-12 07:23:41 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2022-01-06 08:05:38 -05:00
|
|
|
AM2320.wakeUp();
|
|
|
|
delay(2000);
|
2017-12-12 10:28:41 -05:00
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
// sensor only returns one decimal.
|
2017-12-12 10:28:41 -05:00
|
|
|
Serial.println();
|
2017-12-12 10:43:02 -05:00
|
|
|
Serial.println("Read:\t");
|
2022-01-06 08:05:38 -05:00
|
|
|
|
2017-12-12 10:28:41 -05:00
|
|
|
int status = AM2320.read();
|
|
|
|
switch (status)
|
|
|
|
{
|
2022-01-06 08:05:38 -05:00
|
|
|
case AM232X_OK:
|
|
|
|
Serial.println("OK");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println(status);
|
|
|
|
break;
|
2017-12-12 10:28:41 -05:00
|
|
|
}
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print("Temperature:\t");
|
2020-05-07 03:53:25 -04:00
|
|
|
Serial.println(AM2320.getTemperature(), 1);
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" Humidity:\t");
|
2020-05-07 03:53:25 -04:00
|
|
|
Serial.println(AM2320.getHumidity(), 1);
|
2017-12-12 10:28:41 -05:00
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("GET SENSOR INFO (experimental)");
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" Model:\t");
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println(AM2320.getModel());
|
|
|
|
Serial.print("Version:\t");
|
|
|
|
Serial.println(AM2320.getVersion());
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" DevId:\t");
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println(AM2320.getDeviceID());
|
2017-12-12 10:28:41 -05:00
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("GET REGISTERS (experimental)");
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" Status:\t");
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println(AM2320.getStatus());
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" UserA:\t");
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println(AM2320.getUserRegisterA());
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print(" UserB:\t");
|
2017-12-12 07:23:41 -05:00
|
|
|
Serial.println(AM2320.getUserRegisterB());
|
|
|
|
|
2017-12-12 10:28:41 -05:00
|
|
|
Serial.println();
|
|
|
|
Serial.println("SET REGISTERS (experimental)");
|
|
|
|
AM2320.setStatus(42);
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print("Status 42 ==> ");
|
2017-12-12 10:28:41 -05:00
|
|
|
Serial.println(AM2320.getStatus());
|
|
|
|
AM2320.setUserRegisterA(1234);
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print("UserA 1234 ==> ");
|
2017-12-12 10:28:41 -05:00
|
|
|
Serial.println(AM2320.getUserRegisterA());
|
|
|
|
AM2320.setUserRegisterB(5678);
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.print("UserB 5678 ==> ");
|
2017-12-12 10:28:41 -05:00
|
|
|
Serial.println(AM2320.getUserRegisterB());
|
|
|
|
|
2022-01-06 08:05:38 -05:00
|
|
|
Serial.println("done...\n");
|
2017-12-12 07:23:41 -05:00
|
|
|
}
|
|
|
|
|
2021-02-03 11:20:20 -05:00
|
|
|
|
2017-12-12 07:23:41 -05:00
|
|
|
void loop()
|
|
|
|
{
|
2022-01-06 08:05:38 -05:00
|
|
|
delay(2000);
|
|
|
|
|
|
|
|
int status = AM2320.read();
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case AM232X_OK:
|
|
|
|
Serial.println("OK");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println(status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Serial.print("Temp:\t");
|
|
|
|
Serial.println(AM2320.getTemperature(), 1);
|
|
|
|
Serial.print("Hum:\t");
|
|
|
|
Serial.println(AM2320.getHumidity(), 1);
|
2017-12-12 07:23:41 -05:00
|
|
|
}
|
|
|
|
|
2021-10-19 05:51:07 -04:00
|
|
|
|
2020-05-07 03:53:25 -04:00
|
|
|
// -- END OF FILE --
|