add examples

This commit is contained in:
Rob Tillaart 2023-10-16 15:40:41 +02:00
parent 3188e13658
commit d2ea84004d
4 changed files with 203 additions and 0 deletions

View File

@ -0,0 +1,29 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
- esp32
# - esp8266
# - mega2560
# - rpipico

View File

@ -0,0 +1,80 @@
//
// FILE: AM2315_Wire1.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for AM2315 I2C humidity & temperature sensor
// Wire1 on ESP32 (et al)
#include "AM2315.h"
#include "Wire.h"
AM2315 sensor(&Wire1);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AM2315_LIB_VERSION: ");
Serial.println(AM2315_LIB_VERSION);
Serial.println();
Wire.begin();
// Wire.setClock(100000);
while (sensor.begin() == false)
{
Serial.print(millis());
Serial.println("\tCould not connect to sensor.");
delay(1000);
}
delay(2000);
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C), \t micros");
delay(100);
}
void loop()
{
if (millis() - sensor.lastRead() >= 2000)
{
// READ DATA
uint32_t start = micros();
int status = sensor.read();
uint32_t stop = micros();
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:
Serial.print("error <");
Serial.print(status);
Serial.print(">,\t");
break;
}
// DISPLAY DATA, sensor has only one decimal.
Serial.print("AM2315, \t");
Serial.print(sensor.getHumidity(), 1);
Serial.print(",\t");
Serial.print(sensor.getTemperature(), 1);
Serial.print(",\t");
Serial.print(stop - start);
Serial.print("\n");
}
}
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
- esp32
# - esp8266
# - mega2560

View File

@ -0,0 +1,83 @@
//
// FILE: AM2315C_test_Wire1.ino
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for AM2315C I2C humidity & temperature sensor
//
// Always check datasheet
//
// +-----------------+
// RED -------- | VDD |
// YELLOW -------- | SDA AM2315C |
// BLACK -------- | GND |
// WHITE -------- | SCL |
// +-----------------+
#include "AM2315C.h"
AM2315C DHT(&Wire1);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AM2315C LIBRARY VERSION: ");
Serial.println(AM2315C_LIB_VERSION);
Serial.println();
Wire1.begin(12, 13); // ESP32 default pins 21 22
Wire1.setClock(400000);
DHT.begin();
delay(2000);
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("AM2315C, \t");
int status = DHT.read();
switch (status)
{
case AM2315C_OK:
Serial.print("OK,\t");
break;
case AM2315C_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case AM2315C_ERROR_CONNECT:
Serial.print("Connect error,\t");
break;
case AM2315C_MISSING_BYTES:
Serial.print("Missing bytes,\t");
break;
case AM2315C_ERROR_BYTES_ALL_ZERO:
Serial.print("All bytes read zero");
break;
case AM2315C_ERROR_READ_TIMEOUT:
Serial.print("Read time out");
break;
case AM2315C_ERROR_LASTREAD:
Serial.print("Error read too fast");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA, sensor has only one decimal.
Serial.print(DHT.getHumidity(), 1);
Serial.print(",\t");
Serial.println(DHT.getTemperature(), 1);
delay(2000);
}
// -- END OF FILE --