diff --git a/README.md b/README.md index c1b6a79..e25d56b 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,79 @@ -# ScioSense ENS21x +# ScioSense ENS21x Arduino Library Arduino library for the ENS21x temperature & humidity sensor family with I2C interface from ScioSense. -## Introduction -This project is an Arduino *library*. It implements a driver with examples for the ENS21x sensor family. ENS21x chips are digital temperature & humidity sensors with an I2C interface. + -Note that the ENS21x requires a supply voltage of 1.71V .. 3.60V. +The ENS21x is a family of high-performance digital temperature and humidity sensors produced by +[ScioSense](http://www.sciosense.com). With industry leading accuracies down to 0.1°C temperature and 0.8% relative +humidity, their rapid response and reliable, long-term performance the ENS21x family addresses the fields of home +appliances, building and automotive HVAC, cold chain management, personal health and wellness monitoring, industrial +automation and instrumentation. + +The ENS21x family includes the ENS210, ENS211, ENS212, ENS213A and the ENS215. ## Links -The ENS21x sensors are made by [ScioSense](http://www.sciosense.com). - - In the library, an implementation for the ENS210 is given. The datasheet and further documents for this sensor can be downloaded here - https://www.sciosense.com/products/relative-humidity-and-temperature-sensors/ens210-relative-humidity-and-temperature-sensor/ - +* [Further information about the ENS21x](https://www.sciosense.com/products/relative-humidity-and-temperature-sensors/ens210-relative-humidity-and-temperature-sensor/) +* [Datasheet](https://www.sciosense.com/wp-content/uploads/2023/06/SC-001822-DS-3-ENS21x-Datasheet.pdf) +* [Application notes](https://www.sciosense.com/wp-content/uploads/documents/SC-001928-AN-1-ENS21xA-Design-Guidelines.pdf) +* Buy the ENS210 on [Mouser](https://mou.sr/3P3DWmK) or [Digikey](https://www.digikey.nl/en/products/detail/sciosense/ENS210-LQFM/6490747) +* Buy the ENS210 evaluation kit on [Mouser](https://mou.sr/44GNQAi) + + ## Prerequisites It is assumed that - The Arduino IDE has been installed. If not, refer to "Install the Arduino Desktop IDE" on the [Arduino site](https://www.arduino.cc/en/Guide/HomePage). - - The library directory is at its default location. - For me, that is `C:\Users\sciosense\Documents\Arduino\libraries`. + - Install your board. This library was tested with the ESP32. Here is a step-by-step guide for board installation +(coming soon). + ## Installation -### Installation via Arduino Library Manager -- In the Arduino IDE, navigate to the Arduino Library Manager on the left side (or, alternatively, select Sketch > Include Library > Manage Libraries...) +### Installation via Arduino Library Manager (coming soon) +- In the Arduino IDE, navigate to the Arduino Library Manager on the left side (or, alternatively, select Sketch > +Include Library > Manage Libraries...) - Search for `ScioSense_ENS21x` - Select the library from the search results and press `Install` ### Manual installation -- Download the code from this repo via Download ZIP. +- Download the code from this repository via "Download ZIP". - In Arduino IDE, select Sketch > Include Library > Add .ZIP library... and browse to the just downloaded ZIP file. -- When the IDE is ready this README.md should be located at e.g. `C:\Users\sciosense\Documents\Arduino\libraries\ScioSense_ENS21x\README.md`. +- When the IDE is ready this README.md should be located at `C:\Users\[your_username]\Documents\Arduino\libraries\ScioSense_ENS21x\README.md`. + + +## Wiring + +### General +Please make sure that you use the correct supply voltage: The ENS21x runs at VDD = 1.71...3.60 V. + +### Example with ESP32 (I2C) +This example shows how to wire a [ESP32DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html#get-started-esp32-devkitc-board-front) +with the ENS21x flex foil for I2C communication. + +| ENS21x flex foil | ESP32 | +|:----------------:|:-----:| +| VDD | 3V3 | +| GND | GND | +| SDA | G21 | +| SCL | G22 | + + ## Build an example To build an example sketch - (Re)start Arduino. - - Open File > Examples > Examples from Custom Libraries > ScioSense ENS21x > 01_Basic (or any other of the provided examples you wish to run) + - Open File > Examples > Examples from Custom Libraries > ScioSense_ENS21x > 01_Basic (or any other of the provided +examples you wish to run) - Make sure Tools > Board lists the correct board. - Select Sketch > Verify/Compile. +## Contributing +Contributions in the form of issue opening or creating pull requests are very welcome! + ## Acknowledgements This library is developed for ScioSense by [at² GmbH](https://www.at2-software.com/en/) @at2software - -### ScioSense is a Joint Venture of ams AG \ No newline at end of file +### ScioSense is a Joint Venture of ams AG diff --git a/examples/01_Basic/01_Basic.ino b/examples/01_Basic/ENS210/ENS210.ino similarity index 90% rename from examples/01_Basic/01_Basic.ino rename to examples/01_Basic/ENS210/ENS210.ino index 80bae2d..513145c 100644 --- a/examples/01_Basic/01_Basic.ino +++ b/examples/01_Basic/ENS210/ENS210.ino @@ -29,11 +29,11 @@ void loop() float temperatureCelsius = ens210.getTempCelsius(); float humidityPercent = ens210.getHumidityPercent(); - Serial.print("Temperature: "); + Serial.print("Temperature:"); Serial.print(temperatureCelsius); Serial.print("°C\t"); - Serial.print("Humidity: "); + Serial.print("Humidity:"); Serial.print(humidityPercent); Serial.println("%"); } diff --git a/examples/01_Basic/ENS211/ENS211.ino b/examples/01_Basic/ENS211/ENS211.ino new file mode 100644 index 0000000..603c263 --- /dev/null +++ b/examples/01_Basic/ENS211/ENS211.ino @@ -0,0 +1,42 @@ +#include +#include + +#include "ens211.h" + +using namespace ScioSense; + +ENS211 ens211; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens211.begin(); + + if (ens211.isConnected() == false) + { + Serial.println("Error -- The ENS211 is not connected."); + while(1); + } +} + +void loop() +{ + if (ens211.singleShotMeasure() == ENS211::Result::STATUS_OK) + { + float temperatureCelsius = ens211.getTempCelsius(); + float humidityPercent = ens211.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + } + + delay(1000); +} \ No newline at end of file diff --git a/examples/01_Basic/ENS212/ENS212.ino b/examples/01_Basic/ENS212/ENS212.ino new file mode 100644 index 0000000..70b61d6 --- /dev/null +++ b/examples/01_Basic/ENS212/ENS212.ino @@ -0,0 +1,42 @@ +#include +#include + +#include "ens212.h" + +using namespace ScioSense; + +ENS212 ens212; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens212.begin(); + + if (ens212.isConnected() == false) + { + Serial.println("Error -- The ENS212 is not connected."); + while(1); + } +} + +void loop() +{ + if (ens212.singleShotMeasure() == ENS212::Result::STATUS_OK) + { + float temperatureCelsius = ens212.getTempCelsius(); + float humidityPercent = ens212.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + } + + delay(1000); +} \ No newline at end of file diff --git a/examples/01_Basic/ENS213A/ENS213A.ino b/examples/01_Basic/ENS213A/ENS213A.ino new file mode 100644 index 0000000..fa08738 --- /dev/null +++ b/examples/01_Basic/ENS213A/ENS213A.ino @@ -0,0 +1,42 @@ +#include +#include + +#include "ens213a.h" + +using namespace ScioSense; + +ENS213A ens213a; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens213a.begin(); + + if (ens213a.isConnected() == false) + { + Serial.println("Error -- The ENS213A is not connected."); + while(1); + } +} + +void loop() +{ + if (ens213a.singleShotMeasure() == ENS213A::Result::STATUS_OK) + { + float temperatureCelsius = ens213a.getTempCelsius(); + float humidityPercent = ens213a.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + } + + delay(1000); +} \ No newline at end of file diff --git a/examples/01_Basic/ENS215/ENS215.ino b/examples/01_Basic/ENS215/ENS215.ino new file mode 100644 index 0000000..40945ae --- /dev/null +++ b/examples/01_Basic/ENS215/ENS215.ino @@ -0,0 +1,42 @@ +#include +#include + +#include "ens215.h" + +using namespace ScioSense; + +ENS215 ens215; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens215.begin(); + + if (ens215.isConnected() == false) + { + Serial.println("Error -- The ENS215 is not connected."); + while(1); + } +} + +void loop() +{ + if (ens215.singleShotMeasure() == ENS215::Result::STATUS_OK) + { + float temperatureCelsius = ens215.getTempCelsius(); + float humidityPercent = ens215.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + } + + delay(1000); +} \ No newline at end of file diff --git a/examples/02_Continuous_Mode/02_Continuous_Mode.ino b/examples/02_Continuous_Mode/ENS210/ENS210.ino similarity index 93% rename from examples/02_Continuous_Mode/02_Continuous_Mode.ino rename to examples/02_Continuous_Mode/ENS210/ENS210.ino index 8826815..fe9d302 100644 --- a/examples/02_Continuous_Mode/02_Continuous_Mode.ino +++ b/examples/02_Continuous_Mode/ENS210/ENS210.ino @@ -42,11 +42,11 @@ void loop() float temperatureCelsius = ens210.getTempCelsius(); float humidityPercent = ens210.getHumidityPercent(); - Serial.print("Temperature: "); + Serial.print("Temperature:"); Serial.print(temperatureCelsius); Serial.print("°C\t"); - Serial.print("Humidity: "); + Serial.print("Humidity:"); Serial.print(humidityPercent); Serial.println("%"); ens210.getStatusH(); diff --git a/examples/02_Continuous_Mode/ENS211/ENS211.ino b/examples/02_Continuous_Mode/ENS211/ENS211.ino new file mode 100644 index 0000000..1d52673 --- /dev/null +++ b/examples/02_Continuous_Mode/ENS211/ENS211.ino @@ -0,0 +1,54 @@ +#include +#include + +#include "ens211.h" + +using namespace ScioSense; + +ENS211 ens211; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens211.begin(); + + if (ens211.isConnected() == false) + { + Serial.println("Error -- The ENS211 is not connected."); + while(1); + } + + ens211.reset(); + + Serial.print("Starting continous mode.."); + while (ens211.startContinuousMeasure() != ENS211::Result::STATUS_OK) + { + Serial.print("."); + delay(ENS211::SystemTiming::BOOTING); + } + Serial.println(" Done!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens211.update() == ENS211::Result::STATUS_OK) + { + float temperatureCelsius = ens211.getTempCelsius(); + float humidityPercent = ens211.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + ens211.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/02_Continuous_Mode/ENS212/ENS212.ino b/examples/02_Continuous_Mode/ENS212/ENS212.ino new file mode 100644 index 0000000..c22869a --- /dev/null +++ b/examples/02_Continuous_Mode/ENS212/ENS212.ino @@ -0,0 +1,54 @@ +#include +#include + +#include "ens212.h" + +using namespace ScioSense; + +ENS212 ens212; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens212.begin(); + + if (ens212.isConnected() == false) + { + Serial.println("Error -- The ENS212 is not connected."); + while(1); + } + + ens212.reset(); + + Serial.print("Starting continous mode.."); + while (ens212.startContinuousMeasure() != ENS212::Result::STATUS_OK) + { + Serial.print("."); + delay(ENS212::SystemTiming::BOOTING); + } + Serial.println(" Done!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens212.update() == ENS212::Result::STATUS_OK) + { + float temperatureCelsius = ens212.getTempCelsius(); + float humidityPercent = ens212.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + ens212.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/02_Continuous_Mode/ENS213A/ENS213A.ino b/examples/02_Continuous_Mode/ENS213A/ENS213A.ino new file mode 100644 index 0000000..0f744f0 --- /dev/null +++ b/examples/02_Continuous_Mode/ENS213A/ENS213A.ino @@ -0,0 +1,54 @@ +#include +#include + +#include "ens213a.h" + +using namespace ScioSense; + +ENS213A ens213a; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens213a.begin(); + + if (ens213a.isConnected() == false) + { + Serial.println("Error -- The ENS213a is not connected."); + while(1); + } + + ens213a.reset(); + + Serial.print("Starting continous mode.."); + while (ens213a.startContinuousMeasure() != ENS213A::Result::STATUS_OK) + { + Serial.print("."); + delay(ENS213A::SystemTiming::BOOTING); + } + Serial.println(" Done!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens213a.update() == ENS213A::Result::STATUS_OK) + { + float temperatureCelsius = ens213a.getTempCelsius(); + float humidityPercent = ens213a.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + ens213a.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/02_Continuous_Mode/ENS215/ENS215.ino b/examples/02_Continuous_Mode/ENS215/ENS215.ino new file mode 100644 index 0000000..2f6b11a --- /dev/null +++ b/examples/02_Continuous_Mode/ENS215/ENS215.ino @@ -0,0 +1,54 @@ +#include +#include + +#include "ens215.h" + +using namespace ScioSense; + +ENS215 ens215; + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + Wire.begin(); + ens215.begin(); + + if (ens215.isConnected() == false) + { + Serial.println("Error -- The ENS215 is not connected."); + while(1); + } + + ens215.reset(); + + Serial.print("Starting continous mode.."); + while (ens215.startContinuousMeasure() != ENS215::Result::STATUS_OK) + { + Serial.print("."); + delay(ENS215::SystemTiming::BOOTING); + } + Serial.println(" Done!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens215.update() == ENS215::Result::STATUS_OK) + { + float temperatureCelsius = ens215.getTempCelsius(); + float humidityPercent = ens215.getHumidityPercent(); + + Serial.print("Temperature:"); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity:"); + Serial.print(humidityPercent); + Serial.println("%"); + ens215.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/03_Debug_and_Troubleshoot/03_Debug_and_Troubleshoot.ino b/examples/03_Debug_and_Troubleshoot/ENS210/ENS210.ino similarity index 100% rename from examples/03_Debug_and_Troubleshoot/03_Debug_and_Troubleshoot.ino rename to examples/03_Debug_and_Troubleshoot/ENS210/ENS210.ino diff --git a/examples/03_Debug_and_Troubleshoot/ENS211/ENS211.ino b/examples/03_Debug_and_Troubleshoot/ENS211/ENS211.ino new file mode 100644 index 0000000..d951808 --- /dev/null +++ b/examples/03_Debug_and_Troubleshoot/ENS211/ENS211.ino @@ -0,0 +1,108 @@ +#include +#include + +#include "ens211.h" + +using namespace ScioSense; + +ENS211 ens211; +ENS211::Result result; + +void validateData(ENS211::Result result) +{ + switch (result) + { + case ENS211::Result::STATUS_I2C_ERROR: Serial.println("i2c-error"); break; + case ENS211::Result::STATUS_CRC_ERROR: Serial.println("crc-error"); break; + case ENS211::Result::STATUS_INVALID: Serial.println("data-invalid"); break; + case ENS211::Result::STATUS_OK: Serial.println("ok"); break; + default: Serial.println("unknown-status"); break; + } +} + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + ens211.enableDebugging(Serial); + + Wire.begin(); + ens211.begin(); + + if (ens211.isConnected() == false) + { + Serial.println("Error -- The ENS211 is not connected."); + while(1); + } + + if (ens211.reset() != ENS211::Result::STATUS_OK) + { + Serial.println("Error -- Failed to reset the device."); + while(1); + } + + if (ens211.singleShotMeasure() != ENS211::Result::STATUS_OK) + { + Serial.println("Error -- Single shot measure failed."); + + Serial.print("Temperature status: "); + validateData(ens211.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens211.getStatusH()); + + while(1); + } + + if (ens211.startContinuousMeasure() != ENS211::Result::STATUS_OK) + { + Serial.println("Error -- Starting continuous mode failed."); + while(1); + } + + if (ens211.update() != ENS211::Result::STATUS_OK) + { + Serial.println("Error -- Updating measurement data failed."); + + Serial.print("Temperature status: "); + validateData(ens211.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens211.getStatusH()); + + while(1); + } + + if (ens211.stopContinuousMeasure() != ENS211::Result::STATUS_OK) + { + Serial.println("Error -- Stopping continuous mode failed."); + while(1); + } + + ens211.disableDebugging(); + + Serial.println(); + Serial.println("Done. All OK!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens211.singleShotMeasure() == ENS211::Result::STATUS_OK) + { + float temperatureCelsius = ens211.getTempCelsius(); + float humidityPercent = ens211.getHumidityPercent(); + + Serial.print("Temperature: "); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity: "); + Serial.print(humidityPercent); + Serial.println("%"); + ens211.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/03_Debug_and_Troubleshoot/ENS212/ENS212.ino b/examples/03_Debug_and_Troubleshoot/ENS212/ENS212.ino new file mode 100644 index 0000000..9848700 --- /dev/null +++ b/examples/03_Debug_and_Troubleshoot/ENS212/ENS212.ino @@ -0,0 +1,108 @@ +#include +#include + +#include "ens212.h" + +using namespace ScioSense; + +ENS212 ens212; +ENS212::Result result; + +void validateData(ENS212::Result result) +{ + switch (result) + { + case ENS212::Result::STATUS_I2C_ERROR: Serial.println("i2c-error"); break; + case ENS212::Result::STATUS_CRC_ERROR: Serial.println("crc-error"); break; + case ENS212::Result::STATUS_INVALID: Serial.println("data-invalid"); break; + case ENS212::Result::STATUS_OK: Serial.println("ok"); break; + default: Serial.println("unknown-status"); break; + } +} + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + ens212.enableDebugging(Serial); + + Wire.begin(); + ens212.begin(); + + if (ens212.isConnected() == false) + { + Serial.println("Error -- The ENS212 is not connected."); + while(1); + } + + if (ens212.reset() != ENS212::Result::STATUS_OK) + { + Serial.println("Error -- Failed to reset the device."); + while(1); + } + + if (ens212.singleShotMeasure() != ENS212::Result::STATUS_OK) + { + Serial.println("Error -- Single shot measure failed."); + + Serial.print("Temperature status: "); + validateData(ens212.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens212.getStatusH()); + + while(1); + } + + if (ens212.startContinuousMeasure() != ENS212::Result::STATUS_OK) + { + Serial.println("Error -- Starting continuous mode failed."); + while(1); + } + + if (ens212.update() != ENS212::Result::STATUS_OK) + { + Serial.println("Error -- Updating measurement data failed."); + + Serial.print("Temperature status: "); + validateData(ens212.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens212.getStatusH()); + + while(1); + } + + if (ens212.stopContinuousMeasure() != ENS212::Result::STATUS_OK) + { + Serial.println("Error -- Stopping continuous mode failed."); + while(1); + } + + ens212.disableDebugging(); + + Serial.println(); + Serial.println("Done. All OK!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens212.singleShotMeasure() == ENS212::Result::STATUS_OK) + { + float temperatureCelsius = ens212.getTempCelsius(); + float humidityPercent = ens212.getHumidityPercent(); + + Serial.print("Temperature: "); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity: "); + Serial.print(humidityPercent); + Serial.println("%"); + ens212.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/03_Debug_and_Troubleshoot/ENS213A/ENS213A.ino b/examples/03_Debug_and_Troubleshoot/ENS213A/ENS213A.ino new file mode 100644 index 0000000..bb168bd --- /dev/null +++ b/examples/03_Debug_and_Troubleshoot/ENS213A/ENS213A.ino @@ -0,0 +1,108 @@ +#include +#include + +#include "ens213a.h" + +using namespace ScioSense; + +ENS213A ens213a; +ENS213A::Result result; + +void validateData(ENS213A::Result result) +{ + switch (result) + { + case ENS213A::Result::STATUS_I2C_ERROR: Serial.println("i2c-error"); break; + case ENS213A::Result::STATUS_CRC_ERROR: Serial.println("crc-error"); break; + case ENS213A::Result::STATUS_INVALID: Serial.println("data-invalid"); break; + case ENS213A::Result::STATUS_OK: Serial.println("ok"); break; + default: Serial.println("unknown-status"); break; + } +} + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + ens213a.enableDebugging(Serial); + + Wire.begin(); + ens213a.begin(); + + if (ens213a.isConnected() == false) + { + Serial.println("Error -- The ENS213A is not connected."); + while(1); + } + + if (ens213a.reset() != ENS213A::Result::STATUS_OK) + { + Serial.println("Error -- Failed to reset the device."); + while(1); + } + + if (ens213a.singleShotMeasure() != ENS213A::Result::STATUS_OK) + { + Serial.println("Error -- Single shot measure failed."); + + Serial.print("Temperature status: "); + validateData(ens213a.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens213a.getStatusH()); + + while(1); + } + + if (ens213a.startContinuousMeasure() != ENS213A::Result::STATUS_OK) + { + Serial.println("Error -- Starting continuous mode failed."); + while(1); + } + + if (ens213a.update() != ENS213A::Result::STATUS_OK) + { + Serial.println("Error -- Updating measurement data failed."); + + Serial.print("Temperature status: "); + validateData(ens213a.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens213a.getStatusH()); + + while(1); + } + + if (ens213a.stopContinuousMeasure() != ENS213A::Result::STATUS_OK) + { + Serial.println("Error -- Stopping continuous mode failed."); + while(1); + } + + ens213a.disableDebugging(); + + Serial.println(); + Serial.println("Done. All OK!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens213a.singleShotMeasure() == ENS213A::Result::STATUS_OK) + { + float temperatureCelsius = ens213a.getTempCelsius(); + float humidityPercent = ens213a.getHumidityPercent(); + + Serial.print("Temperature: "); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity: "); + Serial.print(humidityPercent); + Serial.println("%"); + ens213a.getStatusH(); + } +} \ No newline at end of file diff --git a/examples/03_Debug_and_Troubleshoot/ENS215/ENS215.ino b/examples/03_Debug_and_Troubleshoot/ENS215/ENS215.ino new file mode 100644 index 0000000..a9159cb --- /dev/null +++ b/examples/03_Debug_and_Troubleshoot/ENS215/ENS215.ino @@ -0,0 +1,108 @@ +#include +#include + +#include "ens215.h" + +using namespace ScioSense; + +ENS215 ens215; +ENS215::Result result; + +void validateData(ENS215::Result result) +{ + switch (result) + { + case ENS215::Result::STATUS_I2C_ERROR: Serial.println("i2c-error"); break; + case ENS215::Result::STATUS_CRC_ERROR: Serial.println("crc-error"); break; + case ENS215::Result::STATUS_INVALID: Serial.println("data-invalid"); break; + case ENS215::Result::STATUS_OK: Serial.println("ok"); break; + default: Serial.println("unknown-status"); break; + } +} + +void setup() +{ + Serial.begin(9600); + Serial.println(); + + ens215.enableDebugging(Serial); + + Wire.begin(); + ens215.begin(); + + if (ens215.isConnected() == false) + { + Serial.println("Error -- The ENS215 is not connected."); + while(1); + } + + if (ens215.reset() != ENS215::Result::STATUS_OK) + { + Serial.println("Error -- Failed to reset the device."); + while(1); + } + + if (ens215.singleShotMeasure() != ENS215::Result::STATUS_OK) + { + Serial.println("Error -- Single shot measure failed."); + + Serial.print("Temperature status: "); + validateData(ens215.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens215.getStatusH()); + + while(1); + } + + if (ens215.startContinuousMeasure() != ENS215::Result::STATUS_OK) + { + Serial.println("Error -- Starting continuous mode failed."); + while(1); + } + + if (ens215.update() != ENS215::Result::STATUS_OK) + { + Serial.println("Error -- Updating measurement data failed."); + + Serial.print("Temperature status: "); + validateData(ens215.getStatusT()); + + Serial.print("Humidity status: "); + validateData(ens215.getStatusH()); + + while(1); + } + + if (ens215.stopContinuousMeasure() != ENS215::Result::STATUS_OK) + { + Serial.println("Error -- Stopping continuous mode failed."); + while(1); + } + + ens215.disableDebugging(); + + Serial.println(); + Serial.println("Done. All OK!"); + + Serial.println(); + Serial.println("----------------------------------------"); +} + +void loop() +{ + if (ens215.singleShotMeasure() == ENS215::Result::STATUS_OK) + { + float temperatureCelsius = ens215.getTempCelsius(); + float humidityPercent = ens215.getHumidityPercent(); + + Serial.print("Temperature: "); + Serial.print(temperatureCelsius); + Serial.print("°C\t"); + + Serial.print("Humidity: "); + Serial.print(humidityPercent); + Serial.println("%"); + ens215.getStatusH(); + } +} \ No newline at end of file diff --git a/images/ens21x.png b/images/ens21x.png new file mode 100644 index 0000000..5aca0bc Binary files /dev/null and b/images/ens21x.png differ diff --git a/images/i2c_pinout_esp32.png b/images/i2c_pinout_esp32.png new file mode 100644 index 0000000..60f3c34 Binary files /dev/null and b/images/i2c_pinout_esp32.png differ diff --git a/library.properties b/library.properties index 259db7a..52ec135 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=ScioSense_ENS21x -version=1.1.0 -author=Sciosense -maintainer=Sciosense +version=1.2.0 +author=ScioSense +maintainer=ScioSense sentence=Arduino library for ENS21x digital temperature & humidity sensors with I2C interface from ScioSense paragraph=This library controls ENS21x sensors. The main feature of this library is performing a single shot measurement, retrieving the measurement data. -category=Device Control -url=https://github.com/sciosense/ENS21x_driver/ +category=Sensors +url=https://github.com/sciosense/ens21x-arduino architectures=*