diff --git a/Capteur-autonome/.DS_Store b/Capteur-autonome/.DS_Store index 889d353531711bcd33a687409014e77e7a72e7c5..e065bccb38476c646209d1313b9e2d26ed2b6709 100644 Binary files a/Capteur-autonome/.DS_Store and b/Capteur-autonome/.DS_Store differ diff --git a/Capteur-autonome/Projects/.DS_Store b/Capteur-autonome/Projects/.DS_Store index c7f4ca017d160539e0651715fb7601326872b709..6fb63268dc7407d84f83f129f977a37df4d7df06 100644 Binary files a/Capteur-autonome/Projects/.DS_Store and b/Capteur-autonome/Projects/.DS_Store differ diff --git a/Capteur-autonome/Projects/.vscode/settings.json b/Capteur-autonome/Projects/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..a5a2d31465e7477c8553b704019c464f469261ad --- /dev/null +++ b/Capteur-autonome/Projects/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "print": "cpp" + } +} \ No newline at end of file diff --git a/Capteur-autonome/Projects/Archives/.DS_Store b/Capteur-autonome/Projects/Archives/.DS_Store index 23053c5754c63c8b1e7db8e0a79aa52f6bcdf6b7..c20f8517a495c5bc80e087a675e20bbab23cc437 100644 Binary files a/Capteur-autonome/Projects/Archives/.DS_Store and b/Capteur-autonome/Projects/Archives/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/.DS_Store index ce9df434bb57decaf26f87bbc13da6215c004373..207b755efe3dbbbfadc1ae9796398003a819c4bd 100644 Binary files a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/.DS_Store and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST/.DS_Store index f3709fc1c46d6dd36382a677de75d5af542acee9..d4a51670f1e51ed9159df2eed4e528110afae6b6 100644 Binary files a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST/.DS_Store and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..70b36caa535b58ff9559f29f9202e353a77c0683 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.gitignore b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.gitignore similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.gitignore rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.gitignore diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.vscode/extensions.json b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.vscode/extensions.json similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.vscode/extensions.json rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/.vscode/extensions.json diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/include/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/include/README similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/include/README rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/include/README diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/lib/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/lib/README similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/lib/README rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/lib/README diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/platformio.ini b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/platformio.ini new file mode 100644 index 0000000000000000000000000000000000000000..c1b8e155ef0c2b1675c0cbdc3d643c186c58e2e6 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/platformio.ini @@ -0,0 +1,19 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:nodemcuv2] +platform = espressif8266 +board = nodemcuv2 +framework = arduino +upload_speed = 115200 +monitor_speed = 115200 + +lib_deps = + lewapek/Nova Fitness Sds dust sensors library@^1.5.1 diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/src/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/src/.DS_Store similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/src/.DS_Store rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/src/.DS_Store diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/src/main.cpp b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01f5e03bf7a0f868635881c5c8748684b313716e --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/src/main.cpp @@ -0,0 +1,42 @@ +#include <Arduino.h> +#include <SoftwareSerial.h> +#include "SdsDustSensor.h" + +// Définition des broches pour le SDS011 (sur ESP8266) +#define RX_PIN 14 // GPIO14 = D5 (RX de l'ESP, donc relié au TX du SDS011) +#define TX_PIN 12 // GPIO12 = D6 (TX de l'ESP, donc relié au RX du SDS011) + +// Création du port série logiciel pour le capteur SDS011 +SoftwareSerial SDS_Serial(RX_PIN, TX_PIN); // RX, TX + +// Objet SDS011 +SdsDustSensor sds(SDS_Serial); + +void setup() { + Serial.begin(115200); // Moniteur série USB + + SDS_Serial.begin(9600); + sds.begin(); + + Serial.println("SDS011 Initialisé !"); + Serial.println(sds.queryFirmwareVersion().toString()); + Serial.println(sds.setActiveReportingMode().toString()); + Serial.println(sds.setContinuousWorkingPeriod().toString()); +} + +void loop() { + PmResult pm = sds.readPm(); + if (pm.isOk()) { + Serial.print("PM2.5 = "); + Serial.print(pm.pm25); + Serial.print(" µg/m³, PM10 = "); + Serial.print(pm.pm10); + Serial.println(" µg/m³"); + Serial.println(pm.toString()); + } else { + Serial.print("Erreur de lecture SDS011 : "); + Serial.println(pm.statusToString()); + } + + delay(1000); +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/test/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/test/README similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/test/README rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ESP8266/test/README diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.DS_Store similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/.DS_Store rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.DS_Store diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.gitignore b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..89cc49cbd652508924b868ea609fa8f6b758ec56 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.vscode/extensions.json b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.vscode/extensions.json new file mode 100644 index 0000000000000000000000000000000000000000..080e70d08b9811fa743afe5094658dba0ed6b7c2 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/include/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/include/README new file mode 100644 index 0000000000000000000000000000000000000000..49819c0d54960b5848277cc68ab2d08169cecaf3 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/lib/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/lib/README new file mode 100644 index 0000000000000000000000000000000000000000..93793971ffcaedf70668ba0d17d84315c350f9f7 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include <Foo.h> +#include <Bar.h> + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/platformio.ini b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/platformio.ini similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/platformio.ini rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/platformio.ini diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/src/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/src/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/src/main.cpp b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/src/main.cpp similarity index 100% rename from Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST copie/src/main.cpp rename to Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/src/main.cpp diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/test/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/test/README new file mode 100644 index 0000000000000000000000000000000000000000..9b1e87bc67c90e7f09a92a3e855444b085c655a6 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/SDS011_TEST_ModeVEILLE/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30 copie/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30 copie/.DS_Store index 066bc068c6f266d9f9370455998a70373aab3536..9af56d81851e0e59150082e0160f2a56b8f4f248 100644 Binary files a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30 copie/.DS_Store and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30 copie/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..066bc068c6f266d9f9370455998a70373aab3536 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.gitignore b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..89cc49cbd652508924b868ea609fa8f6b758ec56 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.vscode/extensions.json b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.vscode/extensions.json new file mode 100644 index 0000000000000000000000000000000000000000..080e70d08b9811fa743afe5094658dba0ed6b7c2 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/include/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/include/README new file mode 100644 index 0000000000000000000000000000000000000000..49819c0d54960b5848277cc68ab2d08169cecaf3 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/.DS_Store b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6c3113982cbb71a3ebdbdbf453584360a1b7d5e8 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/.DS_Store differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.cpp b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8399bd1e4100c1c0c30996bd1c4780b733098309 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.cpp @@ -0,0 +1,604 @@ +/*! + * @file DFRobot_SHT3x.cpp + * @brief Define the infrastructure and the implementation of the underlying method of the DFRobot_SHT3x class, + * + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @License The MIT License (MIT) + * @author [fengli](li.feng@dfrobot.com) + * @version V1.0 + * @date 2019-08-20 + * @url https://github.com/DFRobot/DFRobot_SHT3x + */ + +#include <DFRobot_SHT3x.h> +#include"math.h" +DFRobot_SHT3x::DFRobot_SHT3x(TwoWire *pWire, uint8_t address,uint8_t RST) +{ + _pWire = pWire; + _address = address; + _RST = RST; + measurementMode = eOneShot; + pinMode(_RST,OUTPUT); + digitalWrite(_RST,HIGH); +} + +int DFRobot_SHT3x::begin() +{ + _pWire->begin(); + if(readSerialNumber() == 0){ + DBG("bus data access error"); + return ERR_DATA_BUS; + } + return ERR_OK; +} +uint32_t DFRobot_SHT3x::readSerialNumber() +{ + uint32_t result = 0 ; + uint8_t serialNumber1[3]; + uint8_t serialNumber2[3]; + uint8_t rawData[6]; + writeCommand(SHT3X_CMD_READ_SERIAL_NUMBER,2); + delay(1); + readData(rawData,6); + memcpy(serialNumber1,rawData,3); + memcpy(serialNumber2,rawData+3,3); + if((checkCrc(serialNumber1) == serialNumber1[2]) && (checkCrc(serialNumber2) == serialNumber2[2])){ + result = serialNumber1[0]; + result = (result << 8) | serialNumber1[1]; + result = (result << 8) | serialNumber2[0]; + result = (result << 8) | serialNumber2[1]; + } + return result; +} + +bool DFRobot_SHT3x::softReset() +{ + sStatusRegister_t registerRaw; + writeCommand(SHT3X_CMD_SOFT_RESET,2); + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.commandStatus == 0) + return true; + else + return false; +} + +bool DFRobot_SHT3x::pinReset() +{ + sStatusRegister_t registerRaw; + clearStatusRegister(); + digitalWrite(_RST,LOW); + delay(1); + digitalWrite(_RST,HIGH); + //After hardware reset, it takes some time to enter the idle state + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.systemResetDeteced == 1) + return true; + else + return false; +} + +bool DFRobot_SHT3x::stopPeriodicMode() +{ + sStatusRegister_t registerRaw; + measurementMode = eOneShot; + writeCommand(SHT3X_CMD_STOP_PERIODIC_ACQUISITION_MODE,2); + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.commandStatus == 0) + return true; + else + return false; +} + +bool DFRobot_SHT3x::heaterEnable() +{ + sStatusRegister_t registerRaw; + writeCommand(SHT3X_CMD_HEATER_ENABLE,2); + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.heaterStaus == 1) + return true; + else + return false; +} + +bool DFRobot_SHT3x::heaterDisable() +{ + sStatusRegister_t registerRaw; + writeCommand( SHT3X_CMD_HEATER_DISABLE,2); + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.heaterStaus == 0) + return true; + else + return false; +} + +void DFRobot_SHT3x::clearStatusRegister(){ + writeCommand(SHT3X_CMD_CLEAR_STATUS_REG,2); + delay(10); +} + +bool DFRobot_SHT3x::readAlertState() +{ + sStatusRegister_t registerRaw; + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.humidityAlert == 1 || registerRaw.temperatureAlert == 1){ + return true; + } else { + return false; + } +} +DFRobot_SHT3x::sRHAndTemp_t DFRobot_SHT3x::readTemperatureAndHumidity(eRepeatability_t repeatability) +{ + uint8_t rawData[6]; + uint8_t rawTemperature[3]; + uint8_t rawHumidity[3]; + tempRH.ERR = 0; + switch(repeatability){ + case eRepeatability_High:writeCommand(SHT3X_CMD_GETDATA_POLLING_H,2);break; + case eRepeatability_Medium:writeCommand(SHT3X_CMD_GETDATA_POLLING_M,2);break; + case eRepeatability_Low:writeCommand(SHT3X_CMD_GETDATA_POLLING_L,2);break; + } + delay(15); + readData(rawData,6); + memcpy(rawTemperature,rawData,3); + memcpy(rawHumidity,rawData+3,3); + if((checkCrc(rawTemperature) != rawTemperature[2]) || (checkCrc(rawHumidity) != rawHumidity[2])){ + tempRH.ERR = -1; + return tempRH; + } + tempRH.TemperatureC = convertTemperature(rawTemperature); + tempRH.TemperatureF = 1.8*tempRH.TemperatureC+32; + tempRH.Humidity = convertHumidity(rawHumidity); + return tempRH; +} + +float DFRobot_SHT3x::getTemperatureC(){ + if(measurementMode == eOneShot){ + readTemperatureAndHumidity(eRepeatability_High); + } else { + readTemperatureAndHumidity(); + } + return tempRH.TemperatureC; +} + +float DFRobot_SHT3x::getTemperatureF() +{ + if(measurementMode == eOneShot){ + readTemperatureAndHumidity(eRepeatability_High); + } else { + readTemperatureAndHumidity(); + } + return tempRH.TemperatureF; +} + +float DFRobot_SHT3x::getHumidityRH() +{ + if(measurementMode == eOneShot){ + readTemperatureAndHumidity(eRepeatability_High); + } else { + readTemperatureAndHumidity(); + } + return tempRH.Humidity; +} +bool DFRobot_SHT3x::startPeriodicMode(eMeasureFrequency_t measureFreq,eRepeatability_t repeatability) +{ + const uint16_t cmd[5][3] ={{SHT3X_CMD_SETMODE_H_FREQUENCY_HALF_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_HALF_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_HALF_HZ}\ + ,{SHT3X_CMD_SETMODE_H_FREQUENCY_1_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_1_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_1_HZ}\ + ,{SHT3X_CMD_SETMODE_H_FREQUENCY_2_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_2_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_2_HZ}\ + ,{SHT3X_CMD_SETMODE_H_FREQUENCY_4_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_4_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_4_HZ}\ + ,{SHT3X_CMD_SETMODE_H_FREQUENCY_10_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_10_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_10_HZ}} ; + sStatusRegister_t registerRaw; + measurementMode = ePeriodic; + writeCommand(cmd[measureFreq][repeatability],2); + delay(1); + registerRaw = readStatusRegister(); + if(registerRaw.commandStatus == 0) + return true; + else + return false; +} + +DFRobot_SHT3x::sStatusRegister_t DFRobot_SHT3x::readStatusRegister(){ + uint8_t register1[3]; + uint16_t data; + sStatusRegister_t registerRaw; + uint8_t retry = 10; + while(retry--){ + writeCommand(SHT3X_CMD_READ_STATUS_REG,2); + delay(1); + readData(register1,3); + if(checkCrc(register1) == register1[2]){ + break; + } + } + data = (register1[0]<<8) | register1[1]; + memcpy(®isterRaw,&data,2); + return registerRaw; +} +uint8_t DFRobot_SHT3x::environmentState() +{ + sStatusRegister_t registerRaw; + float rhHighSet ; + float rhLowSet ; + delay(1); + registerRaw = readStatusRegister(); + sRHAndTemp_t data = readTemperatureAndHumidity(); + if(measureTemperatureLimitC()){ + tempHighSet = getTemperatureHighSetC(); + tempLowSet = getTemperatureLowSetC(); + } + if(measureHumidityLimitRH()){ + rhHighSet = getHumidityHighSetRH(); + rhLowSet = getHumidityLowSetRH(); + } + if(registerRaw.humidityAlert == 1 && registerRaw.temperatureAlert ==0){ + if(data.Humidity > rhHighSet) + return 2; + else if(data.Humidity < rhLowSet) + return 1; + } + else if(registerRaw.humidityAlert == 0 && registerRaw.temperatureAlert ==1){ + if(data.TemperatureC > tempHighSet) + return 20; + else if(data.TemperatureC < tempLowSet) + return 10; + } + else if(registerRaw.humidityAlert == 1 && registerRaw.temperatureAlert ==1){ + if(data.TemperatureC < tempLowSet && data.Humidity < rhLowSet) + return 11; + else if(data.TemperatureC > tempHighSet && data.Humidity > rhHighSet) + return 22; + else if(data.TemperatureC > tempHighSet && data.Humidity < rhLowSet) + return 21; + else if(data.TemperatureC < tempLowSet && data.Humidity > rhHighSet) + return 12; + } + + return 0 ; + +} +DFRobot_SHT3x::sRHAndTemp_t DFRobot_SHT3x::readTemperatureAndHumidity() +{ + uint8_t rawData[6]; + uint8_t rawTemperature[3]; + uint8_t rawHumidity[3]; + tempRH.ERR = 0; + writeCommand(SHT3X_CMD_GETDATA,2); + readData(rawData,6); + memcpy(rawTemperature,rawData,3); + memcpy(rawHumidity,rawData+3,3); + if((checkCrc(rawTemperature) != rawTemperature[2]) || (checkCrc(rawHumidity) != rawHumidity[2])){ + tempRH.ERR = -1; + return tempRH; + } + tempRH.TemperatureC = convertTemperature(rawTemperature); + tempRH.Humidity = convertHumidity(rawHumidity); + tempRH.TemperatureF = 1.8*tempRH.TemperatureC+32; + return tempRH; +} + +uint8_t DFRobot_SHT3x::setTemperatureLimitC(float highset,float highclear, float lowset,float lowclear) +{ + uint16_t _highset ,_highclear,_lowclear,_lowset,limit[1]; + + if(highset > highclear && highclear > lowclear && lowclear> lowset){ + _highset = convertRawTemperature(highset); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET,limit) != 0) { + return 1; + } + _highset = (_highset >> 7) |(limit[0] & 0xfe00); + writeLimitData(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET,_highset); + _highclear = convertRawTemperature(highclear); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR,limit) != 0){ + return 1; + } + _highclear = (_highclear >> 7) |(limit[0] & 0xfe00); + writeLimitData(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR,_highclear); + _lowclear = convertRawTemperature(lowclear); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR,limit) != 0){ + return 1; + } + _lowclear = (_lowclear >> 7) |(limit[0] & 0xfe00); + writeLimitData(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR,_lowclear); + _lowset = convertRawTemperature(lowset); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET,limit) != 0){ + return 1; + } + _lowset = (_lowset >> 7) |(limit[0] & 0xfe00); + writeLimitData(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET,_lowset); + } else { + return 1; + } + + return 0; +} +uint8_t DFRobot_SHT3x::setTemperatureLimitF(float highset,float highclear,float lowset,float lowclear) +{ + float _highset ,_highclear,_lowclear,_lowset; + _highset = (highset - 32.0) * 5.0 / 9.0; + _highclear = (highclear - 32.0) * 5.0 / 9.0; + _lowclear = (lowclear - 32.0) * 5.0 / 9.0; + _lowset = (lowset - 32.0) * 5.0 / 9.0; + if(setTemperatureLimitC(_highset,_highclear,_lowset,_lowclear) == 0){ + return 0; + } + return 1; +} +uint8_t DFRobot_SHT3x::setHumidityLimitRH(float highset,float highclear, float lowset,float lowclear) +{ + uint16_t _highset ,_highclear,_lowclear,_lowset,limit[1]; + if(highset > highclear && highclear > lowclear && lowclear> lowset){ + _highset = convertRawHumidity(highset); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET,limit) != 0) { + return 1; + } + _highset = (_highset & 0xFE00) |(limit[0] & 0x1FF); + writeLimitData(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET,_highset); + + _highclear = convertRawHumidity(highclear); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR,limit) != 0){ + return 1; + } + _highclear = (_highclear & 0xFE00) |(limit[0] & 0x1FF); + writeLimitData(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR,_highclear); + _lowclear = convertRawHumidity(lowclear); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR,limit) != 0){ + return 1; + } + _lowclear = (_lowclear & 0xFE00) |(limit[0] & 0x1FF); + writeLimitData(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR,_lowclear); + _lowset = convertRawHumidity(lowset); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET,limit) != 0){ + return 1; + } + _lowset = (_lowset & 0xFE00) |(limit[0] & 0x1FF); + writeLimitData(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET,_lowset); + } else { + return 1; + } + return 0; +} + +bool DFRobot_SHT3x::measureTemperatureLimitC(){ + + uint16_t limit[1] ; + float data; + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET,limit) != 0) { + return false; + } + data = convertTempLimitData(limit); + limitData.highSet = round(data); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.highClear = round(data); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.lowClear = round(data); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.lowSet = round(data); + return true; +} + +bool DFRobot_SHT3x::measureTemperatureLimitF() +{ + uint16_t limit[1] ; + float data; + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET,limit) != 0) { + return false; + } + data = convertTempLimitData(limit); + limitData.highSet = round(data * 9.0 / 5.0 + 32.0); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.highClear = round(data * 9.0 / 5.0 + 32.0); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.lowClear = round(data * 9.0 / 5.0 + 32.0); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET,limit) != 0){ + return false; + } + data = convertTempLimitData(limit); + limitData.lowSet = round(data * 9.0 / 5.0 + 32.0); + return true; + +} +float DFRobot_SHT3x::getTemperatureHighSetF(){ + return limitData.highSet; +} + +float DFRobot_SHT3x::getTemperatureHighClearF(){ + return limitData.highClear; +} + +float DFRobot_SHT3x::getTemperatureLowClearF(){ + return limitData.lowClear; +} +float DFRobot_SHT3x::getTemperatureLowSetF(){ + return limitData.lowSet; +} +uint8_t DFRobot_SHT3x::readLimitData(uint16_t cmd,uint16_t *pBuf) +{ + uint8_t rawData[3]; + uint8_t crc; + + writeCommand(cmd,2); + readData(rawData,3); + crc = rawData[2]; + if(checkCrc(rawData) != crc){ + return 1 ; + } + pBuf[1] = rawData[0]; + pBuf[1] = (pBuf[1] << 8) | rawData[1]; + return 0; +} +float DFRobot_SHT3x::getTemperatureHighSetC(){ + return limitData.highSet; +} +float DFRobot_SHT3x::getTemperatureHighClearC(){ + return limitData.highClear; +} +float DFRobot_SHT3x::getTemperatureLowClearC(){ + return limitData.lowClear; +} +float DFRobot_SHT3x::getTemperatureLowSetC(){ + return limitData.lowSet; +} +float DFRobot_SHT3x::getHumidityHighSetRH(){ + return limitData.highSet; +} +float DFRobot_SHT3x::getHumidityHighClearRH(){ + return limitData.highClear; +} +float DFRobot_SHT3x::getHumidityLowClearRH(){ + return limitData.lowClear; +} +float DFRobot_SHT3x::getHumidityLowSetRH(){ + return limitData.lowSet; +} + +bool DFRobot_SHT3x::measureHumidityLimitRH() +{ + + uint16_t limit[1]; + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET,limit) != 0) { + return false; + } + limitData.highSet = convertHumidityLimitData(limit); + if(readLimitData(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + limitData.highClear = convertHumidityLimitData(limit); + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR,limit) != 0){ + return false; + } + limitData.lowClear = convertHumidityLimitData(limit); + + if(readLimitData(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET,limit) != 0){ + return false; + } + limitData.lowSet = convertHumidityLimitData(limit); + return true; +} +float DFRobot_SHT3x::convertTemperature(uint8_t rawTemperature[]) +{ + uint16_t rawValue ; + rawValue = rawTemperature[0]; + rawValue = (rawValue << 8) | rawTemperature[1]; + return 175.0f * (float)rawValue / 65535.0f - 45.0f; +} +float DFRobot_SHT3x::convertHumidity(uint8_t rawHumidity[]) +{ + uint16_t rawValue ; + rawValue = rawHumidity[0]; + rawValue = (rawValue << 8) | rawHumidity[1]; + return 100.0f * (float)rawValue / 65535.0f; +} + +uint16_t DFRobot_SHT3x::convertRawTemperature(float value) +{ + return (value + 45.0f) / 175.0f * 65535.0f; +} + +uint16_t DFRobot_SHT3x::convertRawHumidity(float value) +{ + return value / 100.0f * 65535.0f; +} + +float DFRobot_SHT3x::convertTempLimitData(uint16_t limit[]) +{ + limit[1] = limit[1] << 7; + limit[1] = limit[1] & 0xFF80; + limit[1] = limit[1] | 0x1A; + return 175.0f * (float)limit[1] / 65535.0f - 45.0f; +} + +float DFRobot_SHT3x::convertHumidityLimitData(uint16_t limit[]) +{ + limit[1] = limit[1] & 0xFE00; + limit[1] = limit[1] | 0xCD; + return round(100.0f * (float)limit[1] / 65535.0f) ; +} + +uint8_t DFRobot_SHT3x::checkCrc(uint8_t data[]) +{ + uint8_t bit; + uint8_t crc = 0xFF; + + for (uint8_t dataCounter = 0; dataCounter < 2; dataCounter++) + { + crc ^= (data[dataCounter]); + for (bit = 8; bit > 0; --bit) + { + if (crc & 0x80) + crc = (crc << 1) ^ 0x131; + else + crc = (crc << 1); + } + } + return crc; +} + +void DFRobot_SHT3x::writeLimitData(uint16_t cmd,uint16_t limitData){ + uint8_t _pBuf[5]; + _pBuf[0] = cmd >>8; + _pBuf[1] = cmd & 0xff; + _pBuf[2] = limitData >> 8; + _pBuf[3] = limitData & 0xff; + uint8_t crc = checkCrc(_pBuf+2); + _pBuf[4] = crc; + write(_pBuf,5); +} + +void DFRobot_SHT3x::writeCommand(uint16_t cmd,size_t size) +{ + uint8_t _pBuf[2]; + _pBuf[0] = cmd >> 8; + _pBuf[1] = cmd & 0xFF; + delay(1); + write(_pBuf,2); +} + +void DFRobot_SHT3x::write(const void* pBuf,size_t size) +{ + if (pBuf == NULL) { + DBG("pBuf ERROR!! : null pointer"); + } + uint8_t * _pBuf = (uint8_t *)pBuf; + _pWire->beginTransmission(_address); + for (uint8_t i = 0; i < size; i++) { + _pWire->write(_pBuf[i]); + } + _pWire->endTransmission(); +} + +uint8_t DFRobot_SHT3x::readData(void *pBuf, size_t size) { + if (pBuf == NULL) { + DBG("pBuf ERROR!! : null pointer"); + } + uint8_t * _pBuf = (uint8_t *)pBuf; + + _pWire->requestFrom(_address,size); + uint8_t len = 0; + for (uint8_t i = 0 ; i < size; i++) { + _pBuf[i] = _pWire->read(); + len++; + } + + return len; +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.h b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.h new file mode 100644 index 0000000000000000000000000000000000000000..365ab0b38597075652c3cb211df854ad48cb928d --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/DFRobot_SHT3x.h @@ -0,0 +1,566 @@ +/*! + * @file DFRobot_SHT3x.h + * @brief Define the infrastructure of the DFRobot_SHT3x class + * @details This is a library of digital temperature and humidity sensors used to drive the SHT3x series SHT30, + * @n SHT31 and SHT35 to read ambient temperature and relative humidity. + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @License The MIT License (MIT) + * @author [fengli](li.feng@dfrobot.com) + * @version V1.0 + * @date 2019-08-19 + * @url https://github.com/DFRobot/DFRobot_SHT3x + */ + +#ifndef DFROBOT_SHT3X_H +#define DFROBOT_SHT3X_H +#include "Arduino.h" +#include <Wire.h> + +//#define ENABLE_DBG +#ifdef ENABLE_DBG +#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);} +#else +#define DBG(...) +#endif + +#define SHT3X_CMD_GETDATA_POLLING_H (0x2400) // measurement: polling, high repeatability +#define SHT3X_CMD_GETDATA_POLLING_M (0x240B) // measurement: polling, medium repeatability +#define SHT3X_CMD_GETDATA_POLLING_L (0x2416) // measurement: polling, low repeatability + +#define SHT3X_CMD_READ_SERIAL_NUMBER (0x3780)///< Read the chip serial number +#define SHT3X_CMD_GETDATA_H_CLOCKENBLED (0x2C06)///< Measurement:high repeatability +#define SHT3X_CMD_GETDATA_M_CLOCKENBLED (0x2C0D)///< Measurement: medium repeatability +#define SHT3X_CMD_GETDATA_L_CLOCKENBLED (0x2C10)///< Measurement: low repeatability +#define SHT3X_CMD_SETMODE_H_FREQUENCY_HALF_HZ (0x2032)///< Measurement: periodic 0.5 mps, high repeatability +#define SHT3X_CMD_SETMODE_M_FREQUENCY_HALF_HZ (0x2024)///< Measurement: periodic 0.5 mps, medium +#define SHT3X_CMD_SETMODE_L_FREQUENCY_HALF_HZ (0x202F)///< Measurement: periodic 0.5 mps, low repeatability +#define SHT3X_CMD_SETMODE_H_FREQUENCY_1_HZ (0x2130)///< Measurement: periodic 1 mps, high repeatability +#define SHT3X_CMD_SETMODE_M_FREQUENCY_1_HZ (0x2126)///< Measurement: periodic 1 mps, medium repeatability +#define SHT3X_CMD_SETMODE_L_FREQUENCY_1_HZ (0x212D)///< Measurement: periodic 1 mps, low repeatability +#define SHT3X_CMD_SETMODE_H_FREQUENCY_2_HZ (0x2236)///< Measurement: periodic 2 mps, high repeatability +#define SHT3X_CMD_SETMODE_M_FREQUENCY_2_HZ (0x2220)///< Measurement: periodic 2 mps, medium repeatability +#define SHT3X_CMD_SETMODE_L_FREQUENCY_2_HZ (0x222B)///< Measurement: periodic 2 mps, low repeatability +#define SHT3X_CMD_SETMODE_H_FREQUENCY_4_HZ (0x2334)///< Measurement: periodic 4 mps, high repeatability +#define SHT3X_CMD_SETMODE_M_FREQUENCY_4_HZ (0x2322)///< Measurement: periodic 4 mps, medium repeatability +#define SHT3X_CMD_SETMODE_L_FREQUENCY_4_HZ (0x2329)///< Measurement: periodic 4 mps, low repeatability +#define SHT3X_CMD_SETMODE_H_FREQUENCY_10_HZ (0x2737)///< Measurement: periodic 10 mps, high repeatability +#define SHT3X_CMD_SETMODE_M_FREQUENCY_10_HZ (0x2721)///< Measurement: periodic 10 mps, medium +#define SHT3X_CMD_SETMODE_L_FREQUENCY_10_HZ (0x272A)///< Measurement: periodic 10 mps, low repeatability +#define SHT3X_CMD_GETDATA (0xE000)///< Readout measurements for periodic mode + +#define SHT3X_CMD_STOP_PERIODIC_ACQUISITION_MODE (0x3093)///< +#define SHT3X_CMD_SOFT_RESET (0x30A2)///< Soft reset +#define SHT3X_CMD_HEATER_ENABLE (0x306D)///< Enabled heater +#define SHT3X_CMD_HEATER_DISABLE (0x3066)///< Disable heater +#define SHT3X_CMD_READ_STATUS_REG (0xF32D)///< Read status register +#define SHT3X_CMD_CLEAR_STATUS_REG (0x3041)///< Clear status register + +#define SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET (0xE11F)///< Read alert limits, high set +#define SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR (0xE114)///< Read alert limits, high clear +#define SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR (0xE109)///< Read alert limits, low clear +#define SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET (0xE102)///< Read alert limits, low set +#define SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET (0x611D)///< Write alert limits, high set +#define SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR (0x6116)///< Write alert limits, high clear +#define SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR (0x610B)///< Write alert limits, low clear +#define SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET (0x6100)///< Write alert limits, low set +class DFRobot_SHT3x +{ +public: + #define ERR_OK 0 //No error + #define ERR_DATA_BUS -1 //Data bus error + #define ERR_IC_VERSION -2 //Chip version does not match + + /** + * @struct sStatusRegister_t + * @brief The status register contains information on the operational status of the heater, the alert mode and on the execution status of + * @n the last command and the last write sequence. + + * @n ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + b15 | b14 | b13 | b12 | b11 | b10 | b5~b9 | b4 | b2~b3 | b1 | b0 | + * @n ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * @n alertPendingStatus| reserved3 | heaterStaus|reserved2 |humidityAlert | temperatureAlert | reserved1 | systemResetDeteced |reserved0 |commendStatus|writeDataChecksumStatus| + * @n ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * @n writeDataChecksumStatus: '0' : checksum of last write transfer was correct + * @n '1' : checksum of last write transfer failed + * @n commendStatus '0' : last command executed successfully + * @n '1' : last command not processed. + * @n systemResetDeteced '0' : no reset detected since last ‘clear status register’ command + * @n '1' : reset detected (hard reset, soft reset command or supply fail) + * @n temperatureAlert '0' : no alert + * @n '1' : alert + * @n humidityAlert '0' : no alert + * @n '1' : alert + * @n heaterStaus '0' : heater OFF + * @n '1' : heater ON + * @n alertPendingStatus '0' : no pending alerts + * @n '1' : at least one pending alert + */ + typedef struct { + uint16_t writeDataChecksumStatus : 1; + uint16_t commandStatus : 1; + uint16_t reserved0 : 2; + uint16_t systemResetDeteced : 1; + uint16_t reserved1 : 5; + uint16_t temperatureAlert : 1; + uint16_t humidityAlert : 1; + uint16_t reserved2 : 1; + uint16_t heaterStaus :1; + uint16_t reserved3 :1; + uint16_t alertPendingStatus :1; + }__attribute__ ((packed)) sStatusRegister_t; + + /** + * @struct eMode_t + * @brief Two measurement modes for the chip + */ + typedef enum { + ePeriodic,/**<Cycle measurement mode*/ + eOneShot,/**<Single measurement mode*/ + } eMode_t; + + /** + * @struct eRepeatability_t + * @brief We can choose the repeatability of the chip to measure temperature and humidity data + * @details (which means the difference between the data measured by the chip under two identical measurementconditions). + * @note There are 3 repeatabilities to choose: low, medium and high. The higher repeatability, the more accurate data. + */ + typedef enum{ + eRepeatability_High = 0,/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + eRepeatability_Medium = 1,/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + eRepeatability_Low = 2,/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + } eRepeatability_t; + + /** + * @struct eMeasureFrequency_t + * @brief Under the periodic data acquisition mode, we can select the frequency at which the chip measures temperature and humidity data. + * @n Optional frequencies are 0.5Hz, 1Hz, 2Hz, 4Hz, 10Hz. + */ + typedef enum{ + eMeasureFreq_Hz5 = 0, + eMeasureFreq_1Hz = 1, + eMeasureFreq_2Hz = 2, + eMeasureFreq_4Hz = 3, + eMeasureFreq_10Hz = 4, + } eMeasureFrequency_t; + + /** + * @struct sRHAndTemp_t + * @brief Structures used to store temperature and relative humidity + */ + typedef struct{ + float TemperatureC; + float Humidity; + float TemperatureF; + int ERR; + }sRHAndTemp_t; + + /** + * @struct sMode_t + * @brief Structures used to store the limits of temperature and relative humidity read + */ + typedef struct{ + float highSet;/**<Define the temperature (C)/humidity (%RH) range upper threshold, ALERT generates a high-level alarm once the data greater than the value defined*/ + float highClear;/**<Clear the alarm once the temperature (C)/humidity (%RH) less than the value defined>*/ + float lowSet;/**<Define the temperature (C)/humidity (%RH) range low threshold,ALERT generates a high-level alarm once the data lower than the value defined>*/ + float lowClear;/**<Clear the alarm once the temperature (C)/humidity (%RH) more than the value defined>*/ + } sLimitData_t; + +public: + + /** + * @fn DFRobot_Sensor + * @brief Construct the function + * @param pWire IC bus pointer object and construction device, can both pass or not pass parameters, Wire in default. + * @param address Chip IIC address, two optional addresses 0x44 and 0x45(0x45 in default). + * @param RST Chip reset pin, 4 in default. + * @n The IIC address is determined by the pin addr on the chip. + * @n When the ADR is connected to VDD, the chip IIC address is 0x45. + * @n When the ADR is connected to GND, the chip IIC address is 0x44. + */ + DFRobot_SHT3x(TwoWire *pWire = &Wire, uint8_t address = 0x45,uint8_t RST = 4); + + /** + * @fn readSerialNumber + * @brief Read the serial number of the chip + * @return 32-digit serial number + */ + uint32_t readSerialNumber(); + + /** + * @fn begin + * @brief Initialize the function + * @return Return 0 indicates a successful initialization, while other values indicates failure and return to error code. + */ + int begin(); + + /** + * @fn softReset + * @brief Send command resets via iiC, enter the chip's default mode single-measure mode, + * turn off the heater, and clear the alert of the ALERT pin. + * @return Read the status register to determine whether the command was executed successfully, and returning true indicates success + */ + bool softReset(); + + /** + * @fn pinReset + * @brief Reset through the chip's reset pin, enter the chip's default mode single-measure mode, and clear the alert of the ALERT pin. + * @return The status register has a data bit that detects whether the chip has been reset, and returning true indicates success + */ + bool pinReset(); + + /** + * @fn readTemperatureAndHumidity + * @brief Get temperature and humidity data in single measurement mode. + * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t. + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + * @n A status of 0 indicates the right return data. + */ + sRHAndTemp_t readTemperatureAndHumidity(eRepeatability_t repeatability ); + + /** + * @fn getTemperatureC + * @brief Get the measured temperature (in degrees Celsius) + * @return Return the float temperature data + */ + float getTemperatureC(); + + /** + * @fn getTemperatureF + * @brief Get the measured temperature (in degrees Fahrenheit) + * @return Return the float temperature data + */ + float getTemperatureF(); + + /** + * @fn getHumidityRH + * @brief Get measured humidity(%RH) + * @return Return the float humidity data + */ + float getHumidityRH(); + + /** + * @fn startPeriodicMode + * @brief Enter cycle measurement mode and set repeatability(the difference between the data measured + * the difference between the data measured by the chip under the same measurement conditions) + * @param measureFreq Read the eMeasureFrequency_t data frequency + * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t. + * eRepeatability_High(high repeatability mode) in default. + * @return Return true indicates a successful entrance to cycle measurement mode. + */ + bool startPeriodicMode(eMeasureFrequency_t measureFreq,eRepeatability_t repeatability = eRepeatability_High); + + /** + * @fn readTemperatureAndHumidity + * @brief Get temperature and humidity data in cycle measurement mode. + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + * @n A status of 0 indicates the right return data. + */ + sRHAndTemp_t readTemperatureAndHumidity(); + + /** + * @fn stopPeriodicMode + * @brief Exit from cycle measurement mode + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + */ + bool stopPeriodicMode(); + + /** + * @fn heaterEnable + * @brief Turn on the heater inside the chip + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + */ + bool heaterEnable(); + + /** + * @fn heaterDisable + * @brief Turn off the heater inside the chip + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + */ + bool heaterDisable(); + + /** + * @fn clearStatusRegister + * @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + * @n Set bit:15 to 0 so that ALERT pin can work, otherwise it will keep high. + */ + void clearStatusRegister(); + + /** + * @fn readAlertState + * @brief Read the state of the pin ALERT. + * @return High returns 1, low returns 0. + */ + bool readAlertState(); + + /** + * @fn environmentState + * @brief Determine if the temperature and humidity are out of the threshold range + * @return Return the status code, representing as follows + * @retval 01 :Indicates that the humidity exceeds the lower threshold range + * @retval 10 :Indicates that the temperature exceeds the lower threshold range + * @retval 11 :Indicates that both the humidity and the temperature exceed the lower threshold range + * @retval 02 :Indicates that the humidity exceeds the upper threshold range + * @retval 20 :Indicates that the temperature exceeds the upper threshold range + * @retval 22 :Indicates that both the humidity and the temperature exceed the upper threshold range + * @retval 12 :Indicates that the temperature exceeds the lower threshold range, + * @n and the humidity exceeds the upper threshold range + * @retval 21 :Indicates that the temperature exceeds the upper threshold range, + * @n and the humidity exceeds the lower threshold range + */ + uint8_t environmentState(); + + /** + * @fn setTemperatureLimitC + * @brief Set the threshold temperature and alarm clear temperature(°C) + * @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + * @note range: -40 to 125 degrees Celsius, highset > highClear > lowclear > lowset. + * @return A return to 0 indicates a successful setting. + */ + uint8_t setTemperatureLimitC(float highset,float highclear,float lowset,float lowclear); + + /** + * @fn setTemperatureLimitF + * @brief Set the threshold temperature and alarm clear temperature(°F) + * @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + * @note Range: -40 to 257 (Fahrenheit), highset > highClear > lowclear > lowset. + * @return A return to 0 indicates a successful setting. + */ + uint8_t setTemperatureLimitF(float highset,float highclear, float lowset,float lowclear); + + /** + * @fn setHumidityLimitRH + * @brief Set the relative humidity threshold temperature and the alarm clear humidity(%RH) + * @param highset High humidity alarm point, when the humidity is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High humidity alarm clear point, alarming when the humidity higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low humidity alarm point, when the humidity is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low humidity alarm clear point, alarming when the humidity lower than the highset, otherwise the alarm signal will be cleared. + * @note range: 0 - 100 %RH, highset > highClear > lowclear > lowset + * @return: A return to 0 indicates a successful setting. + */ + uint8_t setHumidityLimitRH(float highset,float highclear, float lowset,float lowclear); + + /** + * @fn measureTemperatureLimitC + * @brief Measure temperature threshold temperature and alarm clear temperature + * @return Return true indicates successful data acquisition + */ + bool measureTemperatureLimitC(); + + /** + * @fn getTemperatureHighSetC + * @brief Get high temperature alarm points(°C) + * @return Return high temperature alarm points(°C) + */ + float getTemperatureHighSetC(); + + /** + * @fn getTemperatureHighClearC + * @brief Get high temperature alarm clear points(°C) + * @return Return high temperature alarm clear points(°C) + */ + float getTemperatureHighClearC(); + + /** + * @fn getTemperatureLowClearC + * @brief Get low temperature alarm clear points(°C) + * @return Return low temperature alarm clear points(°C) + */ + float getTemperatureLowClearC(); + + /** + * @fn getTemperatureLowSetC + * @brief Get low temperature alarm points(°C) + * @return Return low temperature alarm points + */ + float getTemperatureLowSetC(); + + /** + * @fn measureTemperatureLimitF + * @brief Measure the threshold temperature and alarm clear temperature + * @return Return true indicates successful data acquisition + */ + bool measureTemperatureLimitF(); + + /** + * @fn getTemperatureHighSetF + * @brief Get high temperature alarm points(°F) + * @return Return high temperature alarm points(°F) + */ + float getTemperatureHighSetF(); + + /** + * @fn getTemperatureHighClearF + * @brief Get high temperature alarm clear points(°F) + * @return Return high temperature alarm clear points(°F)) + */ + float getTemperatureHighClearF(); + + /** + * @fn getTemperatureLowClearF + * @brief Get low temperature alarm clear points(°F) + * @return Return low temperature alarm clear points(°F) + */ + float getTemperatureLowClearF(); + + /** + * @fn getTemperatureLowSetF + * @brief Get low temperature alarm points(°F) + * @return Return low temperature alarm points + */ + float getTemperatureLowSetF(); + + /** + * @fn measureHumidityLimitRH + * @brief Measure the threshold humidity of relative humidity and alarm clear humidity + * @return Return true indicates successful data acquisition + */ + bool measureHumidityLimitRH(); + + /** + * @fn getHumidityHighSetRH + * @brief Get the high humidity alarm point(%RH) + * @return Return the high humidity alarm point + */ + float getHumidityHighSetRH(); + + /** + * @fn getHumidityHighClearRH + * @brief Get the high humidity alarm clear point(%RH) + * @return Return the high humidity alarm clear point + */ + float getHumidityHighClearRH(); + + /** + * @fn getHumidityLowClearRH + * @brief Get the low humidity alarm clear point(%RH) + * @return Return the low humidity alarm clear point + */ + float getHumidityLowClearRH(); + + /** + * @fn getHumidityLowSetRH + * @brief Get the low humidity alarm point + * @return Return the low humidity alarm point + */ + float getHumidityLowSetRH(); + +private: + + /** + * @fn writeCommand + * @brief Write commands to the sensor chip + * @param cmd chip command + * @param size The number of command data, 8 digits for one data. + */ + void writeCommand(uint16_t cmd,size_t size); + /** + * @fn readStatusRegister + * @brief Read the data stored in the status register. + * @return Return to status like whether heater is ON or OFF, the status of the pin alert, reset status and the former cmd is executed or not. + */ + sStatusRegister_t readStatusRegister(); + + /** + * @fn writeLimitData + * @brief Write threshold data. + * @param cmd Send threshold data of chip command. + * @param limitData Raw data on temperature and humidity need to be sent (humidity is 7 bits and temperatures are 11 bits). + * @return Return 0 indicates that the command was sent successfully, other return values suggest unsuccessful send. + */ + void writeLimitData(uint16_t cmd,uint16_t limitData); + + /** + * @fn readLimitData + * @brief Read threshold data. + * @param cmd Read threshold data of chip command. + * @param *pBuf Save read data. + */ + uint8_t readLimitData(uint16_t cmd,uint16_t *pBuf); + /** + * @fn readData + * @brief Write command to sensor chip. + * @param pBuf The data contained in the command. + * @param size Number of command data + * @return Return 0 indicates the successful read, other return values suggest unsuccessful read. + */ + uint8_t readData(void *pBuf,size_t size); + + /** + * @fn checkCrc + * @brief CRC calibration. + * @param data[] Data need to be calibrated. + * @return Obtained calibration code. + */ + uint8_t checkCrc(uint8_t data[]); + + /** + * @fn convertTemperature + * @brief Convert the data returned from the sensor to temperature(°C). + * @param Data obtained from the sensor + * @return Celsius temperature. + */ + float convertTemperature(uint8_t rawTemperature[]); + /** + * @fn convertHumidity + * @brief Convert the data returned from the sensor to relative humidity. + * @param Data obtained from the sensor. + * @return Relative humidity. + */ + float convertHumidity(uint8_t rawHumidity[]); + + /** + * @fn convertRawTemperature + * @brief The temperature data to be written is converted into the data needed by the chip. + * @param The temperature need to be written. + * @return Data write to sensor. + */ + uint16_t convertRawTemperature(float value); + /** + * @fn convertRawHumidity + * @brief The relative humidity data to be written is converted into the data needed by the chip. + * @param The relative humidity data to be written + * @return Data write to sensor. + */ + uint16_t convertRawHumidity(float value); + /** + * @fn convertTempLimitData + * @brief Convert the data returned from the sensor to temperature limited data + * @param Temperature limited data from sensor + * @return Temperature limited data + */ + float convertTempLimitData(uint16_t limit[]); + /** + * @fn convertHumidityLimitData + * @brief Convert the data returned from the sensor to humidity limited data + * @param Humidity limited data from sensor + * @return Humidity limited data + */ + float convertHumidityLimitData(uint16_t limit[]); + /** + * @fn write + * @brief Transport data to chip + * @param Data address + * @param Data length + */ + void write(const void* pBuf,size_t size); + +private: + + sLimitData_t limitData; + sRHAndTemp_t tempRH; + TwoWire *_pWire; + eMode_t measurementMode ; + uint8_t _address; + uint8_t _RST; + float tempHighSet ; + float tempLowSet ; +}; +#endif diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/LICENSE b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..79f310082f4253cee659e29e2d888ada0024ba25 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/LICENSE @@ -0,0 +1,7 @@ +Copyright 2010 DFRobot Co.Ltd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README.md b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4a460ce3fc74b43a15ffa5fd81bc37d93dc36676 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README.md @@ -0,0 +1,356 @@ +# DFRobot_SHT3x +- [中文版](./README_CN.md) + +The SHT3x series chips are used to measure ambient temperature and relative humidity (the degree of moisture in the air, which indicates the degree to which the moisture content in the atmosphere is saturated from the atmosphere). <br> +It is a successor to the SHT2x series that contain the low-cost version of the SHT30, the standard version of SHT31, and the professional version of SHT35.<br> +The SHT3x series temperature and humidity sensors adopt IIC communication which is easy to use, with a wide operating voltage range (2.15 to 5.5 V), and a space area of the chip package is 2.5 x 2.5 mm2 and 0.9 mm high, which can help SHT3x be easily integrated into a wide range of applications for a wide range of scenarios.<br> +Based on brand-new optimized CMOSens® chip, SHT3x further improved its product reliability and accuracy specifications.<br> +SHT3x offers a range of new features, e.g. enhanced signal processing, two unique user-selectable I2C addresses, an alarm mode with programmable temperature and humidity limits, and communication speeds up to 1 MHz.<br> +<br> +You can choose to open or not open the heater +Heater Function<br> +①By comparing the relative humidity and temperature values measured before and after heating, it is possible to determine whether the sensor is working properly.<br> +②Using heaters in wet environments can avoid sensor condensation.<br> +③A heater can also measure the dew point temperature (the temperature at which water vapor in the air turns into dewdrops).<br> +The SHT3x chip offers two modes of operation:<br> +1.Single measurement mode with an idle state current of 0.2 mA and low power consumption (measurement data is 600 mA).<br> +2.Cycle measurement mode, where the idle state current is 45 mA, and in this mode ALERT starts to work(measurement data is 600 mA)<br> +The following is the typical measurement accuracy of the chip (followed by this temperature and humidity range):<br> + +Version No.|Typical Temp Precision (°C)|Typical Humidity Precision(%RH)| Range(Temp/Humidity) +-----------|:-------------------------:|:-----------------------------:|:---------------------- +SHT30 | ±0.2 @0-65 °C | ±2 @10-90% RH | -40-125 °C/0-100 %RH +SHT31 | ±0.2 @0-90 °C | ±2 @0-100% RH | -40-125 °C/0-100 %RH +SHT35 | ±0.1 @20-60°C | ±1.5 @0-80% RH | -40-125 °C/0-100 %RH + + + + + + + +## Product Link(https://www.dfrobot.com/product-2016.html) + + SEN0330:Fermion: SHT30 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0331:Fermion: SHT31 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0332:Fermion: SHT31-F Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0333:Fermion: SHT35 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0334:Gravity: SHT31-F Digital Temperature and Humidity Sensor<br> +## Table of Contents + +* [Summary](#summary) +* [Installation](#installation) +* [Methods](#methods) +* [Compatibility](#compatibility) +* [History](#history) +* [Credits](#credits) + +## Summary + + 1.Read repeatability of the temperature and humidity data in single measurement mode, users can select the measure repeatability(the difference between the data measured by the chip under the same measurement conditions).<br> + The higher the repeatability is, the smaller the difference and the more dependable data will be.<br> + 2.Read repeatability of the temperature and humidity data in cycle measurement mode, users can select the measure repeatability and the measure frequency(0.5Hz,1Hz,2Hz,4Hz,10Hz).<br> + 3.The user can customize the threshold range. The ALERT pin and the Arduino's interrupt pin can achieve the effect of the temperature and humidity threshold alarm.<br> +## Installation +To use this library, please download the library file first, and paste it into the \Arduino\libraries directory, then open the examples folder and run the demo in the folder. + +## Methods + +```C++ + /** + * @fn readSerialNumber + * @brief Read the serial number of the chip + * @return 32-digit serial number + */ + uint32_t readSerialNumber(); + + /** + * @fn begin + * @brief Initialize the function + * @return Return 0 indicates a successful initialization, while other values indicates failure and return to error code. + */ + int begin(); + + /** + * @fn softReset + * @brief Send command resets via iiC, enter the chip's default mode single-measure mode, + * turn off the heater, and clear the alert of the ALERT pin. + * @return Read the status register to determine whether the command was executed successfully, and returning true indicates success + */ + bool softReset(); + + /** + * @fn pinReset + * @brief Reset through the chip's reset pin, enter the chip's default mode single-measure mode, and clear the alert of the ALERT pin. + * @return The status register has a data bit that detects whether the chip has been reset, and returning true indicates success + */ + bool pinReset(); + + /** + * @fn readTemperatureAndHumidity + * @brief Get temperature and humidity data in single measurement mode. + * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t. + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + * @n A status of 0 indicates the right return data. + */ + sRHAndTemp_t readTemperatureAndHumidity(eRepeatability_t repeatability ); + + /** + * @fn getTemperatureC + * @brief Get the measured temperature (in degrees Celsius) + * @return Return the float temperature data + */ + float getTemperatureC(); + + /** + * @fn getTemperatureF + * @brief Get the measured temperature (in degrees Fahrenheit) + * @return Return the float temperature data + */ + float getTemperatureF(); + + /** + * @fn getHumidityRH + * @brief Get measured humidity(%RH) + * @return Return the float humidity data + */ + float getHumidityRH(); + + /** + * @fn startPeriodicMode + * @brief Enter cycle measurement mode and set repeatability(the difference between the data measured + * the difference between the data measured by the chip under the same measurement conditions) + * @param measureFreq Read the eMeasureFrequency_t data frequency + * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t. + * eRepeatability_High(high repeatability mode) in default. + * @return Return true indicates a successful entrance to cycle measurement mode. + */ + bool startPeriodicMode(eMeasureFrequency_t measureFreq,eRepeatability_t repeatability = eRepeatability_High); + + /** + * @fn readTemperatureAndHumidity + * @brief Get temperature and humidity data in cycle measurement mode. + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + * @n A status of 0 indicates the right return data. + */ + sRHAndTemp_t readTemperatureAndHumidity(); + + /** + * @fn stopPeriodicMode + * @brief Exit from cycle measurement mode + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + */ + bool stopPeriodicMode(); + + /** + * @fn heaterEnable + * @brief Turn on the heater inside the chip + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + */ + bool heaterEnable(); + + /** + * @fn heaterDisable + * @brief Turn off the heater inside the chip + * @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + */ + bool heaterDisable(); + + /** + * @fn clearStatusRegister + * @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + * @n Set bit:15 to 0 so that ALERT pin can work, otherwise it will keep high. + */ + void clearStatusRegister(); + + /** + * @fn readAlertState + * @brief Read the state of the pin ALERT. + * @return High returns 1, low returns 0. + */ + bool readAlertState(); + + /** + * @fn environmentState + * @brief Determine if the temperature and humidity are out of the threshold range + * @return Return the status code, representing as follows + * @retval 01 :Indicates that the humidity exceeds the lower threshold range + * @retval 10 :Indicates that the temperature exceeds the lower threshold range + * @retval 11 :Indicates that both the humidity and the temperature exceed the lower threshold range + * @retval 02 :Indicates that the humidity exceeds the upper threshold range + * @retval 20 :Indicates that the temperature exceeds the upper threshold range + * @retval 22 :Indicates that both the humidity and the temperature exceed the upper threshold range + * @retval 12 :Indicates that the temperature exceeds the lower threshold range, + * @n and the humidity exceeds the upper threshold range + * @retval 21 :Indicates that the temperature exceeds the upper threshold range, + * @n and the humidity exceeds the lower threshold range + */ + uint8_t environmentState(); + + /** + * @fn setTemperatureLimitC + * @brief Set the threshold temperature and alarm clear temperature(°C) + * @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + * @note range: -40 to 125 degrees Celsius, highset > highClear > lowclear > lowset. + * @return A return to 0 indicates a successful setting. + */ + uint8_t setTemperatureLimitC(float highset,float highclear,float lowset,float lowclear); + + /** + * @fn setTemperatureLimitF + * @brief Set the threshold temperature and alarm clear temperature(°F) + * @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + * @note Range: -40 to 257 (Fahrenheit), highset > highClear > lowclear > lowset. + * @return A return to 0 indicates a successful setting. + */ + uint8_t setTemperatureLimitF(float highset,float highclear, float lowset,float lowclear); + + /** + * @fn setHumidityLimitRH + * @brief Set the relative humidity threshold temperature and the alarm clear humidity(%RH) + * @param highset High humidity alarm point, when the humidity is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High humidity alarm clear point, alarming when the humidity higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low humidity alarm point, when the humidity is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low humidity alarm clear point, alarming when the humidity lower than the highset, otherwise the alarm signal will be cleared. + * @note range: 0 - 100 %RH, highset > highClear > lowclear > lowset + * @return: A return to 0 indicates a successful setting. + */ + uint8_t setHumidityLimitRH(float highset,float highclear, float lowset,float lowclear); + + /** + * @fn measureTemperatureLimitC + * @brief Measure temperature threshold temperature and alarm clear temperature + * @return Return true indicates successful data acquisition + */ + bool measureTemperatureLimitC(); + + /** + * @fn getTemperatureHighSetC + * @brief Get high temperature alarm points(°C) + * @return Return high temperature alarm points(°C) + */ + float getTemperatureHighSetC(); + + /** + * @fn getTemperatureHighClearC + * @brief Get high temperature alarm clear points(°C) + * @return Return high temperature alarm clear points(°C) + */ + float getTemperatureHighClearC(); + + /** + * @fn getTemperatureLowClearC + * @brief Get low temperature alarm clear points(°C) + * @return Return low temperature alarm clear points(°C) + */ + float getTemperatureLowClearC(); + + /** + * @fn getTemperatureLowSetC + * @brief Get low temperature alarm points(°C) + * @return Return low temperature alarm points + */ + float getTemperatureLowSetC(); + + /** + * @fn measureTemperatureLimitF + * @brief Measure the threshold temperature and alarm clear temperature + * @return Return true indicates successful data acquisition + */ + bool measureTemperatureLimitF(); + + /** + * @fn getTemperatureHighSetF + * @brief Get high temperature alarm points(°F) + * @return Return high temperature alarm points(°F) + */ + float getTemperatureHighSetF(); + + /** + * @fn getTemperatureHighClearF + * @brief Get high temperature alarm clear points(°F) + * @return Return high temperature alarm clear points(°F)) + */ + float getTemperatureHighClearF(); + + /** + * @fn getTemperatureLowClearF + * @brief Get low temperature alarm clear points(°F) + * @return Return low temperature alarm clear points(°F) + */ + float getTemperatureLowClearF(); + + /** + * @fn getTemperatureLowSetF + * @brief Get low temperature alarm points(°F) + * @return Return low temperature alarm points + */ + float getTemperatureLowSetF(); + + /** + * @fn measureHumidityLimitRH + * @brief Measure the threshold humidity of relative humidity and alarm clear humidity + * @return Return true indicates successful data acquisition + */ + bool measureHumidityLimitRH(); + + /** + * @fn getHumidityHighSetRH + * @brief Get the high humidity alarm point(%RH) + * @return Return the high humidity alarm point + */ + float getHumidityHighSetRH(); + + /** + * @fn getHumidityHighClearRH + * @brief Get the high humidity alarm clear point(%RH) + * @return Return the high humidity alarm clear point + */ + float getHumidityHighClearRH(); + + /** + * @fn getHumidityLowClearRH + * @brief Get the low humidity alarm clear point(%RH) + * @return Return the low humidity alarm clear point + */ + float getHumidityLowClearRH(); + + /** + * @fn getHumidityLowSetRH + * @brief Get the low humidity alarm point + * @return Return the low humidity alarm point + */ + float getHumidityLowSetRH(); + +``` + +## Compatibility + +MCU | Work Well | Work Wrong | Untested | Remarks +------------------ | :----------: | :----------: | :---------: | ----- +Arduino uno | √ | | | +Mega2560 | √ | | | +Leonardo | √ | | | +ESP32 | √ | | | +micro:bit | √ | | | + +## History + +- 2019/08/25 - Version 1.0.0 released. + +## Credits + +Written by fengli(li.feng@dfrobot.com), 2019.8.25 (Welcome to our [website](https://www.dfrobot.com/)) + + + + + diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README_CN.md b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README_CN.md new file mode 100644 index 0000000000000000000000000000000000000000..52348bebdbf9d0ac7ea4864d93d17abe50a69782 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/README_CN.md @@ -0,0 +1,356 @@ +# DFRobot_SHT3x +- [English Version](./README.md) + +SHT3x系列芯片用于测量环境温度和相对湿度(空气中的潮湿程度,它表示大气中水汽含量距离大气饱和的程度),它是SHT2x系列的继承者,包括低成本版本SHT30、标准版本SHT31,以及高端版本SHT35<br> +SHT3x系列温湿度传感器通过IIC通信,使用比较方便,工作电压范围宽(2.15至5.5 V),芯片封装的占位面积<br> +为2.5 × 2.5 mm2,高度为0.9 mm,这有助于SHT3x集成到多种应用,适合各类场景<br> +SHT3x建立在全新和优化的CMOSens® 芯片之上,进一步提高了产品可靠性和精度规格。SHT3x提供了一系列新功能,<br> +如增强信号处理、两个独特的用户可选的I2C地址、一个可编程温湿度极限的报警模式,以及高达1 MHz的通信速度<br> +在使用过程中可选择是否打开加热器<br> + 加热器作用:<br> + ①通过比较加热前后测出的相对湿度值及温度值,可确定传感器是否正常工作;<br> + ②在潮湿环境下使用加热器,可避免传感器凝露;<br> + ③测量露点温度(空气中的水蒸气变为露珠时候的温度)时也需要使用加热器。<br> +SHT3x芯片提供两种工作模式:<br> +1.单次测量模式,此模式下空闲状态电流为0.2微安,功耗较低(测量数据时600 微安).<br> +2.周期测量模式,此模式下空闲状态电流为45微安,此模式下ALERT开始工作(测量数据时600 微安).<br> +以下是芯片典型的测量精度(@后面是在此温湿度范围下):<br> + +版本号 | 典型温度精度 (°C) | 典型湿度精度 (%RH) | 测量范围(温度/湿度) +--------------------| :-------------------: | :---------------------: | ----- +SHT30 | ±0.2 @0-65 °C | ±2 @10-90% RH | -40-125 °C/0-100 %RH +SHT31 | ±0.2 @0-90 °C | ±2 @0-100% RH | -40-125 °C/0-100 %RH +SHT35 | ±0.1 @20-60 °C | ±1.5 @0-80% RH | -40-125 °C/0-100 %RH + + + + + + + + +## 产品链接(https://www.dfrobot.com.cn/goods-2695.html) + + SEN0330:Fermion: SHT30数字温湿度传感器<br> + SEN0331:Fermion: SHT31数字温湿度传感器<br> + SEN0332:Fermion: SHT31-F数字温湿度传感器<br> + SEN0333:Fermion: SHT35-F数字温湿度传感器(Breakout)<br> + SEN0334:Gravity: SHT31-F数字温湿度传感器<br> + +## 目录 + + * [概述](#概述) + * [库安装](#库安装) + * [方法](#方法) + * [兼容性](#兼容性) + * [历史](#历史) + * [创作者](#创作者) + +## 概述 + 1.在单次测量模式下读取环境温湿度,用户可以选择测量的可重复性(芯片在两次相同测量条件下测量到的数据的差值)<br> + 可重复性越高,差值越小,数据越可靠<br> + 2.在周期测量模式下读取环境温湿度,用户可以选择测量的可重复性和测量频率(0.5Hz,1Hz,2Hz,4Hz,10Hz)<br> + 3.利用ALERT引脚和Arduino的中断引脚达到温湿度超阈值报警的效果,用户可自定义阈值大小<br> + +## 库安装 + +要使用这个库,首先下载库文件,将其粘贴到\Arduino\libraries目录中,然后打开示例文件夹并在文件夹中运行演示程序。 + + +## 方法 + +```C++ + +/** + * @fn readSerialNumber + * @brief 读取芯片的序列号 + * @return 返回32位序列号 + */ +uint32_t readSerialNumber(); + +/** + * @fn begin + * @brief 初始化函数 + * @return 返回0表示初始化成功,返回其他值表示初始化失败,返回错误码 + */ +int begin(); + +/** + * @fn softReset + * @brief 通过IIC发送命令复位,进入芯片的默认模式单次测量模式,关闭加热器,并清除ALERT引脚的警报。 + * @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + */ +bool softReset(); + +/** + * @fn pinReset + * @brief 通过芯片的复位引脚进行复位,进入芯片的默认模式单次测量模式,并清除ALERT引脚的警报。 + * @return 状态寄存器有一数据位能检测芯片是否进行了复位,返回true则表示成功 + */ +bool pinReset(); + +/** + * @fn readTemperatureAndHumidity + * @brief 在单次测量模式下获取温湿度数据 + * @param repeatability 设置读取温湿度数据的可重复性,eRepeatability_t类型的数据 + * @return 返回包含摄氏温度(°C),华氏温度(°F),相对湿度(%RH),状态码的结构体 + * @n 状态为0表示返回数据正确 + */ +sRHAndTemp_t readTemperatureAndHumidity(eRepeatability_t repeatability ); + +/** + * @fn getTemperatureC + * @brief 获取测量到的温度(单位:摄氏度) + * @return 返回float类型的温度数据 + */ +float getTemperatureC(); + +/** + * @fn getTemperatureF + * @brief 获取测量到的温度(单位:华氏度) + * @return 返回float类型的温度数据 + */ +float getTemperatureF(); + +/** + * @fn getHumidityRH + * @brief 获取测量到的湿度(单位:%RH) + * @return 返回float类型的湿度数据 + */ +float getHumidityRH(); + +/** + * @fn startPeriodicMode + * @brief 进入周期测量模式,并设置可重复性(芯片在两次相同测量条件下测量到的数据的差值)、读取频率。 + * @param measureFreq 读取数据的频率,eMeasureFrequency_t类型的数据 + * @param repeatability 设置读取温湿度数据的可重复性,eRepeatability_t类型的数据,默认为eRepeatability_High(高重复性) + * @return 返回true表示进入周期模式成功。 + */ +bool startPeriodicMode(eMeasureFrequency_t measureFreq,eRepeatability_t repeatability = eRepeatability_High); + +/** + * @fn readTemperatureAndHumidity + * @brief 在周期测量模式下获取温湿度数据. + * @return 返回包含摄氏温度(°C),华氏温度(°F),相对湿度(%RH),状态码的结构体 + * @n 状态为0表示返回数据正确 + */ +sRHAndTemp_t readTemperatureAndHumidity(); + +/** + * @fn stopPeriodicMode + * @brief 从周期读取数据模式退出。 + * @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + */ +bool stopPeriodicMode(); + +/** + * @fn heaterEnable + * @brief 打开芯片里面的加热器. + * @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + * @note 加热器的使用条件,应是在潮湿环境时,若正常情况下使用则会造成读数不准. + */ +bool heaterEnable(); + +/** + * @fn heaterDisable + * @brief 关闭芯片里面的加热器. + * @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + * @note 加热器的使用条件,应是在潮湿环境时,若正常情况下使用则会造成读数不准. + */ +bool heaterDisable(); + +/** + * @fn clearStatusRegister + * @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + * @n 把bit:15 设置为0后ALERT引脚才能正常工作,否则将一直处于高电平。 + */ +void clearStatusRegister(); + +/** + * @fn readAlertState + * @brief 读取ALERT引脚的状态. + * @return 高电平则返回1,低电平则返回0. + */ +bool readAlertState(); + +/** + * @fn environmentState + * @brief 判断温湿度超出阈值范围的情况 + * @return 返回状态码,状态码代表含义如下: + * @n 01 :表示湿度超过下阈值范围 + * @n 10 :表示温度超过下阈值范围 + * @n 11 :表示温湿度都超过下阈值范围 + * @n 02 :表示湿度超过上阈值范围 + * @n 20 :表示温度超过上阈值范围 + * @n 22 :表示温湿度都超过上阈值范围 + * @n 12 :表示温度超过下阈值范围,湿度超过上阈值范围 + * @n 21 :表示温度超过上阈值范围,湿度超过下阈值范围 + */ +uint8_t environmentState(); + +/** + * @fn setTemperatureLimitC + * @brief 设置温度阈值温度和警报清除温度(°C) + * @param highset 高温报警点,当温度大于此值时ALERT引脚产生报警信号。 + * @param highClear 高温警报清除点,当温度大于highset产生报警信号,而温度小于此值报警信号则被清除。 + * @param lowset 低温报警点,当温度小于此值时ALERT引脚产生报警信号。 + * @param lowclear 低温警报清除点,当温度小于lowset产生报警信号,而温度大于此值时报警信号则被清除 + * @note 范围:-40 到 125 ,highset>highClear>lowclear>lowset。 + * @return 返回0则表示设置成功. + */ +uint8_t setTemperatureLimitC(float highset,float highclear,float lowset,float lowclear); + +/** + * @fn setTemperatureLimitF + * @brief 设置温度阈值温度和警报清除温度(°F) + * @param highset 高温报警点,当温度大于此值时ALERT引脚产生报警信号。 + * @param highClear 高温警报清除点,当温度大于highset产生报警信号,而温度小于此值报警信号则被清除。 + * @param lowset 低温报警点,当温度小于此值时ALERT引脚产生报警信号。 + * @param lowclear 低温警报清除点,当温度小于lowset产生报警信号,而温度大于此值时报警信号则被清除。 + * @note 范围:-40 到 257 ,highset>highClear>lowclear>lowset。 + * @return 返回0则表示设置成功. + */ +uint8_t setTemperatureLimitF(float highset,float highclear, float lowset,float lowclear); + +/** + * @fn setHumidityLimitRH + * @brief 设置相对湿度阈值温度和警报清除湿度(%RH) + * @param highset 高湿度报警点,当相对湿度大于此值时ALERT引脚产生报警信号。 + * @param highClear 高湿度警报清除点,当相对湿度大于highset产生报警信号,而相对湿度小于此值报警信号则被清除。 + * @param lowset 低湿度报警点,当相对湿度小于此值时ALERT引脚产生报警信号。 + * @param lowclear 低湿度警报清除点,当相对湿度小于lowset产生报警信号,而相对湿度大于此值时报警信号则被清除。 + * @note 范围:0 - 100 %RH,highset>highClear>lowclear>lowset。 + * @return 返回0则表示设置成功. + */ +uint8_t setHumidityLimitRH(float highset,float highclear, float lowset,float lowclear); + +/** + * @fn measureTemperatureLimitC + * @brief 测量温度阈值温度和警报清除温度 + * @return 返回true 表示数据获取成功 + */ +bool measureTemperatureLimitC(); + +/** + * @fn getTemperatureHighSetC + * @brief 获取高温报警点温度(°C) + * @return 返回高温报警点温度 + */ +float getTemperatureHighSetC(); + +/** + * @fn getTemperatureHighClearC + * @brief 获取高温警报清除点温度(°C) + * @return 返回高温警报清除点温度 + */ +float getTemperatureHighClearC(); + +/** + * @fn getTemperatureLowClearC + * @brief 获取低温警报清除点温度(°C) + * @return 返回低温警报清除点温度 + */ +float getTemperatureLowClearC(); + +/** + * @fn getTemperatureLowSetC + * @brief 获取低温报警点温度(°C) + * @return 返回低温报警点温度 + */ +float getTemperatureLowSetC(); + +/** + * @fn measureTemperatureLimitF + * @brief 测量相对湿度阈值温度和警报清除湿度 + * @return 返回true 表示数据获取成功 + */ +bool measureTemperatureLimitF(); + +/** + * @fn getTemperatureHighSetF + * @brief 获取高温报警点温度(°F) + * @return 返回高温报警点温度 + */ +float getTemperatureHighSetF(); + +/** + * @fn getTemperatureHighClearF + * @brief 获取高温警报清除点温度(°F) + * @return 返回高温警报清除点温度 + */ +float getTemperatureHighClearF(); + +/** + * @fn getTemperatureLowClearF + * @brief 获取低温警报清除点温度(°F) + * @return 返回低温警报清除点温度 + */ +float getTemperatureLowClearF(); + +/** + * @fn getTemperatureLowSetF + * @brief 获取低温报警点温度(°F) + * @return 返回低温报警点温度 + */ +float getTemperatureLowSetF(); + +/** + * @fn measureHumidityLimitRH + * @brief 读取相对湿度阈值温度和警报清除湿度 + * @return 返回true 表示数据获取成功 + */ +bool measureHumidityLimitRH(); + +/** + * @fn getHumidityHighSetRH + * @brief 获取高湿度报警点湿度(%RH) + * @return 返回高湿度报警点湿度 + */ +float getHumidityHighSetRH(); + +/** + * @fn getHumidityHighClearRH + * @brief 获取高湿度警报清除点湿度(%RH) + * @return 返回高湿度警报清除点湿度 + */ +float getHumidityHighClearRH(); + +/** + * @fn getHumidityLowClearRH + * @brief 获取低湿度警报清除点湿度(%RH) + * @return 返回低湿度警报清除点湿度 + */ +float getHumidityLowClearRH(); + +/** + * @fn getHumidityLowSetRH + * @brief 获取低湿度报警点湿度(v) + * @return 返回低湿度报警点湿度 + */ +float getHumidityLowSetRH(); + + +``` + +## 兼容性 + +主板 | 通过 | 未通过 | 未测试 | 备注 +------------------ | :----------: | :----------: | :---------: | ----- +Arduino uno | √ | | | +Mega2560 | √ | | | +Leonardo | √ | | | +ESP32 | √ | | | +micro:bit | √ | | | + + +## 兼容性 + +- 2019/08/25 - 1.0.0 版本 + +## 创作者 + +Written by fengli(li.feng@dfrobot.com), 2019.8.25 (Welcome to our [website](https://www.dfrobot.com/)) + + + + diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/alert/alert.ino b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/alert/alert.ino new file mode 100644 index 0000000000000000000000000000000000000000..d5d388c7e5dd3f43216cc268cc3a32201bdf055c --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/alert/alert.ino @@ -0,0 +1,255 @@ +/*! + * @file alert.ino + * @brief Temperature and humidity over-threshold alarm. + * @details Experimental phenomenon: The user can customize the temperature and humidity thresholds, + * @n and the ALERT pin generates an alarm signal once the values exceed the user-defined threshold. + * @n NOTE: The ALERT pin on the sensor should be connected to the interrupt pin on the main panel when using this function. + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @License The MIT License (MIT) + * @author [fengli](li.feng@dfrobot.com) + * @version V1.0 + * @date 2019-08-26 + * @url https://github.com/DFRobot/DFRobot_SHT3x + */ + +#include <DFRobot_SHT3x.h> +/*! + * @brief Construct the function + * @param pWire IIC bus pointer object and construction device, can both pass or not pass parameters, Wire in default. + * @param address Chip IIC address, two optional addresses 0x44 and 0x45(0x45 in default). + * @param RST Chip reset pin, 4 in default. + * @n IIC address is determined by the pin addr on the chip. + * @n When the ADR is connected to VDD, the chip IIC address is 0x45. + * @n When the ADR is connected to GND, the chip IIC address is 0x44. + */ +//DFRobot_SHT3x sht3x(&Wire,/*address=*/0x45,/*RST=*/4); + +DFRobot_SHT3x sht3x; +//The non-alarm status of the alert pin is low; +volatile int alertState = 0; +void alert(){ + alertState = 1 - alertState; +} +void setup() { + Serial.begin(9600); + #ifdef ARDUINO_ARCH_MPYTHON + /* The Correspondence Table of ESP32 Interrupt Pins And Terminal Numbers + * ----------------------------------------------------------------------------------------------------- + * | | DigitalPin | P0-P20 can be used as an external interrupt | + * | esp32 |--------------------------------------------------------------------------------------| + * | | Interrupt No | DigitalPinToInterrupt (Pn) can be used to query the interrupt number | + * |---------------------------------------------------------------------------------------------------| + */ + attachInterrupt(digitalPinToInterrupt(P16)/*Query the interrupt number of the P16 pin*/,alert,CHANGE); + //Open esp32's P16 pin for external interrupt, bilateral edge trigger, ALERT connected to P16 + #else + /* The Correspondence Table of AVR Series Arduino Interrupt Pins And Terminal Numbers + * --------------------------------------------------------------------------------------- + * | | DigitalPin | 2 | 3 | | + * | Uno, Nano, Mini, other 328-based |--------------------------------------------| + * | | Interrupt No | 0 | 1 | | + * |-------------------------------------------------------------------------------------| + * | | Pin | 2 | 3 | 21 | 20 | 19 | 18 | + * | Mega2560 |--------------------------------------------| + * | | Interrupt No | 0 | 1 | 2 | 3 | 4 | 5 | + * |-------------------------------------------------------------------------------------| + * | | Pin | 3 | 2 | 0 | 1 | 7 | | + * | Leonardo, other 32u4-based |--------------------------------------------| + * | | Interrupt No | 0 | 1 | 2 | 3 | 4 | | + * |-------------------------------------------------------------------------------------- + */ + /* The Correspondence Table of micro:bit Interrupt Pins And Terminal Numbers + * --------------------------------------------------------------------------------------------------------------------------------------------- + * | micro:bit | DigitalPin |P0-P20 can be used as an external interrupt | + * | (When using as an external interrupt, |---------------------------------------------------------------------------------------------| + * |no need to set it to input mode with pinMode)|Interrupt No|Interrupt number is a pin digital value, such as P0 interrupt number 0, P1 is 1 | + * |-------------------------------------------------------------------------------------------------------------------------------------------| + */ + attachInterrupt(/*Interrupt No*/0,alert,CHANGE);//Open the external interrupt 0, connect ALERT to the digital pin of the main control: + //UNO(2), Mega2560(2), Leonardo(3), microbit(P0). + #endif + //Initialize the chip to detect if it can communicate properly + while (sht3x.begin() != 0) { + Serial.println("The initialization of the chip is failed, please confirm whether the chip connection is correct"); + delay(1000); + } + /** + * readSerialNumber Read the serial number of the chip + * @return Return 32-digit serial number + */ + Serial.print("The chip serial number"); + Serial.println(sht3x.readSerialNumber()); + /** + * softReset Send command resets via iiC, enter the chip's default mode single-measure mode, turn off the heater, + * and clear the alert of the ALERT pin. + * @return Read the status register to determine whether the command was executed successfully, and returning true indicates success. + */ + if(!sht3x.softReset()){ + Serial.println("Failed to reset the chip"); + } + /** + * @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero). + * @n ALERT can work properly only when the bit:15 is set to 0, otherwise it will remain high. + */ + sht3x.clearStatusRegister(); + /** + * startPeriodicMode Enter cycle measurement mode and set repeatability, read frequency, and only in this mode ALERT can work. + * @param measureFreq Read the data frequency, data type eMeasureFrequency_t + * @note Selectable parameters: + eMeasureFreq_Hz5, /**the chip collects data in every 2s + eMeasureFreq_1Hz, /**the chip collects data in every 1s + eMeasureFreq_2Hz, /**the chip collects data in every 0.5s + eMeasureFreq_4Hz, /**the chip collects data in every 0.25s + eMeasureFreq_10Hz /**the chip collects data in every 0.1s + * @param repeatability Read the repeatability of temperature and humidity data, the default parameter is eRepeatability_High. + * @note Optional parameters: + eRepeatability_High /**In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C + eRepeatability_Medium,/**In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C. + eRepeatability_Low, /**In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C + * @return Read the status of the register to determine whether the command was executed successfully, and return true indicates success. + */ + if(!sht3x.startPeriodicMode(sht3x.eMeasureFreq_10Hz)){ + Serial.println("Failed to enter the periodic mode"); + } + /** + * setTemperatureLimitC Set the threshold temperature and alarm clear temperature(°C) + * setTemperatureLimitF Set the threshold temperature and alarm clear temperature(°F) + * @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + * @note The filled value should be an integer (range: -40 to 125 degrees Celsius), -40 to 257 (Fahrenheit)highset>highClear>lowclear>lowset) + */ + //sht3x.setTemperatureLimitF(/*highset=*/35,/*highClear=*/34,/*lowSet=*/18,/*lowClear=*/20) + if(sht3x.setTemperatureLimitC(/*highset=*/35,/*highClear=*/34,/*lowSet=*/18,/*lowClear=*/20) != 0){ + Serial.println("Failed to set the temperature limit"); + } + /** + * setHumidityLimitRH Set the relative humidity threshold temperature and the alarm clear humidity(%RH) + * @param highset High humidity alarm point, when the humidity is greater than this value, the ALERT pin generates an alarm signal. + * @param highClear High humidity alarm clear point, alarming when the humidity higher than the highset, otherwise the alarm signal will be cleared. + * @param lowset Low humidity alarm point, when the humidity is lower than this value, the ALERT pin generates an alarm signal. + * @param lowclear Low humidity alarm clear point, alarming when the humidity lower than the highset, otherwise the alarm signal will be cleared. + * @note The filled value should be an integer (range: 0 - 100 %RH,highset>highClear>lowclear>lowset) + */ + if(sht3x.setHumidityLimitRH(/*highset=*/70,/*highClear=*/68,/*lowSet=*/19,/*lowClear=*/20) != 0){ + Serial.println("Failed to set the humidity limit"); + } + //Serial.println(F("string") Save stings to flash to save the dynamic ram when compiling. + Serial.println(F("----------------------Alarm Detection-------------------------------")); + Serial.println(F("Alarms raised when temp and humidity are out of the threshold range. Please connect ALERT to the main control board interrupt pin")); + Serial.println(F("-Different main contorl UNO(2), Mega2560(2), Leonardo(3), microbit(P0), mPython(P16)----")); + Serial.println(F("----------------------the humidity limit(%RH)-----------------------------------")); + /** + * @brief Measure relative humidity threshold temperature and alarm clear humidity + * @return Return true indicates successful data acquisition + */ + if(sht3x.measureHumidityLimitRH()){ + Serial.print("high set:"); + //getHumidityHighSetRH() Get the high humidity alarm point + Serial.print(sht3x.getHumidityHighSetRH()); + Serial.print(" low clear:"); + //getHumidityHighClearRH() Get the high humidity alarm clear point + Serial.println(sht3x.getHumidityLowClearRH()); + Serial.print("high clear:"); + //getHumidityLowClearRH() Get the low humidity alarm clear point + Serial.print(sht3x.getHumidityHighClearRH()); + Serial.print(" low set:"); + //getHumidityLowSetRH() Get the low humidity alarm point + Serial.println(sht3x.getHumidityLowSetRH()); + } else { + Serial.println("Failed to get the humidity limit"); + } + /** + * measureTemperatureLimitC Measure the threshold temperature and alarm clear temperature(°C) + * measureTemperatureLimitF Measure the threshold temperature and alarm clear temperature(°F) + * @return Return true indicates successful data acquisition + */ + Serial.println("----------------------temperature limit(°C)---------------------------------"); + //Serial.println(F("----------------------temperature limit(°F)---------------------------------")); + if(sht3x.measureTemperatureLimitC()){ + Serial.print("high set:"); + //getTemperatureHighSetC() Get high temperature alarm points(°C) + //getTemperatureHighSetF() Get high temperature alarm points(°F) + Serial.print(sht3x.getTemperatureHighSetC()); + Serial.print(" low clear:"); + //getTemperatureHighClearC() Get high temperature alarm clear points(°C) + //getTemperatureHighClearF() Get high temperature alarm clear points(°F)) + Serial.println(sht3x.getTemperatureLowClearC()); + Serial.print("high clear:"); + //getTemperatureLowClearC() Get low temperature alarm clear points(°C) + //getTemperatureLowClearF() Get low temperature alarm clear points(°F) + Serial.print(sht3x.getTemperatureHighClearC()); + Serial.print(" low set:"); + //getTemperatureLowSetC() Get low temperature alarm points(°C) + //getTemperatureLowSetF() Get low temperature alarm points(°F) + Serial.println(sht3x.getTemperatureLowSetC()); + Serial.println("------------------------------------------------------------------"); + } else { + Serial.println("Failed to get temperature limit"); + } + /** + * readAlertState Read the status of the ALERT pin. + * @return High returns 1, low returns 0. + */ + //To initialize the state of ALERT + if(sht3x.readAlertState() == 1){ + alertState = 1; + } else { + alertState = 0; + } +} +void loop() { + Serial.print("environment temperature(°C/F):"); + /** + * getTemperatureC Get the measured temperature (in degrees Celsius) + * @return Return temperature data of the type float + */ + Serial.print(sht3x.getTemperatureC()); + Serial.print(" C/"); + /** + * getTemperatureF Get the measured temperature (in degrees Celsius) + * @return Return temperature data of the type float + */ + Serial.print(sht3x.getTemperatureF()); + Serial.print(" F "); + Serial.print("relative humidity(%RH):"); + /** + * getHumidityRH Get measured humidity (in %RH) + * @return Return humidity data of the type float + */ + Serial.print(sht3x.getHumidityRH()); + Serial.println(" %RH"); + //The read data frequency should greater than the frequency to collect data, otherwise the return data will make errors. + if(alertState == 1){ + /** + * @brief Determine if the temperature and humidity are out of the threshold range + * @return Return the status code, representing as follows + * @n 01 Indicates that the humidity exceeds the lower threshold range + * @n 10 Indicates that the temperature exceeds the lower threshold range + * @n 11 Indicates that both the humidity and the temperature exceed the lower threshold range + * @n 02 Indicates that the humidity exceeds the upper threshold range + * @n 20 Indicates that the temperature exceeds the upper threshold range + * @n 22 Indicates that both the humidity and the temperature exceed the upper threshold range + * @n 12 Indicates that the temperature exceeds the lower threshold range, + //and the humidity exceeds the upper threshold range + * @n 21 Indicates that the temperature exceeds the upper threshold range, + //and the humidity exceeds the lower threshold range + * @n 0 Back to normal, but the alarm is not cleared. + */ + uint8_t state = sht3x.environmentState(); + //Serial.println(F("string") Save stings to flash to save the dynamic ram when compiling. + if(state == 1) Serial.println(F("The humidity exceeds the lower threshold range!")); + else if(state == 10) Serial.println(F("The temperature exceeds the lower threshold range!")); + else if(state == 11) Serial.println(F("The humidity and the temperature exceed the lower threshold range!")); + else if(state == 2) Serial.println(F("The humidity exceeds the upper threshold range!")); + else if(state == 20) Serial.println(F("The temperature exceeds the upper threshold range!")); + else if(state == 22) Serial.println(F("The humidity and the temperature exceed the upper threshold range!")); + else if(state == 12) Serial.println(F("The temperature exceeds the lower threshold range,the humidity exceeds the upper threshold range!")); + else if(state == 21) Serial.println(F("The temperature exceeds the upper threshold range, and the humidity exceeds the lower threshold range!")); + else Serial.println(F("T&H back to normal, but the alarm is not cleared!")); + } else { + Serial.println(F("T&H in normal range, alarm cleared")); + } + delay(1000); +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/periodicDataReading/periodicDataReading.ino b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/periodicDataReading/periodicDataReading.ino new file mode 100644 index 0000000000000000000000000000000000000000..cdf1853b265fc080b8e2b48f81be453aeff8cf2d --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/periodicDataReading/periodicDataReading.ino @@ -0,0 +1,151 @@ +/*! + * @file periodicDataReading.ino + * @brief Read ambient temperature (C/F) and relative humidity (%RH) in cycle read mode. + * @details Experimental phenomenon: Before we start, please set the read frequency and repeatability of the read + * @n (the difference between the data measured by the chip under the same measurement conditions), + * and enter the periodic read mode, and then read the temperature and humidity data. + * @n The temperature and humidity data will be printed at the serial port, after 10 seconds of operation. + * @n It will exit the cycle mode and enter 2 measurement mode: Single measurement mode and Cycle measurement mode. + * @n Single measurement mode: reflect the difference between the two modes of reading data. + * @n Cycle measurement mode: the chip periodically monitors temperature and humidity, only in this mode the ALERT pin will work. + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @License The MIT License (MIT) + * @author [fengli](li.feng@dfrobot.com) + * @version V1.0 + * @date 2019-08-20 + * @url https://github.com/DFRobot/DFRobot_SHT3x +*/ + +#include <DFRobot_SHT3x.h> + +/*! + * @brief Construct the function + * @param pWire IIC bus pointer object and construction device, can both pass or not pass parameters, Wire in default. + * @param address Chip IIC address, two optional addresses 0x44 and 0x45(0x45 in default). + * @param RST Chip reset pin, 4 in default. + * @n The IIC address is determined by the pin addr on the chip. + * @n When the ADR is connected to VDD, the chip IIC address is 0x45. + * @n When the ADR is connected to GND, the chip IIC address is 0x44. + */ +//DFRobot_SHT3x sht3x(&Wire,/*address=*/0x45,/*RST=*/4); + +DFRobot_SHT3x sht3x; + +void setup() { + + Serial.begin(9600); + //Initialize the chip to detect if it can communicate properly. + while (sht3x.begin() != 0) { + Serial.println("Failed to initialize the chip, please confirm the chip connection"); + delay(1000); + } + + /** + * readSerialNumber Read the serial number of the chip + * @return Return 32-digit serial number + */ + Serial.print("chip serial number: "); + Serial.println(sht3x.readSerialNumber()); + /** + * softReset Send command resets via IIC, enter the chip's default mode single-measure mode, + * turn off the heater, and clear the alert of the ALERT pin. + * @return Read the status register to determine whether the command was executed successfully, + * and return true indicates success. + */ + if(!sht3x.softReset()){ + Serial.println("Failed to reset the chip"); + } + + /** + * pinReset Reset through the chip's reset pin, enter the chip's default mode single-measure mode, + * turn off the heater, and clear the alert of the ALERT pin. + * @return The status register has a data bit that detects whether the chip has been reset, + * and return true indicates success. + * @note When using this API, the reset pin of the chip nRESET should be connected to RST (default to pin4) of arduino. + */ + //if(!sht3x.pinReset()){ + //Serial.println("Failed to reset the chip"); + //} + + /** + * heaterEnable() Turn on the heater inside the chip so that the sensor can have accurate humidity data even in humid environment. + * @return Read the status register to determine whether the command was executed successfully, and return true indicates success. + * @NOTE Heaters should be used in wet environment, and other cases of use will result in incorrect readings. + */ + //if(!sht3x.heaterEnable()){ + // Serial.println("Failed to turn on the heater"); + //} + /** + * startPeriodicMode Enter cycle measurement mode and set repeatability and read frequency. + * @param measureFreq Read the eMeasureFrequency_t data frequency. + * @note Selectable parameters: + eMeasureFreq_Hz5, /**the chip collects data in every 2s + eMeasureFreq_1Hz, /**the chip collects data in every 1s + eMeasureFreq_2Hz, /**the chip collects data in every 0.5s + eMeasureFreq_4Hz, /**the chip collects data in every 0.25s + eMeasureFreq_10Hz /**the chip collects data in every 0.1s + * @param repeatability Read the repeatability of temperature and humidity data, the default parameter is eRepeatability_High. + * @note Optional parameters: + eRepeatability_High /**In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C + eRepeatability_Medium,/**In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C. + eRepeatability_Low, /**In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C + * @return Read the status of the register to determine whether the command was executed successfully, and return true indicates success + */ + if(!sht3x.startPeriodicMode(sht3x.eMeasureFreq_1Hz)){ + Serial.println("Failed to enter the periodic mode"); + } + Serial.println("------------------Read data in cycle measurement mode-----------------------"); +} + +void loop() { + + Serial.print("Ambient temperature(°C/F):"); + /** + * getTemperatureC Get the measured temperature (in degrees Celsius). + * @return Return the float temperature data. + */ + Serial.print(sht3x.getTemperatureC()); + Serial.print(" C/"); + /** + * getTemperatureF Get the measured temperature (in degrees Fahrenheit). + * @return Return the float temperature data. + */ + Serial.print(sht3x.getTemperatureF()); + Serial.print(" F "); + Serial.print("Relative humidity(%RH):"); + /** + * getHumidityRH Get measured humidity(%RH) + * @return Return the float humidity data + */ + Serial.print(sht3x.getHumidityRH()); + Serial.println(" %RH"); + //Please adjust the frequency of reading according to the frequency of the chip collection data. + //The frequency to read data must be greater than the frequency to collect the data, otherwise the returned data will go wrong. + delay(100); + if(millis() > 10000 && millis() < 10200){ + /** + * stopPeriodicMode() Exit from the cycle read data + * @return Read the status of the register to determine whether the command was executed successfully, + * and return true indicates success. + */ + sht3x.stopPeriodicMode(); + Serial.println("Exited from the cycle measurement mode, enter the single measurement mode"); + } + /** + * readTemperatureAndHumidity Get temperature and humidity data in cycle measurement mode and use structures to receive data + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code. + * @n A status of 0 indicates that the right return data. + + DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(); + if(data.ERR == 0){ + Serial.print("ambient temperature(°C/F):"); + Serial.print(data.TemperatureC); + Serial.print("C/"); + Serial.print(data.TemperatureF); + Serial.print("F"); + Serial.print("relative humidity(%RH):"); + Serial.print(data.Humidity); + Serial.println("%RH"); + } + */ +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/singleMeasurement/singleMeasurement.ino b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/singleMeasurement/singleMeasurement.ino new file mode 100644 index 0000000000000000000000000000000000000000..3bfff6c92f2a863ad39cbc824fe96f99f3b9a92c --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/examples/singleMeasurement/singleMeasurement.ino @@ -0,0 +1,197 @@ + +/*! + * @file singleMeasurement.ino + * @brief Read ambient temperature (C/F) and relative humidity (%RH) in single-read mode. + * @details n Experimental phenomenon: the chip defaults in this mode, we need to send instructions to enable the chip collect data, + * which means the repeatability of the read needs to be set (the difference between the data measured by the chip under the same measurement conditions) + * then read the temperature and humidity data and print the data in the serial port. + * @n Single measure mode: read data as needed, power consumption is relatively low, the chip idle state only costs 0.5mA. + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @License The MIT License (MIT) + * @author [fengli](li.feng@dfrobot.com) + * @version V1.0 + * @date 2019-08-21 + * @url https://github.com/DFRobot/DFRobot_SHT3x +*/ + + +#include <DFRobot_SHT3x.h> + + +/*! + + * @brief Construct the function + + * @param pWire IIC bus pointer object and construction device, both can pass or not pass parameters, + * Wire in default. + + * @param address Chip IIC address, two optional addresses 0x44 and 0x45(0x45 in default). + + * @param RST RST Chip reset pin, 4 in default. + + * @n IIC address is determined by the pin addr on the chip. + + * @n When the ADR is connected to VDD, the chip IIC address is 0x45. + + * @n When the ADR is connected to GND, the chip IIC address is 0x44. + + */ + +//DFRobot_SHT3x sht3x(&Wire,/*address=*/0x45,/*RST=*/4); + + + +DFRobot_SHT3x sht3x; + + + +void setup() { + + Serial.begin(9600); + + //Initialize the chip + + while (sht3x.begin() != 0) { + + Serial.println("Failed to Initialize the chip, please confirm the wire connection"); + + delay(1000); + + } + + /** + + * readSerialNumber Read the serial number of the chip. + + * @return Return 32-digit serial number. + + */ + + Serial.print("Chip serial number"); + + Serial.println(sht3x.readSerialNumber()); + + + + /** + + * softReset Send command resets via IIC, enter the chip's default mode single-measure mode, + * turn off the heater, and clear the alert of the ALERT pin. + + * @return Read the register status to determine whether the command was executed successfully, + * and return true indicates success. + + */ + + if(!sht3x.softReset()){ + + Serial.println("Failed to Initialize the chip...."); + + } + + + + /** + + * heaterEnable(): Turn on the heater inside the chip to enable the sensor get correct humidity value in wet environments. + + * @return Read the status of the register to determine whether the command was executed successfully, + * and return true indicates success. + + * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + */ + + //if(!sht3x.heaterEnable()){ + + // Serial.println("Failed to turn on the heater...."); + + //} + + Serial.println("------------------Read adta in single measurement mode-----------------------"); + +} + + + +void loop() { + + + + Serial.print("Ambient Temperature(°C/F):"); + + /** + + * getTemperatureC Get the meansured temperature(℃). + + * @return Return float temperature data. + + */ + + Serial.print(sht3x.getTemperatureC()); + + Serial.print(" C/"); + + /** + + * getTemperatureF:Get the meansured temperature(℉). + + * @return Return float temperature data. + */ + + Serial.print(sht3x.getTemperatureF()); + + Serial.print(" F "); + + Serial.print("Relative Humidity(%RH):"); + + /** + + * getHumidityRH: Get the meansured humidity (%RH) + + * @return Return float humidity data + + */ + + Serial.print(sht3x.getHumidityRH()); + + Serial.println(" %RH"); + + + + /** + * @brief Get temperature and humidity data in single measurement mode. + * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t. + * @note Optional parameters: + eRepeatability_High /In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C + eRepeatability_Medium,/In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C. + eRepeatability_Low, /In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C + * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity(%RH), status code. + * @n Return O indicates right data return. + + DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(sht3x.eRepeatability_High); + + if(data.ERR == 0){ + + Serial.print("Ambient Temperature(°C/F):"); + + Serial.print(data.TemperatureC); + + Serial.print(" C/"); + + Serial.print(data.TemperatureF); + + Serial.print(" F "); + + Serial.print("Relative Humidity(%RH):"); + + Serial.print(data.Humidity); + + Serial.println(" %RH"); + + } + + */ + + delay(1000); + +} \ No newline at end of file diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/keywords.txt b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/keywords.txt new file mode 100644 index 0000000000000000000000000000000000000000..94ce56ad7980999fc86a3ce884d108d2e14059ab --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/keywords.txt @@ -0,0 +1,65 @@ +####################################### +# Syntax Coloring Map For DFRobot_SHT3x +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +DFRobot_SHT3x KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +softReset KEYWORD2 +pinReset KEYWORD2 +readTemperatureAndHumidity KEYWORD2 +startPeriodicMode KEYWORD2 +readSerialNumber KEYWORD2 +stopPeriodicMode KEYWORD2 +heaterEnable KEYWORD2 +heaterDisable KEYWORD2 +clearStatusRegister KEYWORD2 +setTemperatureLimitC KEYWORD2 +setTemperatureLimitF KEYWORD2 +setHumidityLimitRH KEYWORD2 +measureTemperatureLimitC KEYWORD2 +measureTemperatureLimitF KEYWORD2 +measureHumidityLimitRH KEYWORD2 +slimitData_t KEYWORD2 +sRHAndTemp_t KEYWORD2 +highSet KEYWORD2 +highClear KEYWORD2 +lowClear KEYWORD2 +lowSet KEYWORD2 +getTemperatureF KEYWORD2 +getTemperatureC KEYWORD2 +getHumidityRH KEYWORD2 +getTemperatureHighSetC KEYWORD2 +getTemperatureHighClearC KEYWORD2 +getTemperatureLowClearC KEYWORD2 +getTemperatureLowSetC KEYWORD2 +getTemperatureHighSetF KEYWORD2 +getTemperatureHighClearF KEYWORD2 +getTemperatureLowClearF KEYWORD2 +getTemperatureLowSetF KEYWORD2 +getHumidityHighSetRH KEYWORD2 +getHumidityHighClearRH KEYWORD2 +getHumidityLowClearRH KEYWORD2 +getHumidityLowSetRH KEYWORD2 +ERR KEYWORD2 +environmentState KEYWORD2 +readAlertState KEYWORD2 +####################################### +# Constants (LITERAL1) +####################################### +eRepeatability_High LITERAL1 +eRepeatability_Medium LITERAL1 +eRepeatability_Low LITERAL1 +eMeasureFreq_Hz5 LITERAL1 +eMeasureFreq_1Hz LITERAL1 +eMeasureFreq_2Hz LITERAL1 +eMeasureFreq_10Hz LITERAL1 +eMeasureFreq_4Hz LITERAL1 diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/library.properties b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/library.properties new file mode 100644 index 0000000000000000000000000000000000000000..f57bf883f70192d21203833392138fa679a90c9c --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/library.properties @@ -0,0 +1,9 @@ +name=DFRobot_SHT3x +version=1.0.0 +author=DFRobot +maintainer=fengli <li.feng@dfrobot.com> +sentence=Sht3x series T/H sensor(SKU: SEN0330,SEN0331,SEN0332,SEN0333,SEN0334). +paragraph = his is a library of digital temperature and humidity sensors used to drive the SHT3x series SHT30, SHT31 and SHT35 to read ambient temperature and relative humidity. +category=Sensors +url=https://github.com/DFRobot/DFRobot_SHT3x +architectures=* diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/DFRobot_SHT3X.py b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/DFRobot_SHT3X.py new file mode 100644 index 0000000000000000000000000000000000000000..735ac816880cc010288183a9a9979cca35ec8c23 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/DFRobot_SHT3X.py @@ -0,0 +1,912 @@ +# -*- coding:utf-8 -*- +'''! + @file DFRobot_SHT3X.py + @brief Define the infrastructure of the DFRobot_SHT3x class + @n This is a library of digital temperature and humidity sensors used to drive the SHT3x series SHT30, + SHT31 and SHT35 to read ambient temperature and relative humidity. + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @License The MIT License (MIT) + @author [yangfeng]<feng.yang@dfrobot.com> + version V1.0 + date 2021-06-11 + @url https://github.com/DFRobot/DFRobot_SHT3x +''' + +import sys +import smbus +import logging +import numpy as np +from ctypes import * +import spidev +import time +import RPi.GPIO as GPIO + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) + +logger = logging.getLogger() +logger.setLevel(logging.INFO) #显示所有的打印信息 +#logger.setLevel(logging.FATAL)#如果不想显示过多打印,只打印错误,请使用这个选项 +ph = logging.StreamHandler() +formatter = logging.Formatter("%(asctime)s - [%(filename)s %(funcName)s]:%(lineno)d - %(levelname)s: %(message)s") +ph.setFormatter(formatter) +logger.addHandler(ph) + +SHT3X_CMD_READ_SERIAL_NUMBER = 0x3780 +SHT3X_CMD_GETDATA_H = 0x2400 +SHT3X_CMD_GETDATA_M = 0x240B +SHT3X_CMD_GETDATA_L = 0x2416 +SHT3X_CMD_SETMODE_H_FREQUENCY_HALF_HZ = 0x2032 +SHT3X_CMD_SETMODE_M_FREQUENCY_HALF_HZ = 0x2024 +SHT3X_CMD_SETMODE_L_FREQUENCY_HALF_HZ = 0x202F +SHT3X_CMD_SETMODE_H_FREQUENCY_1_HZ = 0x2130 +SHT3X_CMD_SETMODE_M_FREQUENCY_1_HZ = 0x2126 +SHT3X_CMD_SETMODE_L_FREQUENCY_1_HZ = 0x212D +SHT3X_CMD_SETMODE_H_FREQUENCY_2_HZ = 0x2236 +SHT3X_CMD_SETMODE_M_FREQUENCY_2_HZ = 0x2220 +SHT3X_CMD_SETMODE_L_FREQUENCY_2_HZ = 0x222B +SHT3X_CMD_SETMODE_H_FREQUENCY_4_HZ = 0x2334 +SHT3X_CMD_SETMODE_M_FREQUENCY_4_HZ = 0x2322 +SHT3X_CMD_SETMODE_L_FREQUENCY_4_HZ = 0x2329 +SHT3X_CMD_SETMODE_H_FREQUENCY_10_HZ = 0x2737 +SHT3X_CMD_SETMODE_M_FREQUENCY_10_HZ = 0x2721 +SHT3X_CMD_SETMODE_L_FREQUENCY_10_HZ = 0x272A +SHT3X_CMD_GETDATA = 0xE000 + +SHT3X_CMD_STOP_PERIODIC_ACQUISITION_MODE = 0x3093 +SHT3X_CMD_SOFT_RESET = 0x30A2 +SHT3X_CMD_HEATER_ENABLE = 0x306D +SHT3X_CMD_HEATER_DISABLE = 0x3066 +SHT3X_CMD_READ_STATUS_REG = 0xF32D +SHT3X_CMD_CLEAR_STATUS_REG = 0x3041 + +SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET = 0xE11F +SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR = 0xE114 +SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR = 0xE109 +SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET = 0xE102 +SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET = 0x611D +SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR = 0x6116 +SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR = 0x610B +SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET = 0x6100 + +TEMP_RH_TEMP_C = 0 +TEMP_RH_HUM = 1 +TEMP_RH_TEMP_F = 2 +TEMP_RH_ERR = 3 + +HIGH_SET = 0 +HIGH_CLEAR = 1 +LOW_SET = 2 +LOW_CLEAR = 3 + +class DFRobot_SHT3x: + + ERR_OK = 0 #无错误 + ERR_DATA_BUS = -1 #数据总线错误 + ERR_IC_VERSION = -2 #芯片版本不匹配 + + Periodic = 0 #<Cycle measurement mode + One_Shot =1, #<Single measurement mode + + repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + repeatability_periodic = 3 + measureFreq_0_5Hz = 0 + measureFreq_1Hz = 1 + measureFreq_2Hz = 2 + measureFreq_4Hz = 3 + measureFreq_10Hz = 4 + + def __init__(self, iic_addr = 0x45,bus = 1): + self.i2cbus=smbus.SMBus(bus) + self.i2c_addr = iic_addr + self.tempRH= [0,0,0,0] + self.limit_Data = [0,0,0,0] + self._measure_freq = 0 + + + def begin(self,RST = 4): + '''! + @brief Initialize the function + @return Return 0 indicates a successful initialization, while other values indicates failure and return to error code. + ''' + self._RST = RST + self.measurement_mode = self.One_Shot + GPIO.setup(self._RST, GPIO.OUT) + GPIO.output(self._RST, GPIO.HIGH) + if(self.read_serial_number() == 0): + logger.warning("bus data access error") + return self.ERR_DATA_BUS + return self.ERR_OK + + def read_serial_number(self): + '''! + @brief Read the serial number of the chip + @return 32-digit serial number + ''' + result = 0 + self.__write_reg(SHT3X_CMD_READ_SERIAL_NUMBER>>8,SHT3X_CMD_READ_SERIAL_NUMBER&0xFF) + time.sleep(0.001) + data0 = self.__read_reg(6) + data1= [data0[0],data0[1],data0[2]] + data2= [data0[3],data0[4],data0[5]] + if((self.__check_crc(data1) == data0[2]) and (self.__check_crc(data2) == data0[5])): + result = data0[0] + result = (result << 8) | data0[1] + result = (result << 8) | data0[3] + result = (result << 8) | data0[4] + return result + + + def soft_reset(self): + '''! + @brief Send command resets via iiC, enter the chip's default mode single-measure mode, + turn off the heater, and clear the alert of the ALERT pin. + @return Read the status register to determine whether the command was executed successfully, and returning true indicates success + ''' + self.__write_reg(SHT3X_CMD_SOFT_RESET>>8,SHT3X_CMD_SOFT_RESET&0xFF) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x02) == 0): + return True + else: + return False + + + def pin_reset(self): + '''! + @brief Reset through the chip's reset pin, enter the chip's default mode single-measure mode, and clear the alert of the ALERT pin. + @return The status register has a data bit that detects whether the chip has been reset, and returning true indicates success + ''' + self.clear_status_register() + GPIO.output(self._RST, GPIO.LOW) + time.sleep(0.001) + GPIO.output(self._RST, GPIO.HIGH) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x10) == 1): + return True + else: + return False + + + def stop_periodic_mode(self): + '''! + @brief Exit from cycle measurement mode + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + ''' + self.measurement_mode = self.One_Shot + self.__write_reg(SHT3X_CMD_STOP_PERIODIC_ACQUISITION_MODE>>8,SHT3X_CMD_STOP_PERIODIC_ACQUISITION_MODE&0xFF) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x02) == 0): + return True + else: + return False + + + def heater_enable(self): + '''! + @brief Turn on the heater inside the chip + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + ''' + self.__write_reg(SHT3X_CMD_HEATER_ENABLE>>8,SHT3X_CMD_HEATER_ENABLE&0xFF) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x2000) == 1): + return True + else: + return False + + + + def heater_disable(self): + '''! + @brief Turn off the heater inside the chip + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + ''' + self.__write_reg(SHT3X_CMD_HEATER_DISABLE>>8,SHT3X_CMD_HEATER_DISABLE&0xFF) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x2000) == 0): + return True + else: + return False + + + def clear_status_register(self): + '''! + @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + @n Set bit:15 to 0 so that ALERT pin can work, otherwise it will keep high. + ''' + self.__write_reg(SHT3X_CMD_CLEAR_STATUS_REG>>8,SHT3X_CMD_CLEAR_STATUS_REG&0xFF) + time.sleep(0.01) + + + def read_alert_state(self): + '''! + @brief Read the state of the pin ALERT. + @return High returns 1, low returns 0. + ''' + time.sleep(0.001) + register_raw = self.__read_status_register() + if(((register_raw & 0x0800) == 1)or((register_raw & 0x0400) == 1)): + return True + else: + return False + + + def read_temperature_and_humidity(self,repeatability = repeatability_periodic): + '''! + @brief Get temperature and humidity data in single measurement mode. + @param repeatability: The mode of reading data + @n repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + @n repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + @n repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + @n repeatability_periodic = 3 Periodic reading of data + @return Return a list containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + @n A status of 0 indicates the right return data. + ''' + self.tempRH[TEMP_RH_ERR] = 0 + if (repeatability == self.repeatability_high): + self.__write_reg(SHT3X_CMD_GETDATA_H>>8,SHT3X_CMD_GETDATA_H&0xFF) + time.sleep(0.015) + elif(repeatability == self.repeatability_medium): + self.__write_reg(SHT3X_CMD_GETDATA_M>>8,SHT3X_CMD_GETDATA_M&0xFF) + time.sleep(0.015) + elif(repeatability == self.repeatability_low): + self.__write_reg(SHT3X_CMD_GETDATA_L>>8,SHT3X_CMD_GETDATA_L&0xFF) + time.sleep(0.015) + elif(repeatability == self.repeatability_periodic): + self.__write_reg(SHT3X_CMD_GETDATA>>8,SHT3X_CMD_GETDATA&0xFF) + time.sleep(0.015) + data0 = self.__read_reg(6) + data1= [data0[0],data0[1],data0[2]] + data2= [data0[3],data0[4],data0[5]] + if((self.__check_crc(data1) != data0[2]) or (self.__check_crc(data2) != data0[5])): + self.tempRH[TEMP_RH_ERR] = -1 + return self.tempRH + self.tempRH[TEMP_RH_TEMP_C] = self.__convert_temperature(data1) + self.tempRH[TEMP_RH_TEMP_F] = (9.0/5)*self.tempRH[TEMP_RH_TEMP_C] + 32 + self.tempRH[TEMP_RH_HUM] = self.__convert_humidity(data2) + return self.tempRH + + + def get_temperature_C(self): + '''! + @brief Get the measured temperature (in degrees Celsius) + @return Return the float temperature data + ''' + if(self.measurement_mode == self.One_Shot): + self.read_temperature_and_humidity(self.repeatability_high) + else: + self.read_temperature_and_humidity() + return self.tempRH[TEMP_RH_TEMP_C] + + + def get_temperature_F(self): + '''! + @brief Get the measured temperature (in degrees Fahrenheit) + @return Return the float temperature data + ''' + if(self.measurement_mode == self.One_Shot): + self.read_temperature_and_humidity(self.repeatability_high) + else: + self.read_temperature_and_humidity() + return self.tempRH[TEMP_RH_TEMP_F] + + + def get_humidity_RH(self): + '''! + @brief Get measured humidity(%RH) + @return Return the float humidity data + ''' + if(self.measurement_mode == self.One_Shot): + self.read_temperature_and_humidity(self.repeatability_high) + else: + self.read_temperature_and_humidity() + return self.tempRH[TEMP_RH_HUM] + + + def start_periodic_mode(self,measure_freq,repeatability = repeatability_high): + '''! + @brief Enter cycle measurement mode and set repeatability(the difference between the data measured + the difference between the data measured by the chip under the same measurement conditions) + @param measure_freq Read the data frequency + @n measureFreq_0_5Hz = 0 + @n measureFreq_1Hz = 1 + @n measureFreq_2Hz = 2 + @n measureFreq_4Hz = 3 + @n measureFreq_10Hz = 4 + @param repeatability The mode of reading data,repeatability_high in default. + @n repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + @n repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + @n repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + @return Return true indicates a successful entrance to cycle measurement mode. + ''' + cmd=[[SHT3X_CMD_SETMODE_H_FREQUENCY_HALF_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_HALF_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_HALF_HZ],\ + [SHT3X_CMD_SETMODE_H_FREQUENCY_1_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_1_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_1_HZ],\ + [SHT3X_CMD_SETMODE_H_FREQUENCY_2_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_2_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_2_HZ],\ + [SHT3X_CMD_SETMODE_H_FREQUENCY_4_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_4_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_4_HZ],\ + [SHT3X_CMD_SETMODE_H_FREQUENCY_10_HZ,SHT3X_CMD_SETMODE_M_FREQUENCY_10_HZ,SHT3X_CMD_SETMODE_L_FREQUENCY_10_HZ]\ + ] + self.measurement_mode = self.Periodic + self._measure_freq = measure_freq + self.__write_reg(cmd[measure_freq][repeatability]>>8,cmd[measure_freq][repeatability]&0xFF) + time.sleep(0.001) + register_raw = self.__read_status_register() + if((register_raw & 0x02) == 0): + return True + else: + return False + + def __read_status_register(self): + '''! + @brief Read the data stored in the status register. + @return Return to status like whether heater is ON or OFF, the status of the pin alert, reset status and the former cmd is executed or not. + ''' + for i in range(0,10): + self.__write_reg(SHT3X_CMD_READ_STATUS_REG>>8,SHT3X_CMD_READ_STATUS_REG&0xFF) + time.sleep(0.001) + register1 = self.__read_reg(3) + if(self.__check_crc(register1) == register1[2]): + break + data = (register1[0]<<8) | register1[1] + return data + + + def environment_state(self): + '''! + @brief Determine if the temperature and humidity are out of the threshold range + @return Return the status code, representing as follows + @n 01 :Indicates that the humidity exceeds the lower threshold range + @n 10 :Indicates that the temperature exceeds the lower threshold range + @n 11 :Indicates that both the humidity and the temperature exceed the lower threshold range + @n 02 :Indicates that the humidity exceeds the upper threshold range + @n 20 :Indicates that the temperature exceeds the upper threshold range + @n 22 :Indicates that both the humidity and the temperature exceed the upper threshold range + @n 12 :Indicates that the temperature exceeds the lower threshold range, + and the humidity exceeds the upper threshold range + @n 21 :Indicates that the temperature exceeds the upper threshold range, + and the humidity exceeds the lower threshold range + ''' + ret = 0 + registerRaw = self.__read_status_register() + data = self.read_temperature_and_humidity() + if(self.measure_temperature_limit_C()): + temp_high_set = self.get_temperature_high_set_C() + temp_low_set = self.get_temperature_low_set_C() + if(self.measure_humidity_limit_RH()): + rh_high_set = self.get_humidity_high_set_RH() + rh_low_set = self.get_humidity_low_set_RH() + if(((registerRaw & 0x0800) == 1) and ((registerRaw & 0x0400) == 0)): + if(data[TEMP_RH_HUM]>rh_high_set): + ret = 2 + elif(data[TEMP_RH_HUM]<rh_low_set): + ret = 1 + elif((((registerRaw & 0x0800) == 0) and ((registerRaw & 0x0400) == 1))): + if(data[TEMP_RH_TEMP_C]>temp_high_set): + ret = 20 + elif(data[TEMP_RH_TEMP_C]<temp_low_set): + return 10 + elif((((registerRaw & 0x0800) == 1) and ((registerRaw & 0x0400) == 1))): + if((data[TEMP_RH_TEMP_C]<temp_low_set) and (data[TEMP_RH_HUM]<rh_low_set)): + ret = 11 + elif((data[TEMP_RH_TEMP_C]>temp_high_set) and (data[TEMP_RH_HUM]>rh_high_set)): + ret = 22 + elif((data[TEMP_RH_TEMP_C]>temp_high_set) and (data[TEMP_RH_HUM]<rh_low_set)): + ret = 21 + elif((data[TEMP_RH_TEMP_C]<temp_low_set) and (data[TEMP_RH_HUM]>rh_high_set)): + ret = 12 + return ret + + + + def set_temperature_limit_C(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the threshold temperature and alarm clear temperature(°C) + @param highset: High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + @param highClear: High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + @param lowset: Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear: Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + @note range: -40 to 125 degrees Celsius, highset > highClear > lowclear > lowset. + @return: A return to 0 indicates a successful setting. + ''' + ret =0 + if((high_set > high_clear) and (high_clear > low_clear) and (low_clear > low_set)): + + _high_set = self.__convert_raw_temperature(high_set) + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _high_set = (_high_set >> 7) | (limit & 0xfe00) + self.__write_limit_data(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET,_high_set) + + _high_clear= self.__convert_raw_temperature(high_clear) + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _high_clear = (_high_clear >> 7) | (limit & 0xfe00) + self.__write_limit_data(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR,_high_clear) + + _low_clear= self.__convert_raw_temperature(low_clear) + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _low_clear = (_low_clear >> 7) | (limit & 0xfe00) + self.__write_limit_data(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR,_low_clear) + + _low_set= self.__convert_raw_temperature(low_set) + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _low_set = (_low_set >> 7) | (limit & 0xfe00) + self.__write_limit_data(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET,_low_set) + else : + ret =1 + return ret + + + def set_temperature_limit_F(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the threshold temperature and alarm clear temperature(°F) + @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + @note Range -40 to 257 (Fahrenheit), highset > highClear > lowclear > lowset. + @return A return to 0 indicates a successful setting. + ''' + _high_set = (high_set - 32) * 5.0 / 9.0 + _high_clear = (high_clear - 32) * 5.0 / 9.0 + _low_clear = (low_clear - 32) * 5.0 / 9.0 + _low_set = (low_set - 32) * 5.0 / 9.0 + ret =1 + if(self.set_temperature_limit_C(_high_set,_high_clear,_low_set,_low_clear) == 0): + ret = 0 + return ret + + + def set_humidity_limit_RH(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the relative humidity threshold temperature and the alarm clear humidity(%RH) + @param highset High humidity alarm point, when the humidity is greater than this value, the ALERT pin generates an alarm signal. + @param highClear High humidity alarm clear point, alarming when the humidity higher than the highset, otherwise the alarm signal will be cleared. + @param lowset Low humidity alarm point, when the humidity is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear Low humidity alarm clear point, alarming when the humidity lower than the highset, otherwise the alarm signal will be cleared. + @note range 0 - 100 %RH, highset > highClear > lowclear > lowset + @return A return to 0 indicates a successful setting. + ''' + limit = 0 + if((high_set > high_clear) and (high_clear > low_clear) and (low_clear > low_set)): + + _high_set = self.__convert_raw_humidity(high_set) + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _high_set = (_high_set & 0xfe00) | (limit & 0x1FF) + self.__write_limit_data(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_SET,_high_set) + + _high_clear= self.__convert_raw_humidity(high_clear) + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _high_clear = (_high_clear & 0xfe00) | (limit & 0x1FF) + self.__write_limit_data(SHT3X_CMD_WRITE_HIGH_ALERT_LIMIT_CLEAR,_high_clear) + + _low_clear= self.__convert_raw_humidity(low_clear) + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _low_clear = (_low_clear & 0xfe00) | (limit & 0x1FF) + self.__write_limit_data(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_CLEAR,_low_clear) + + _low_set= self.__convert_raw_humidity(low_set) + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return 1 + limit = buf[0] + limit = limit<< 8 | buf[1] + _low_set = (_low_set & 0xfe00) | (limit & 0x1FF) + self.__write_limit_data(SHT3X_CMD_WRITE_LOW_ALERT_LIMIT_SET,_low_set) + else : + return 1 + return 0 + + + def measure_temperature_limit_C(self): + '''! + @brief Measure temperature threshold temperature and alarm clear temperature + @return Return true indicates successful data acquisition + ''' + limit = 0 + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[HIGH_SET] = round(data,2) + + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[HIGH_CLEAR] = round(data,2) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[LOW_CLEAR] = round(data,2) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[LOW_SET] = round(data,2) + return True + + + def measure_temperature_limit_F(self): + '''! + @brief Measure the threshold temperature and alarm clear temperature + @return Return true indicates successful data acquisition + ''' + limit = 0 + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[HIGH_SET] = round((data * 9 / 5.0 + 32),2) + + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[HIGH_CLEAR] = round(d(data * 9 / 5.0 + 32),2) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[LOW_CLEAR] = round((data * 9 / 5.0 + 32),2) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + data = self.__convert_temp_limit_data(limit) + self.limit_Data[LOW_SET] = round((data * 9 / 5.0 + 32),2) + return True + + + def measure_humidity_limit_RH(self): + '''! + @brief Measure the threshold humidity of relative humidity and alarm clear humidity + @return Return true indicates successful data acquisition + ''' + limit = 0 + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + self.limit_Data[HIGH_SET] = self.__convert_humidity_limit_data(limit) + + self.__write_reg(SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_HIGH_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + self.limit_Data[HIGH_CLEAR] = self.__convert_humidity_limit_data(limit) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_CLEAR&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + self.limit_Data[LOW_CLEAR] = self.__convert_humidity_limit_data(limit) + + self.__write_reg(SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET>>8,SHT3X_CMD_READ_LOW_ALERT_LIMIT_SET&0xFF) + time.sleep(0.001) + buf = self.__read_reg(3) + if(self.__check_crc(buf)!= buf[2]): + return False + limit = buf[0] + limit = limit<< 8 | buf[1] + self.limit_Data[LOW_SET] = self.__convert_humidity_limit_data(limit) + return True + + + def get_temperature_high_set_F(self): + '''! + @brief Get high temperature alarm points(°F) + @return Return high temperature alarm points(°F) + ''' + return self.limit_Data[HIGH_SET] + + + def get_temperature_high_clear_F(self): + '''! + @brief Get high temperature alarm clear points(°F) + @return Return high temperature alarm clear points(°F)) + ''' + return self.limit_Data[HIGH_CLEAR] + + + def get_temperature_low_clear_F(self): + '''! + @brief Get low temperature alarm clear points(°F) + @return Return low temperature alarm clear points(°F) + ''' + return self.limit_Data[LOW_CLEAR] + + + def get_temperature_low_set_F(self): + '''! + @brief Get low temperature alarm points(°F) + @return Return low temperature alarm points + ''' + return self.limit_Data[LOW_SET] + + + def get_temperature_high_set_C(self): + '''! + @brief Get high temperature alarm points(°C) + @return Return high temperature alarm points(°C) + ''' + return self.limit_Data[HIGH_SET] + + + def get_temperature_high_clear_C(self): + '''! + @brief Get high temperature alarm clear points(°C) + @return Return high temperature alarm clear points(°C) + ''' + return self.limit_Data[HIGH_CLEAR] + + + def get_temperature_low_clear_C(self): + '''! + @brief Get low temperature alarm clear points(°C) + @return Return low temperature alarm clear points(°C) + ''' + return self.limit_Data[LOW_CLEAR] + + + def get_temperature_low_set_C(self): + '''! + @brief Get low temperature alarm points(°C) + @return Return low temperature alarm points + ''' + return self.limit_Data[LOW_SET] + + + def get_humidity_high_set_RH(self): + '''! + @brief Get the high humidity alarm point(%RH) + @return Return the high humidity alarm point + ''' + return self.limit_Data[HIGH_SET] + + + def get_humidity_high_clear_RH(self): + '''! + @brief Get the high humidity alarm clear point(%RH) + @return Return the high humidity alarm clear point + ''' + return self.limit_Data[HIGH_CLEAR] + + + def get_humidity_low_clear_RH(self): + '''! + @brief Get the low humidity alarm clear point(%RH) + @return Return the low humidity alarm clear point + ''' + return self.limit_Data[LOW_CLEAR] + + + def get_humidity_low_set_RH(self): + '''! + @brief Get the low humidity alarm point + @return Return the low humidity alarm point + ''' + return self.limit_Data[LOW_SET] + + + def __convert_temperature(self,raw_temperature): + '''! + @brief Convert the data returned from the sensor to temperature(°C). + @param raw_temperature Data obtained from the sensor + @return Celsius temperature. + ''' + raw_value = raw_temperature[0] + raw_value = (raw_value << 8) | raw_temperature[1] + return 175.0 * raw_value / 65535 - 45 + + + def __convert_humidity(self,raw_humidity): + '''! + @brief Convert the data returned from the sensor to relative humidity. + @param raw_humidity Data obtained from the sensor. + @return Relative humidity. + ''' + raw_value = raw_humidity[0] + raw_value = (raw_value << 8) | raw_humidity[1] + return 100.0 * raw_value / 65535 + + + def __convert_raw_temperature(self,value): + '''! + @brief The temperature data to be written is converted into the data needed by the chip. + @param value The temperature need to be written. + @return Data write to sensor. + ''' + return np.uint16((value + 45) / 175 * 65535) + + + def __convert_raw_humidity(self,value): + '''! + @brief The relative humidity data to be written is converted into the data needed by the chip. + @param value The relative humidity data to be written + @return Data write to sensor. + ''' + return np.uint16(value / 100 * 65535) + + + def __convert_temp_limit_data(self,limit): + '''! + @brief Convert the data returned from the sensor to temperature limited data + @param limit Temperature limited data from sensor + @return Temperature limited data + ''' + limit = limit << 7 + limit = limit & 0xFF80 + limit = limit | 0x1A + return 175.0 * limit / 65535 - 45 + + + def __convert_humidity_limit_data(self,limit): + '''! + @brief Convert the data returned from the sensor to humidity limited data + @param limit Humidity limited data from sensor + @return Humidity limited data + ''' + limit = limit & 0xFE00 + limit = limit | 0xCD + return round((100.0 * limit / 65535),2) + + + def __check_crc(self,data): + '''! + * @brief CRC calibration. + * @param data Checksum data list + * @return Obtained calibration code. + ''' + crc = 0xFF + for i in range(0,2): + crc = crc^data[i] + for bit in range(0,8): + if(crc&0x80): + crc = ((crc <<1)^0x31) + else: + crc = (crc<<1) + crc = crc&0xFF + return crc + + + def __write_limit_data(self,cmd,limit_data): + '''! + @brief Write threshold data. + @param cmd Send threshold data of chip command. + @param limitData Raw data on temperature and humidity need to be sent (humidity is 7 bits and temperatures are 11 bits). + @return Return 0 indicates that the command was sent successfully, other return values suggest unsuccessful send. + ''' + reg = cmd >> 8 + command = [0,0,0,0] + command[0] = int(cmd & 0xFF) + command[1]= int(limit_data >> 8) + command[2] = int(limit_data & 0xFF) + buf=[command[1],command[2]] + command[3] = int(self.__check_crc(buf)) + self.i2cbus.write_i2c_block_data(self.i2c_addr, reg, command) + + + def __write_reg(self, reg, value): + '''! + @brief 向寄存器中写入数据 + @param reg 寄存器地址 + @param value 写入的数据 + ''' + self.i2cbus.write_byte_data(self.i2c_addr, reg, value) + + + def __read_reg(self, len): + '''! + @brief 从寄存器中读取数据 + @param reg 寄存器地址 + @return 读取的数据,list格式 + ''' + rslt = self.i2cbus.read_i2c_block_data(self.i2c_addr,0x00,len) + if(self.measurement_mode == self.Periodic): + if(self._measure_freq == self.measureFreq_0_5Hz): + time.sleep(2) + elif(self._measure_freq == self.measureFreq_1Hz): + time.sleep(1) + elif(self._measure_freq == self.measureFreq_2Hz): + time.sleep(0.5) + elif(self._measure_freq == self.measureFreq_4Hz): + time.sleep(0.25) + elif(self._measure_freq == self.measureFreq_10Hz): + time.sleep(0.1) + return rslt + diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README.md b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b531c06e6744b1525752b46b5f204cefa6bac20f --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README.md @@ -0,0 +1,348 @@ +# DFRobot_SHT3x +- [中文版](./README_CN.md) + +The SHT3x series chips are used to measure ambient temperature and relative humidity (the degree of moisture in the air, which indicates the degree to which the moisture content in the atmosphere is saturated from the atmosphere). +It is a successor to the SHT2x series that contain the low-cost version of the SHT30, the standard version of SHT31, and the professional version of SHT35. +The SHT3x series temperature and humidity sensors adopt IIC communication which is easy to use, with a wide operating voltage range (2.15 to 5.5 V), and a space area of the chip package is 2.5 x 2.5 mm2 and 0.9 mm high, which can help SHT3x be easily integrated into a wide range of applications for a wide range of scenarios. +Based on brand-new optimized CMOSens® chip, SHT3x further improved its product reliability and accuracy specifications. +SHT3x offers a range of new features, e.g. enhanced signal processing, two unique user-selectable I2C addresses, an alarm mode with programmable temperature and humidity limits, and communication speeds up to 1 MHz. + +You can choose to open or not open the heater +Heater Function +①By comparing the relative humidity and temperature values measured before and after heating, it is possible to determine whether the sensor is working properly. +②Using heaters in wet environments can avoid sensor condensation. +③A heater can also measure the dew point temperature (the temperature at which water vapor in the air turns into dewdrops). +The SHT3x chip offers two modes of operation: +1.Single measurement mode with an idle state current of 0.2 mA and low power consumption (measurement data is 600 mA). +2.Cycle measurement mode, where the idle state current is 45 mA, and in this mode ALERT starts to work(measurement data is 600 mA) +The following is the typical measurement accuracy of the chip (followed by this temperature and humidity range): + +| Version No. | Typical Temp Precision (°C) | Typical Humidity Precision(%RH) | Range(Temp/Humidity) | +| ----------- | :-------------------------: | :-----------------------------: | :------------------- | +| SHT30 | ±0.2 @0-65 °C | ±2 @10-90% RH | -40-125 °C/0-100 %RH | +| SHT31 | ±0.2 @0-90 °C | ±2 @0-100% RH | -40-125 °C/0-100 %RH | +| SHT35 | ±0.1 @20-60°C | ±1.5 @0-80% RH | -40-125 °C/0-100 %RH | + + + + + + + +## Product Link(https://www.dfrobot.com/product-2016.html) + + SEN0330:Fermion: SHT30 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0331:Fermion: SHT31 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0332:Fermion: SHT31-F Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0333:Fermion: SHT35 Digital Temperature & Humidity Sensor (Breakout)<br> + SEN0334:Gravity: SHT31-F Digital Temperature and Humidity Sensor<br> +## Table of Contents + +* [Summary](#summary) +* [Installation](#installation) +* [Methods](#methods) +* [Compatibility](#compatibility) +* [History](#history) +* [Credits](#credits) + +## Summary + + 1.Read repeatability of the temperature and humidity data in single measurement mode, users can select the measure repeatability(the difference between the data measured by the chip under the same measurement conditions).<br> + The higher the repeatability is, the smaller the difference and the more dependable data will be.<br> + 2.Read repeatability of the temperature and humidity data in cycle measurement mode, users can select the measure repeatability and the measure frequency(0.5Hz,1Hz,2Hz,4Hz,10Hz).<br> + 3.The user can customize the threshold range. The ALERT pin and the Arduino's interrupt pin can achieve the effect of the temperature and humidity threshold alarm.<br> + +## Installation +To use this library, first download the library to Raspberry Pi, then open the routines folder. To execute one routine, demox.py, type python demox.py on the command line. To execute the get_gyro_accel_temp_data.py routine, for example, you need to type: + +``` +python periodic_data_reading.py +``` + + + +## Methods + +```python + + def begin(self,RST = 4): + '''! + @brief Initialize the function + @return Return 0 indicates a successful initialization, while other values indicates failure and return to error code. + ''' + + def read_serial_number(self): + '''! + @brief Read the serial number of the chip + @return 32-digit serial number + ''' + + def soft_reset(self): + '''! + @brief Send command resets via iiC, enter the chip's default mode single-measure mode, + turn off the heater, and clear the alert of the ALERT pin. + @return Read the status register to determine whether the command was executed successfully, and returning true indicates success + ''' + + def pin_reset(self): + '''! + @brief Reset through the chip's reset pin, enter the chip's default mode single-measure mode, and clear the alert of the ALERT pin. + @return The status register has a data bit that detects whether the chip has been reset, and returning true indicates success + ''' + + def stop_periodic_mode(self): + '''! + @brief Exit from cycle measurement mode + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + ''' + + def heater_enable(self): + '''! + @brief Turn on the heater inside the chip + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + ''' + + def heater_disable(self): + '''! + @brief Turn off the heater inside the chip + @return Read the status of the register to determine whether the command was executed successfully, and returning true indicates success + @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings + ''' + + def clear_status_register(self): + '''! + @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + @n Set bit:15 to 0 so that ALERT pin can work, otherwise it will keep high. + ''' + + def read_alert_state(self): + '''! + @brief Read the state of the pin ALERT. + @return High returns 1, low returns 0. + ''' + + def read_temperature_and_humidity(self,repeatability = repeatability_periodic): + '''! + @brief Get temperature and humidity data in single measurement mode. + @param repeatability: The mode of reading data + @n repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + @n repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + @n repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + @n repeatability_periodic = 3 Periodic reading of data + @return Return a list containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity (%RH), status code + @n A status of 0 indicates the right return data. + ''' + + def get_temperature_C(self): + '''! + @brief Get the measured temperature (in degrees Celsius) + @return Return the float temperature data + ''' + + def get_temperature_F(self): + '''! + @brief Get the measured temperature (in degrees Fahrenheit) + @return Return the float temperature data + ''' + + def get_humidity_RH(self): + '''! + @brief Get measured humidity(%RH) + @return Return the float humidity data + ''' + + def start_periodic_mode(self,measure_freq,repeatability = repeatability_high): + '''! + @brief Enter cycle measurement mode and set repeatability(the difference between the data measured + the difference between the data measured by the chip under the same measurement conditions) + @param measure_freq Read the data frequency + @n measureFreq_0_5Hz = 0 + @n measureFreq_1Hz = 1 + @n measureFreq_2Hz = 2 + @n measureFreq_4Hz = 3 + @n measureFreq_10Hz = 4 + @param repeatability The mode of reading data,repeatability_high in default. + @n repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + @n repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + @n repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + @return Return true indicates a successful entrance to cycle measurement mode. + ''' + + def __read_status_register(self): + '''! + @brief Read the data stored in the status register. + @return Return to status like whether heater is ON or OFF, the status of the pin alert, reset status and the former cmd is executed or not. + ''' + + def environment_state(self): + '''! + @brief Determine if the temperature and humidity are out of the threshold range + @return Return the status code, representing as follows + @n 01 :Indicates that the humidity exceeds the lower threshold range + @n 10 :Indicates that the temperature exceeds the lower threshold range + @n 11 :Indicates that both the humidity and the temperature exceed the lower threshold range + @n 02 :Indicates that the humidity exceeds the upper threshold range + @n 20 :Indicates that the temperature exceeds the upper threshold range + @n 22 :Indicates that both the humidity and the temperature exceed the upper threshold range + @n 12 :Indicates that the temperature exceeds the lower threshold range, + and the humidity exceeds the upper threshold range + @n 21 :Indicates that the temperature exceeds the upper threshold range, + and the humidity exceeds the lower threshold range + ''' + + def set_temperature_limit_C(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the threshold temperature and alarm clear temperature(°C) + @param highset: High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + @param highClear: High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + @param lowset: Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear: Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + @note range: -40 to 125 degrees Celsius, highset > highClear > lowclear > lowset. + @return: A return to 0 indicates a successful setting. + ''' + + def set_temperature_limit_F(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the threshold temperature and alarm clear temperature(°F) + @param highset High temperature alarm point, when the temperature is greater than this value, the ALERT pin generates an alarm signal. + @param highClear High temperature alarm clear point, alarming when the temp higher than the highset, otherwise the alarm signal will be cleared. + @param lowset Low temperature alarm point, when the temperature is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear Low temperature alarm clear point, alarming when the temp lower than the highset, otherwise the alarm signal will be cleared. + @note Range -40 to 257 (Fahrenheit), highset > highClear > lowclear > lowset. + @return A return to 0 indicates a successful setting. + ''' + + def set_humidity_limit_RH(self,high_set,high_clear, low_set,low_clear): + '''! + @brief Set the relative humidity threshold temperature and the alarm clear humidity(%RH) + @param highset High humidity alarm point, when the humidity is greater than this value, the ALERT pin generates an alarm signal. + @param highClear High humidity alarm clear point, alarming when the humidity higher than the highset, otherwise the alarm signal will be cleared. + @param lowset Low humidity alarm point, when the humidity is lower than this value, the ALERT pin generates an alarm signal. + @param lowclear Low humidity alarm clear point, alarming when the humidity lower than the highset, otherwise the alarm signal will be cleared. + @note range 0 - 100 %RH, highset > highClear > lowclear > lowset + @return A return to 0 indicates a successful setting. + ''' + + def measure_temperature_limit_C(self): + '''! + @brief Measure temperature threshold temperature and alarm clear temperature + @return Return true indicates successful data acquisition + ''' + + def measure_temperature_limit_F(self): + '''! + @brief Measure the threshold temperature and alarm clear temperature + @return Return true indicates successful data acquisition + ''' + + def measure_humidity_limit_RH(self): + '''! + @brief Measure the threshold humidity of relative humidity and alarm clear humidity + @return Return true indicates successful data acquisition + ''' + + def get_temperature_high_set_F(self): + '''! + @brief Get high temperature alarm points(°F) + @return Return high temperature alarm points(°F) + ''' + + def get_temperature_high_clear_F(self): + '''! + @brief Get high temperature alarm clear points(°F) + @return Return high temperature alarm clear points(°F)) + ''' + + def get_temperature_low_clear_F(self): + '''! + @brief Get low temperature alarm clear points(°F) + @return Return low temperature alarm clear points(°F) + ''' + + def get_temperature_low_set_F(self): + '''! + @brief Get low temperature alarm points(°F) + @return Return low temperature alarm points + ''' + + def get_temperature_high_set_C(self): + '''! + @brief Get high temperature alarm points(°C) + @return Return high temperature alarm points(°C) + ''' + + def get_temperature_high_clear_C(self): + '''! + @brief Get high temperature alarm clear points(°C) + @return Return high temperature alarm clear points(°C) + ''' + + def get_temperature_low_clear_C(self): + '''! + @brief Get low temperature alarm clear points(°C) + @return Return low temperature alarm clear points(°C) + ''' + + def get_temperature_low_set_C(self): + '''! + @brief Get low temperature alarm points(°C) + @return Return low temperature alarm points + ''' + + def get_humidity_high_set_RH(self): + '''! + @brief Get the high humidity alarm point(%RH) + @return Return the high humidity alarm point + ''' + + def get_humidity_high_clear_RH(self): + '''! + @brief Get the high humidity alarm clear point(%RH) + @return Return the high humidity alarm clear point + ''' + + def get_humidity_low_clear_RH(self): + '''! + @brief Get the low humidity alarm clear point(%RH) + @return Return the low humidity alarm clear point + ''' + + def get_humidity_low_set_RH(self): + '''! + @brief Get the low humidity alarm point + @return Return the low humidity alarm point + ''' + +``` + +## Compatibility + +* RaspberryPi Version + +| Board | Work Well | Work Wrong | Untested | Remarks | +| ------------ | :-------: | :--------: | :------: | ------- | +| RaspberryPi2 | | | √ | | +| RaspberryPi3 | | | √ | | +| RaspberryPi4 | √ | | | | + +* Python Version + +| Python | Work Well | Work Wrong | Untested | Remarks | +| ------- | :-------: | :--------: | :------: | ------- | +| Python2 | √ | | | | +| Python3 | √ | | | | + + +## History + +- 2021/06/11 - Version 1.0.0 released. + +## Credits + +Written by yangfeng(feng.yang@dfrobot.com), 2021 (Welcome to our [website](https://www.dfrobot.com/)) + + + + + diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README_CN.md b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README_CN.md new file mode 100644 index 0000000000000000000000000000000000000000..d13318eca936b48192a0b51e98dadb5b00e68e8e --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/README_CN.md @@ -0,0 +1,326 @@ +# DFRobot_SHT3x +- [English Version](./README.md) + +SHT3x系列芯片用于测量环境温度和相对湿度(空气中的潮湿程度,它表示大气中水汽含量距离大气饱和的程度),它是SHT2x系列的继承者,包括低成本版本SHT30、标准版本SHT31,以及高端版本SHT35<br> +SHT3x系列温湿度传感器通过IIC通信,使用比较方便,工作电压范围宽(2.15至5.5 V),芯片封装的占位面积<br> +为2.5 × 2.5 mm2,高度为0.9 mm,这有助于SHT3x集成到多种应用,适合各类场景<br> +SHT3x建立在全新和优化的CMOSens® 芯片之上,进一步提高了产品可靠性和精度规格。SHT3x提供了一系列新功能,<br> +如增强信号处理、两个独特的用户可选的I2C地址、一个可编程温湿度极限的报警模式,以及高达1 MHz的通信速度<br> +在使用过程中可选择是否打开加热器<br> + 加热器作用:<br> + ①通过比较加热前后测出的相对湿度值及温度值,可确定传感器是否正常工作;<br> + ②在潮湿环境下使用加热器,可避免传感器凝露;<br> + ③测量露点温度(空气中的水蒸气变为露珠时候的温度)时也需要使用加热器。<br> +SHT3x芯片提供两种工作模式:<br> +1.单次测量模式,此模式下空闲状态电流为0.2微安,功耗较低(测量数据时600 微安).<br> +2.周期测量模式,此模式下空闲状态电流为45微安,此模式下ALERT开始工作(测量数据时600 微安).<br> +以下是芯片典型的测量精度(@后面是在此温湿度范围下):<br> + +版本号 | 典型温度精度 (°C) | 典型湿度精度 (%RH) | 测量范围(温度/湿度) +--------------------| :-------------------: | :---------------------: | ----- +SHT30 | ±0.2 @0-65 °C | ±2 @10-90% RH | -40-125 °C/0-100 %RH +SHT31 | ±0.2 @0-90 °C | ±2 @0-100% RH | -40-125 °C/0-100 %RH +SHT35 | ±0.1 @20-60 °C | ±1.5 @0-80% RH | -40-125 °C/0-100 %RH + + + + + + + +## 产品链接(https://www.dfrobot.com.cn/goods-2695.html) + + SEN0330:Fermion: SHT30数字温湿度传感器<br> + SEN0331:Fermion: SHT31数字温湿度传感器<br> + SEN0332:Fermion: SHT31-F数字温湿度传感器<br> + SEN0333:Fermion: SHT35-F数字温湿度传感器(Breakout)<br> + SEN0334:Gravity: SHT31-F数字温湿度传感器<br> + +## 目录 + + * [概述](#概述) + * [库安装](#库安装) + * [方法](#方法) + * [兼容性](#兼容性) + * [历史](#历史) + * [创作者](#创作者) + +## 概述 + +1.在单次测量模式下读取环境温湿度,用户可以选择测量的可重复性(芯片在两次相同测量条件下测量到的数据的差值)<br> + 可重复性越高,差值越小,数据越可靠<br> + 2.在周期测量模式下读取环境温湿度,用户可以选择测量的可重复性和测量频率(0.5Hz,1Hz,2Hz,4Hz,10Hz)<br> + 3.利用ALERT引脚和Arduino的中断引脚达到温湿度超阈值报警的效果,用户可自定义阈值大小<br> + +## 库安装 + +要使用这个库,首先将库下载到Raspberry Pi,然后打开例程文件夹。要执行一个例程demox.py,请在命令行中输入python demox.py。例如,periodic_data_reading.py例程,你需要输入: + +```python +python periodic_data_reading.py +``` + + + +## 方法 + +```python + + def begin(self,RST = 4): + '''! + @brief 初始化函数 + @return 返回0表示初始化成功,返回其他值表示初始化失败,返回错误码 + ''' + + def read_serial_number(self): + '''! + @brief 读取芯片的序列号 + @return 返回32位序列号 + ''' + + def soft_reset(self): + '''! + @brief 通过IIC发送命令复位,进入芯片的默认模式单次测量模式,关闭加热器,并清除ALERT引脚的警报。 + @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + ''' + + def pin_reset(self): + '''! + @brief 通过芯片的复位引脚进行复位,进入芯片的默认模式单次测量模式,并清除ALERT引脚的警报。 + @return 状态寄存器有一数据位能检测芯片是否进行了复位,返回true则表示成功 + ''' + + def stop_periodic_mode(self): + '''! + @brief 从周期读取数据模式退出。 + @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + ''' + + def heater_enable(self): + '''! + @brief 打开芯片里面的加热器. + @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + @note 加热器的使用条件,应是在潮湿环境时,若正常情况下使用则会造成读数不准. + ''' + + def heater_disable(self): + '''! + @brief 关闭芯片里面的加热器. + @return 通过读取状态寄存器来判断命令是否成功被执行,返回true则表示成功 + @note 加热器的使用条件,应是在潮湿环境时,若正常情况下使用则会造成读数不准. + ''' + + def clear_status_register(self): + '''! + @brief All flags (Bit 15, 11, 10, 4) in the status register can be cleared (set to zero) + @n 把bit:15 设置为0后ALERT引脚才能正常工作,否则将一直处于高电平。 + ''' + + def read_alert_state(self): + '''! + @brief 读取ALERT引脚的状态. + @return 高电平则返回1,低电平则返回0. + ''' + + def read_temperature_and_humidity(self,repeatability = repeatability_periodic): + '''! + @brief 在单次测量模式下获取温湿度数据 + @param repeatability 设置读取温湿度数据的可重复性,eRepeatability_t类型的数据 + @return 返回包含摄氏温度(°C),华氏温度(°F),相对湿度(%RH),状态码的结构体 + @n 状态为0表示返回数据正确 + ''' + + def get_temperature_C(self): + '''! + @brief 获取测量到的温度(单位:摄氏度) + @return 返回float类型的温度数据 + ''' + + def get_temperature_F(self): + '''! + @brief 获取测量到的温度(单位:华氏度) + @return 返回float类型的温度数据 + ''' + + def get_humidity_RH(self): + '''! + @brief 获取测量到的湿度(单位:%RH) + @return 返回float类型的湿度数据 + ''' + + def start_periodic_mode(self,measure_freq,repeatability = repeatability_high): + '''! + @brief 进入周期测量模式,并设置可重复性(芯片在两次相同测量条件下测量到的数据的差值)、读取频率。 + @param measureFreq 读取数据的频率,eMeasureFrequency_t类型的数据 + @param repeatability 设置读取温湿度数据的可重复性,eRepeatability_t类型的数据,默认为eRepeatability_High(高重复性) + @return 返回true表示进入周期模式成功。 + ''' + + def environment_state(self): + '''! + @brief 判断温湿度超出阈值范围的情况 + @return 返回状态码,状态码代表含义如下: + @n 01 :表示湿度超过下阈值范围 + @n 10 :表示温度超过下阈值范围 + @n 11 :表示温湿度都超过下阈值范围 + @n 02 :表示湿度超过上阈值范围 + @n 20 :表示温度超过上阈值范围 + @n 22 :表示温湿度都超过上阈值范围 + @n 12 :表示温度超过下阈值范围,湿度超过上阈值范围 + @n 21 :表示温度超过上阈值范围,湿度超过下阈值范围 + ''' + + def set_temperature_limit_C(self,high_set,high_clear, low_set,low_clear): + '''! + @brief 设置温度阈值温度和警报清除温度(°C) + @param highset 高温报警点,当温度大于此值时ALERT引脚产生报警信号。 + @param highClear 高温警报清除点,当温度大于highset产生报警信号,而温度小于此值报警信号则被清除。 + @param lowset 低温报警点,当温度小于此值时ALERT引脚产生报警信号。 + @param lowclear 低温警报清除点,当温度小于lowset产生报警信号,而温度大于此值时报警信号则被清除 + @note 范围:-40 到 125 ,highset>highClear>lowclear>lowset。 + @return 返回0则表示设置成功. + ''' + + def set_temperature_limit_F(self,high_set,high_clear, low_set,low_clear): + '''! + @brief 设置温度阈值温度和警报清除温度(°F) + @param highset 高温报警点,当温度大于此值时ALERT引脚产生报警信号。 + @param highClear 高温警报清除点,当温度大于highset产生报警信号,而温度小于此值报警信号则被清除。 + @param lowset 低温报警点,当温度小于此值时ALERT引脚产生报警信号。 + @param lowclear 低温警报清除点,当温度小于lowset产生报警信号,而温度大于此值时报警信号则被清除。 + @note 范围:-40 到 257 ,highset>highClear>lowclear>lowset。 + @return 返回0则表示设置成功. + ''' + + def set_humidity_limit_RH(self,high_set,high_clear, low_set,low_clear): + '''! + @brief 设置相对湿度阈值温度和警报清除湿度(%RH) + @param highset 高湿度报警点,当相对湿度大于此值时ALERT引脚产生报警信号。 + @param highClear 高湿度警报清除点,当相对湿度大于highset产生报警信号,而相对湿度小于此值报警信号则被清除。 + @param lowset 低湿度报警点,当相对湿度小于此值时ALERT引脚产生报警信号。 + @param lowclear 低湿度警报清除点,当相对湿度小于lowset产生报警信号,而相对湿度大于此值时报警信号则被清除。 + @note 范围:0 - 100 %RH,highset>highClear>lowclear>lowset。 + @return 返回0则表示设置成功. + ''' + + def measure_temperature_limit_C(self): + '''! + @brief 测量温度阈值温度和警报清除温度 + @return 返回true 表示数据获取成功 + ''' + + def measure_temperature_limit_F(self): + '''! + @brief 测量温度阈值温度和警报清除温度 + @return 返回true 表示数据获取成功 + ''' + + def measure_humidity_limit_RH(self): + '''! + @brief 读取相对湿度阈值温度和警报清除湿度 + @return 返回true 表示数据获取成功 + ''' + + def get_temperature_high_set_F(self): + '''! + @brief 获取高温报警点温度(°F) + @return 返回高温报警点温度 + ''' + + def get_temperature_high_clear_F(self): + '''! + @brief 获取高温警报清除点温度(°F) + @return 返回高温警报清除点温度 + ''' + + def get_temperature_low_clear_F(self): + '''! + @brief 获取低温警报清除点温度(°F) + @return 返回低温警报清除点温度 + ''' + + def get_temperature_low_set_F(self): + '''! + @brief 获取低温报警点温度(°F) + @return 返回低温报警点温度 + ''' + + def get_temperature_high_set_C(self): + '''! + @brief 获取高温报警点温度(°C) + @return 返回高温报警点温度 + ''' + + def get_temperature_high_clear_C(self): + '''! + @brief 获取高温警报清除点温度(°C) + @return 返回高温警报清除点温度 + ''' + + def get_temperature_low_clear_C(self): + '''! + @brief 获取低温警报清除点温度(°C) + @return 返回低温警报清除点温度 + ''' + + def get_temperature_low_set_C(self): + '''! + @brief 获取低温报警点温度(°C) + @return 返回低温报警点温度 + ''' + + def get_humidity_high_set_RH(self): + '''! + @brief 获取高湿度报警点湿度(%RH) + @return 返回高湿度报警点湿度 + ''' + + def get_humidity_high_clear_RH(self): + '''! + @brief 获取高湿度警报清除点湿度(%RH) + @return 返回高湿度警报清除点湿度 + ''' + + def get_humidity_low_clear_RH(self): + '''! + @brief 获取低湿度警报清除点湿度(%RH) + @return 返回低湿度警报清除点湿度 + ''' + + def get_humidity_low_set_RH(self): + '''! + @brief 获取低湿度报警点湿度(v) + @return 返回低湿度报警点湿度 + ''' +``` + +## 兼容性 + + + +| 主板 | 通过 | 未通过 | 未测试 | 备注 | +| ------------ | :--: | :----: | :----: | :--: | +| RaspberryPi2 | | | √ | | +| RaspberryPi3 | | | √ | | +| RaspberryPi4 | √ | | | | + +* Python 版本 + +| Python | 通过 | 未通过 | 未测试 | 备注 | +| ------- | :--: | :----: | :----: | ---- | +| Python2 | √ | | | | +| Python3 | √ | | | | + +## 历史 + + +- 2021/06/11 - Version 1.0.0 released. + +## 创作者 + +Written by yangfeng(feng.yang@dfrobot.com), 2021 (Welcome to our [website](https://www.dfrobot.com/)) + + + + + diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/periodic_data_reading.py b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/periodic_data_reading.py new file mode 100644 index 0000000000000000000000000000000000000000..17d42a73a7a876eda0ebbae20796680969ba035f --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/periodic_data_reading.py @@ -0,0 +1,88 @@ +# -*- coding:utf-8 -*- +'''! + @file periodic_data_reading.py + @brief Read ambient temperature (C/F) and relative humidity (%RH) in cycle read mode. + @n Experimental phenomenon: Before we start, please set the read frequency and repeatability of the read + @n(the difference between the data measured by the chip under the same measurement conditions), + @n and enter the periodic read mode, and then read the temperature and humidity data. + @n The temperature and humidity data will be printed at the serial port, after 10 seconds of operation. + @n It will exit the cycle mode and enter 2 measurement mode: Single measurement mode and Cycle measurement mode. + @n Single measurement mode: reflect the difference between the two modes of reading data. + @n Cycle measurement mode: the chip periodically monitors temperature and humidity, only in this mode the ALERT pin will work. + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @License The MIT License (MIT) + @author [yangfeng]<feng.yang@dfrobot.com> + @version V1.0 + @date 2021-06-11 + @url https://github.com/DFRobot/DFRobot_SHT3x +''' +import sys +sys.path.append("../") # set system path to top +import time +from DFRobot_SHT3X import * +SHT3X = DFRobot_SHT3x(iic_addr = 0x45,bus = 1) + +def setup(): + + while(SHT3X.begin(RST = 4) != 0): + print("The initialization of the chip is failed, please confirm whether the chip connection is correct") + time.sleep(1) + + ''' + readSerialNumber Read the serial number of the chip + @return Return 32-digit serial number + ''' + print("The chip serial number = %d "%SHT3X.read_serial_number()) + + ''' + softReset Send command resets via iiC, enter the chip's default mode single-measure mode, turn off the heater, + and clear the alert of the ALERT pin. + @return Read the status register to determine whether the command was executed successfully, and returning true indicates success. + ''' + if(SHT3X.soft_reset() == False): + print("Failed to reset the chip") + + + ''' + @brief Enter cycle measurement mode and set repeatability(the difference between the data measured + the difference between the data measured by the chip under the same measurement conditions) + @param measureFreq: Read the data frequency + @n measureFreq_0_5Hz = 0 + @n measureFreq_1Hz = 1 + @n measureFreq_2Hz = 2 + @n measureFreq_4Hz = 3 + @n measureFreq_10Hz = 4 + @param repeatability: The mode of reading data,repeatability_high in default. + @n repeatability_high = 0 #/**<In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C*/ + @n repeatability_medium = 1 #/**<In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C*/ + @n repeatability_low = 2 #/**<In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C*/ + @return Return true indicates a successful entrance to cycle measurement mode. + ''' + if(SHT3X.start_periodic_mode(measure_freq = SHT3X.measureFreq_10Hz,repeatability = SHT3X.repeatability_high) == False): + print("Failed to enter the periodic mode") + + print("------------------Read data in cycle measurement mode-----------------------") + +def loop(): + ''' + @brief Get the measured temperature (in degrees Celsius) + @return Return the float temperature data + ''' + print("environment temperature(°C): %f C"%SHT3X.get_temperature_C()) + + ''' + @brief Get the measured temperature (in degrees Fahrenheit) + @return Return the float temperature data + ''' + print("environment temperature(F): %f F"%SHT3X.get_temperature_F()) + + ''' + @brief Get measured humidity(%RH) + @return Return the float humidity data + ''' + print("relative humidity(%%RH): %f %%RH"%SHT3X.get_humidity_RH()) + time.sleep(1) +if __name__ == "__main__": + setup() + while True: + loop() diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/single_measurement.py b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/single_measurement.py new file mode 100644 index 0000000000000000000000000000000000000000..a56d3d322f0fe57c81c3144040c7c8a42269cdeb --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/python/raspberrypi/example/single_measurement.py @@ -0,0 +1,68 @@ +# -*- coding:utf-8 -*- +'''! + @file single_measurement.py + @brief Read ambient temperature (C/F) and relative humidity (%RH) in single-read mode. + @n Experimental phenomenon: the chip defaults in this mode, we need to send instructions to enable the chip collect data, + @n which means the repeatability of the read needs to be set (the difference between the data measured by the chip under the same measurement conditions) + @n then read the temperature and humidity data and print the data in the serial port. + @n Single measure mode: read data as needed, power consumption is relatively low, the chip idle state only costs 0.5mA. + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @License The MIT License (MIT) + @author [yangfeng]<feng.yang@dfrobot.com> + @version V1.0 + @date 2021-06-11 + @url https://github.com/DFRobot/DFRobot_SHT3x +''' + +import sys +sys.path.append("../") # set system path to top +import time +from DFRobot_SHT3X import * +SHT3X = DFRobot_SHT3x(iic_addr = 0x45,bus = 1) + +def setup(): + + while(SHT3X.begin(RST = 4) != 0): + print("The initialization of the chip is failed, please confirm whether the chip connection is correct") + time.sleep(1) + + ''' + readSerialNumber Read the serial number of the chip + @return Return 32-digit serial number + ''' + print("The chip serial number = %d "%SHT3X.read_serial_number()) + + ''' + softReset Send command resets via iiC, enter the chip's default mode single-measure mode, turn off the heater, + and clear the alert of the ALERT pin. + @return Read the status register to determine whether the command was executed successfully, and returning true indicates success. + ''' + if(SHT3X.soft_reset() == False): + print("Failed to reset the chip") + + print("------------------Read data in single measurement mode-----------------------") + +def loop(): + ''' + @brief Get the measured temperature (in degrees Celsius) + @return Return the float temperature data + ''' + print("environment temperature(°C): %f C"%SHT3X.get_temperature_C()) + + ''' + @brief Get the measured temperature (in degrees Fahrenheit) + @return Return the float temperature data + ''' + print("environment temperature(F): %f F"%SHT3X.get_temperature_F()) + + ''' + @brief Get measured humidity(%RH) + @return Return the float humidity data + ''' + print("relative humidity(%%RH): %f %%RH"%SHT3X.get_humidity_RH()) + time.sleep(1) + +if __name__ == "__main__": + setup() + while True: + loop() diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0330.jpg b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0330.jpg new file mode 100644 index 0000000000000000000000000000000000000000..90e7c6f7e9e238aaeeeb8c5a1730f661d1bea2cd Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0330.jpg differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0331.jpg b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0331.jpg new file mode 100644 index 0000000000000000000000000000000000000000..94f497d3c49b692b70781e0d35e2c0695dff10c3 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0331.jpg differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0332.jpg b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0332.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c64ae97a0d9c8dc821de8454091db563dae06c65 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0332.jpg differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0333.jpg b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0333.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5e2a727ca4c0b891a85bb4356ea7155988c22c66 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0333.jpg differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0334.jpg b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0334.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ba7122c300396a98d9531c76e481dfa304a2f6e0 Binary files /dev/null and b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/DFRobot_SHT3x-master/resources/images/SEN0334.jpg differ diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/README new file mode 100644 index 0000000000000000000000000000000000000000..93793971ffcaedf70668ba0d17d84315c350f9f7 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include <Foo.h> +#include <Bar.h> + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/platformio.ini b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/platformio.ini new file mode 100644 index 0000000000000000000000000000000000000000..6fb62d3206ce315f5057bf2763bc3cf27c7cf237 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:nodemcuv2] +platform = espressif8266 +board = nodemcuv2 +framework = arduino +monitor_speed = 115200 + +lib_deps = + adafruit/Adafruit SHT31 Library@^2.2.2 diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/src/main.cpp b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..759e1742e521a6203ff8aa2257d9e893c76e98f7 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/src/main.cpp @@ -0,0 +1,40 @@ +#include <Wire.h> +#include "Adafruit_SHT31.h" + +Adafruit_SHT31 sht31 = Adafruit_SHT31(); + +void setup() { + Serial.begin(115200); + + // Pour ESP8266 : D2 = GPIO4 (SDA), D1 = GPIO5 (SCL) + Wire.begin(4, 5); + + if (!sht31.begin(0x44)) { // Adresse I2C par défaut du SHT30/SHT31 + Serial.println("❌ SHT30 non détecté ! Vérifie le câblage."); + // ⚠️ Empêche le watchdog de redémarrer en boucle + while (true) { + delay(1000); + } + } + + Serial.println("✅ SHT30 détecté et initialisé."); +} + +void loop() { + float temperature = sht31.readTemperature(); + float humidity = sht31.readHumidity(); + + if (!isnan(temperature) && !isnan(humidity)) { + Serial.print("Température : "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidité : "); + Serial.print(humidity); + Serial.println(" %"); + } else { + Serial.println("❌ Échec lecture SHT30 !"); + } + + delay(2000); +} diff --git a/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/test/README b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/test/README new file mode 100644 index 0000000000000000000000000000000000000000..9b1e87bc67c90e7f09a92a3e855444b085c655a6 --- /dev/null +++ b/Capteur-autonome/Projects/Archives/Tests de capteurs simples/Test_SHT30_ESP8266/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git "a/Capteur-autonome/Projects/Archives/Tests int\303\251grations/Integration_MAC_SDS011_SHT30_ESP8266/src/main.cpp" "b/Capteur-autonome/Projects/Archives/Tests int\303\251grations/Integration_MAC_SDS011_SHT30_ESP8266/src/main.cpp" index 19ac18a4381017e2b6a6f8fc2c85b4240b0b0e30..3d1774cb503dfa349e1c08ba6d4454ed660dd85b 100644 --- "a/Capteur-autonome/Projects/Archives/Tests int\303\251grations/Integration_MAC_SDS011_SHT30_ESP8266/src/main.cpp" +++ "b/Capteur-autonome/Projects/Archives/Tests int\303\251grations/Integration_MAC_SDS011_SHT30_ESP8266/src/main.cpp" @@ -6,22 +6,26 @@ #include <stdarg.h> // SDS011 via SoftwareSerial -#define RX_PIN_SDS 14 // GPIO14 = D5 -#define TX_PIN_SDS 12 // GPIO12 = D6 +#define RX_PIN_SDS 14 // GPIO14 = D5 (RX de l'ESP ← TX du SDS011) +#define TX_PIN_SDS 12 // GPIO12 = D6 (TX de l'ESP → RX du SDS011) // LoRa-E5 via SoftwareSerial -#define RXD2 13 // GPIO13 = D7 -#define TXD2 15 // GPIO15 = D8 +#define RXD2 13 // GPIO13 = D7 (RX de l'ESP ← TX du LoRa) +#define TXD2 3 // GPIO3 = RX broche physique (TX de l'ESP → RX du LoRa) -SoftwareSerial SDS_Serial(RX_PIN_SDS, TX_PIN_SDS); // RX, TX -SoftwareSerial LoRaSerial(RXD2, TXD2); // RX, TX +// SHT30 via I2C +#define SDA_PIN 4 // D2 = GPIO4 +#define SCL_PIN 5 // D1 = GPIO5 + +SoftwareSerial SDS_Serial(RX_PIN_SDS, TX_PIN_SDS); +SoftwareSerial LoRaSerial(RXD2, TXD2); SdsDustSensor sds(SDS_Serial); DFRobot_SHT3x sht3x; static char recv_buf[512]; -// Fonction AT +// Fonction AT pour LoRa static int at_send_check_response(const char *p_ack, int timeout_ms, const char *p_cmd, ...) { va_list args; int index = 0; @@ -54,20 +58,26 @@ static int at_send_check_response(const char *p_ack, int timeout_ms, const char void setup() { Serial.begin(115200); - Wire.begin(4, 5); // SDA = GPIO4 (D2), SCL = GPIO5 (D1) - - // SHT30 init - while (sht3x.begin() != 0) { - Serial.println("Erreur SHT30"); - delay(1000); - } - sht3x.startPeriodicMode(sht3x.eMeasureFreq_1Hz); - // SDS011 init + // Init SDS011 SDS_Serial.begin(9600); + delay(1000); // important pour laisser le capteur s’allumer sds.begin(); + Serial.println("✅ SDS011 initialisé"); + Serial.println(sds.queryFirmwareVersion().toString()); + Serial.println(sds.setActiveReportingMode().toString()); + Serial.println(sds.setContinuousWorkingPeriod().toString()); + + // Init I2C + SHT30 + Wire.begin(SDA_PIN, SCL_PIN); + if (sht3x.begin() != 0) { + Serial.println("❌ Erreur init SHT30 !"); + } else { + sht3x.startPeriodicMode(sht3x.eMeasureFreq_1Hz); + Serial.println("✅ SHT30 initialisé"); + } - // LoRa-E5 init + // Init LoRa-E5 LoRaSerial.begin(9600); delay(100); at_send_check_response("+AT: OK", 100, "AT\r\n"); @@ -87,21 +97,22 @@ void printReadableData(float pm25, float pm10, float tempC, float hum) { void loop() { PmResult pm = sds.readPm(); if (!pm.isOk()) { - Serial.println("Erreur SDS011 !"); + Serial.println("❌ Erreur SDS011 !"); delay(5000); return; } - delay(1100); // SHT30 timing + delay(1100); // SHT30 timing DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(); if (data.ERR != 0) { - Serial.println("Erreur lecture SHT30 !"); + Serial.println("❌ Erreur lecture SHT30 !"); delay(5000); return; } printReadableData(pm.pm25, pm.pm10, data.TemperatureC, data.Humidity); + // Formatage en hexadécimal pour LoRa uint16_t pm25 = pm.pm25 * 100; uint16_t pm10 = pm.pm10 * 100; uint16_t temp = data.TemperatureC * 100;