Skip to content

Commit

Permalink
Merge pull request #7 from hasenradball/add_sensor_check
Browse files Browse the repository at this point in the history
Update AM2302 Sensor v1.3.0
  • Loading branch information
hasenradball authored Dec 15, 2023
2 parents 96a4f05 + 0066225 commit 51442b7
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 190 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
[![Spell Check](https://github.com/hasenradball/AM2302-Sensor/actions/workflows/spell_checker.yml/badge.svg)](https://github.com/hasenradball/AM2302-Sensor/actions/workflows/spell_checker.yml)
[![Compile Examples](https://github.com/hasenradball/AM2302-Sensor/actions/workflows/compile_examples.yml/badge.svg)](https://github.com/hasenradball/AM2302-Sensor/actions/workflows/compile_examples.yml)

Sensor Library for the AM2302 Sensor (aka DHT22) from ASAIR
Sensor Library for the AM2302 Sensor (aka DHT22) from ASAIR.<br>
This Library is a controller independent library for reading the AM2302 Sensor also known as DHT22.

![AM2302-Sensor](./docs/AM2302.jpg)
![AM2302-Sensor Adapter](./docs/AM2302_sensor_adapter.png)


## Contents
Expand Down
Binary file added docs/AM2302_sensor_adapter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/AM2302_sensor_adapter_org.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 32 additions & 25 deletions examples/AM2302-Sensor_Example/AM2302-Sensor_Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,41 @@

#include <AM2302-Sensor.h>

AM2302::AM2302_Sensor am2302{7};
constexpr unsigned int SENSOR_PIN {7U};

AM2302::AM2302_Sensor am2302{SENSOR_PIN};

void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.print(F("\n >>> AM2302-Sensor_Example <<<\n\n"));

// put your setup code here, to run once:
//set Pin
am2302.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.print(F("\n >>> AM2302-Sensor_Example <<<\n\n"));

// set pin and check for sensor
if (am2302.begin()) {
// this delay is needed to receive valid data,
// when the loop directly read again
delay(3000);
}
else {
while (true) {
Serial.println("Error: sensor check. => Please check sensor connection!");
delay(10000);
}
}
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);
auto status = am2302.read();
Serial.print("\n\nstatus of sensor read(): ");
Serial.println(status);

Serial.print("Temperature: ");
Serial.println(am2302.get_Temperature());

Serial.print("Humidity: ");
Serial.println(am2302.get_Hunidity());
digitalWrite(LED_BUILTIN, LOW);
delay(5000);
// put your main code here, to run repeatedly:
auto status = am2302.read();
Serial.print("\n\nstatus of sensor read(): ");
Serial.println(status);

Serial.print("Temperature: ");
Serial.println(am2302.get_Temperature());

Serial.print("Humidity: ");
Serial.println(am2302.get_Humidity());
delay(5000);
}
52 changes: 33 additions & 19 deletions examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,63 @@

#include <AM2302-Sensor.h>

AM2302::AM2302_Sensor am2302{7};
constexpr unsigned int SENSOR_PIN {7U};

AM2302::AM2302_Sensor am2302{SENSOR_PIN};

void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.print(F("\n >>> AM2302-sensor Health Check <<<\n\n"));
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.print(F("\n >>> AM2302-sensor Health Check <<<\n\n"));

// put your setup code here, to run once:
//set Pin
am2302.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// put your setup code here, to run once:
// set pin and check for sensor
if (am2302.begin()) {
// this delay is needed to receive valid data,
// when the loop directly read again
delay(3000);
}
else {
while (true) {
Serial.println("Error: sensor check. => Please check sensor connection!");
delay(10000);
}
}
}

void loop() {
static int checksum_err{0}, timeout_err {0};
static int checksum_err{0}, timeout_err {0}, read_freq_err {0};
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);
auto status = am2302.read();
if (status == AM2302::AM2302_ERROR_CHECKSUM) {
++checksum_err;
}
if (status == AM2302::AM2302_ERROR_TIMEOUT) {
++timeout_err;
}
if (status == AM2302::AM2302_ERROR_READ_FREQ) {
++read_freq_err;
}
Serial.print("\n\n");
Serial.print("Sensor status: ");
Serial.print("Sensor status: ");
Serial.println(status);

Serial.print("Number checksum errors: ");
Serial.print("Number checksum errors: ");
Serial.println(checksum_err);

Serial.print("Number timeout errors: ");
Serial.print("Number timeout errors: ");
Serial.println(timeout_err);

Serial.print("Number read freq errors: ");
Serial.println(read_freq_err);

Serial.print("\n\n");
Serial.print("Temperature: ");
Serial.println(am2302.get_Temperature());

Serial.print("Humidity: ");
Serial.println(am2302.get_Hunidity());
digitalWrite(LED_BUILTIN, LOW);
delay(5000);
Serial.println(am2302.get_Humidity());
delay(10000);
}
12 changes: 6 additions & 6 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# Library (KEYWORD1)
#######################################
# => Namespace
AM2302 KEYWORD1
AM2302-Sensor KEYWORD1
AM2302 KEYWORD1
AM2302-Sensor KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
read KEYWORD2
get_Temperature KEYWORD2
get_Humidity KEYWORD2
begin KEYWORD2
read KEYWORD2
get_Temperature KEYWORD2
get_Humidity KEYWORD2


#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AM2302-Sensor",
"version": "1.2.2",
"version": "1.3.0",
"repository":
{
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AM2302-Sensor
version=1.2.2
version=1.3.0
author=Frank Häfele <[email protected]>
maintainer=Frank Häfele <[email protected]>
sentence=This library read temperature and humidity from the AM2302 (aka DHT22) senor.
Expand Down
Loading

0 comments on commit 51442b7

Please sign in to comment.