Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
hardware:wsks:notes-install [2021/01/06 23:57] – yoann | hardware:wsks:notes-install [2021/02/01 21:51] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 71: | Ligne 71: | ||
+ | ^ Devkit | ||
+ | | D5 (GPIO14) | ||
+ | | G | - | | ||
+ | | 3V | + | | ||
+ | |||
+ | |||
+ | ==== Code de test ==== | ||
+ | |||
+ | <code cpp testDHT11.ino> | ||
+ | #define pin 14 // ESP8266-12E | ||
+ | int temp = 0; // | ||
+ | int humi = 0; //humidity | ||
+ | void readTemperatureHumidity(); | ||
+ | void uploadTemperatureHumidity(); | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | | ||
+ | readTemperatureHumidity(); | ||
+ | delay(4000); | ||
+ | |||
+ | } | ||
+ | |||
+ | //read temperature humidity data | ||
+ | void readTemperatureHumidity(){ | ||
+ | int j; | ||
+ | unsigned int loopCnt; | ||
+ | int chr[40] = {0}; | ||
+ | unsigned long time1; | ||
+ | bgn: | ||
+ | delay(2000); | ||
+ | //Set interface mode 2 to: output | ||
+ | //Output low level 20ms (>18ms) | ||
+ | //Output high level 40μs | ||
+ | pinMode(pin, | ||
+ | digitalWrite(pin, | ||
+ | delay(20); | ||
+ | digitalWrite(pin, | ||
+ | delayMicroseconds(40); | ||
+ | digitalWrite(pin, | ||
+ | //Set interface mode 2: input | ||
+ | pinMode(pin, | ||
+ | //High level response signal | ||
+ | loopCnt = 10000; | ||
+ | while (digitalRead(pin) != HIGH){ | ||
+ | if (loopCnt-- == 0){ | ||
+ | //If don't return to high level for a long time, output a prompt and start over | ||
+ | Serial.println(" | ||
+ | goto bgn; | ||
+ | } | ||
+ | } | ||
+ | //Low level response signal | ||
+ | loopCnt = 30000; | ||
+ | while (digitalRead(pin) != LOW){ | ||
+ | if (loopCnt-- == 0){ | ||
+ | //If don't return low for a long time, output a prompt and start over | ||
+ | Serial.println(" | ||
+ | goto bgn; | ||
+ | } | ||
+ | } | ||
+ | //Start reading the value of bit1-40 | ||
+ | for (int i = 0; i < 40; i++){ | ||
+ | while (digitalRead(pin) == LOW){} | ||
+ | //When the high level occurs, write down the time " | ||
+ | time1 = micros(); | ||
+ | while (digitalRead(pin) == HIGH){} | ||
+ | //When there is a low level, write down the time and subtract the time just saved | ||
+ | //If the value obtained is greater than 50μs, it is ‘1’, otherwise it is ‘0’ | ||
+ | //And save it in an array | ||
+ | if (micros() - time1 > 50){ | ||
+ | chr[i] = 1; | ||
+ | } else { | ||
+ | chr[i] = 0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //Humidity, 8-bit bit, converted to a value | ||
+ | humi = chr[0] * 128 + chr[1] * 64 + chr[2] * 32 + chr[3] * 16 + chr[4] * 8 + chr[5] * 4 + chr[6] * 2 + chr[7]; | ||
+ | // | ||
+ | temp = chr[16] * 128 + chr[17] * 64 + chr[18] * 32 + chr[19] * 16 + chr[20] * 8 + chr[21] * 4 + chr[22] * 2 + chr[23]; | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(temp); | ||
+ | Serial.print(" | ||
+ | Serial.println(humi); | ||
+ | |||
+ | } | ||
+ | </ | ||
==== Montage du capteur BMP185 ==== | ==== Montage du capteur BMP185 ==== | ||
SCL -> D1 | SCL -> D1 | ||
SDA -> D2 | SDA -> D2 | ||
+ | |||
+ | ===== Montage capteur de luminosité ===== | ||
+ | |||
+ | ^ Devkit | ||
+ | | 3V | VCC | | ||
+ | | D1 | SCL | | ||
+ | | D2 | SDA | | ||
+ | | G | GND | | ||
+ | |||
+ | |||
+ | <code c test_BH1750FVI.ino> | ||
+ | #include < | ||
+ | |||
+ | const int Light_ADDR = 0b0100011; | ||
+ | |||
+ | int tempLight = 0; | ||
+ | |||
+ | void readLight(); | ||
+ | |||
+ | void setup() { | ||
+ | | ||
+ | |||
+ | Wire.begin(); | ||
+ | |||
+ | // | ||
+ | Wire.beginTransmission(Light_ADDR); | ||
+ | Wire.write(0b00000001); | ||
+ | Wire.endTransmission(); | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | readLight(); | ||
+ | delay(5000); | ||
+ | } | ||
+ | |||
+ | void readLight(){ | ||
+ | // reset | ||
+ | Wire.beginTransmission(Light_ADDR); | ||
+ | Wire.write(0b00000111); | ||
+ | Wire.endTransmission(); | ||
+ | |||
+ | Wire.beginTransmission(Light_ADDR); | ||
+ | Wire.write(0b00100000); | ||
+ | Wire.endTransmission(); | ||
+ | // typical read delay 120ms | ||
+ | delay(120); | ||
+ | Wire.requestFrom(Light_ADDR, | ||
+ | for (tempLight = 0; Wire.available() >= 1; ) { | ||
+ | char c = Wire.read(); | ||
+ | tempLight = (tempLight << 8) + (c & 0xFF); | ||
+ | } | ||
+ | tempLight = tempLight / 1.2; | ||
+ | Serial.print(" | ||
+ | Serial.println(tempLight); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Montage de l' | ||
+ | |||
+ | ^ DevKit | ||
+ | | 3V | Vcc | | ||
+ | | G | GND | | ||
+ | | D1 | SCL | | ||
+ | | D2 | SDA | | ||
+ | |||
===== Références ===== | ===== Références ===== |