// Matériels : Adafruit Feather Huzzah ESP8266 + Support Particle, Adafruit OLED SH1107, HYT221, câble Qwiic // Logiciel : Arduino // A ajouter #include #include #include #include // Adresse I2C par défaut de HYT 221, 271, 371 #define HYT_ADDR 0x28 #define BUTTON_A 0 #define BUTTON_B 16 #define BUTTON_C 2 // Constructeurs Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); void setup() { // Bus I2C Wire.begin(); Wire.setClock(400000); display.begin(0x3C, true); // L'addresse de l'afficheur est 0x3C par défaut // Configuration de l'affichage display.setRotation(1); // Affichage horizontal display.setTextSize(1); display.setTextColor(SH110X_WHITE); display.clearDisplay(); // Pour ne pas afficher le logo Adafruit chargé // automatiquement à la mise sous tension // Connexion des boutons-poussoirs pinMode(BUTTON_A, INPUT_PULLUP); pinMode(BUTTON_B, INPUT_PULLUP); pinMode(BUTTON_C, INPUT_PULLUP); } void loop() { double humidity; double temperature; // Efface le buffer display.clearDisplay(); // Test des boutons display.setCursor(0, 0); if (!digitalRead(BUTTON_A)) display.print("[A]"); if (!digitalRead(BUTTON_B)) display.print("[B]"); if (!digitalRead(BUTTON_C)) display.print("[C]"); // Titre display.setCursor(30, 0); display.println("HYT221"); Wire.beginTransmission(HYT_ADDR); // Début de la transmission avec le capteur HYT221 Wire.requestFrom(HYT_ADDR, 4); // Nécessite 4 octets // Read the bytes if they are available // Les deux premiers octets sont l'humidité, les deux suivants la température if (Wire.available() == 4) { int b1 = Wire.read(); int b2 = Wire.read(); int b3 = Wire.read(); int b4 = Wire.read(); Wire.endTransmission(); // Fin de la transmission avec le capteur HYT221 // Calcul de l'humidité int rawHumidity = b1 << 8 | b2; rawHumidity = (rawHumidity &= 0x3FFF); humidity = 100.0 / pow(2, 14) * rawHumidity; // Calcul de la température b4 = (b4 >> 2); int rawTemperature = b3 << 6 | b4; temperature = 165.0 / pow(2, 14) * rawTemperature - 40; // Affichage display.setCursor(0, 12); display.print("Temperature: "); display.print(temperature); display.println("C "); display.print("Humidite: "); display.print(humidity); display.println("% "); // Infos display.setCursor(5, 52); display.print("Appuyer sur A, B, C"); display.display(); } else { display.println("Pas de mesure"); } }