Bonjour à tous,
Je me permet de vous solliciter sur un problème que je rencontre sur mon projet de serre automatisée.
Le projet consiste à afficher sur 8 écrans Oled128/64 des donnée sur les capteurs suivants
- Horloge RTC DS1307 " I2C "
- Sonde DHT22 gérant " une serre dans la serre " ( mini serre )
- Sonde DHT22 gérant la serre principale
- Sonde barométrique " I2C "
- Sonde DFRobots SEN0390 " I2C "
Voici le montage
Pour l'affichage des écrans, j'utilise un multiplexer TCA9548A branché sur un shield Grove fixé sur une méga v3. Le shield m'offre 3 prises grove I2C.
Au jour d'aujourd'hui, j'arrive à afficher en lecture direct les deux sondes de température, la sonde barométrique qui gère un écran qui affiche des icones météo, l'horloge en temps réelle.
Le problème est le suivant, lorsque je branche ma sonde luxmètre SEN0390 sur le réseau I2C, l'affiche pour le texte et la valeur de retour fonctionnent sauf que la valeure renvoyé est " -1.00 "
J'ai remarqué que lorsque j'active ma sonde en SETUP
myLux.begin();
Après téléversement, tous mes écrans plantent et se figent.
J'ai testé la sonde SEN0390 seule sur la méga, j'ai un bon retour de valeur dans le moniteur série.
Voici mon code ou la sonde n'est pas activé dans le SETUP
[code]
/* -------------------------------- Déclaration OLED et TCA9548A ------------------------------------------------*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Select I2C BUS
void TCA9548A(uint8_t bus) {
Wire.beginTransmission(0x70);
Wire.write(1 << bus);
Wire.endTransmission();
Serial.print(bus);
}
/* ------------------------ Déclaration de la sonde DHT22 mini serre ------------------------------------*/
#include <DHT.h> // Appel de la bibliothèque DHT22
#define PINsonde_mini_serre 2 // sonde mini serre
#define DHTTYPE DHT22
DHT sonde_mini_serre(2, DHT22);
float temperature_mini_serre = sonde_mini_serre.readTemperature();
float humidite_mini_serre = sonde_mini_serre.readHumidity();
void lecture_temperature_mini_serre()
{
TCA9548A(1);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(2, 0); // Start at top-left corner
float temperature_mini_serre = sonde_mini_serre.readTemperature();
float h = sonde_mini_serre.readHumidity();
display.println("Mini serre");
display.setTextSize(3);
display.setCursor(0, 20);
display.print(temperature_mini_serre);
display.println(" C");
display.print(h);
display.print(" %");
display.display();
display.clearDisplay();
}
const int ventilateur_air_frais = 10;
const int ventilateur_air_sortie = 12;
/* ------------------------ Déclaration de la sonde DHT22 serre principale ------------------------------------*/
#include <DHT.h> // Appel de la bibliothèque DHT22
#define PINsonde_serre_principale 3 // sonde mini serre
#define DHTTYPE DHT22
DHT sonde_serre_principale(3, DHT22);
float temperature_serre_principale = sonde_serre_principale.readTemperature();
float humidite_serre_principale = sonde_serre_principale.readHumidity();
void lecture_temperature_serre_principale() {
TCA9548A(2);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(29, 0); // Start at top-left corner
float temperature_serre_principale = sonde_serre_principale.readTemperature();
float h = sonde_serre_principale.readHumidity();
display.println("Serre");
display.setTextSize(3);
display.setCursor(0, 20);
display.print(temperature_serre_principale);
display.println(" C");
display.print(h);
display.print(" %");
display.display();
display.clearDisplay();
}
/* ------------------------- Déclaration de l'horloge DS1307 -------------------------------*/
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
const int relais_brumisation = 5;
void printTime() {
TCA9548A(0);
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(19, 0); // Start at top-left corner
DateTime now = rtc.now();
display.print(now.hour(), DEC);
display.print(':');
display.print(now.minute(), DEC);
display.print(':');
display.print(now.second(), DEC);
display.println();
display.setCursor(13, 23); // Start at top-left corner
display.print(now.day(), DEC);
display.print('/');
display.print(now.month(), DEC);
display.print('/');
display.print(now.year(), DEC);
display.setCursor(19, 45); // Start at top-left corner
display.print(daysOfTheWeek[now.dayOfTheWeek()]);
display.display();
display.clearDisplay();
}
/* --------------------------------------------- Déclaration du baromètre ------------------------------------------------*/
#include "Ecran_icone.h"
#include <HP20x_dev.h>
#include "Arduino.h"
#include <KalmanFilter.h>
unsigned char ret = 0;
KalmanFilter t_filter; //temperature filter
KalmanFilter p_filter; //pressure filter
KalmanFilter a_filter;
void lecture_barometre() {
TCA9548A(3);
Serial.println("------------------\n");
long Temper = HP20x.ReadTemperature();
Serial.println("Temper:");
float t = Temper / 100.0;
Serial.print(t);
Serial.println("C.\n");
Serial.println("Filter:");
Serial.print(t_filter.Filter(t));
Serial.println("C.\n");
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(18, 0); // Start at top-left corner
display.println("Pression");
long Pressure = HP20x.ReadPressure();
t = Pressure / 100.0;
display.setTextSize(3); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 20); // Start at top-left corner
display.print(t);
display.setTextSize(2);
display.setCursor(40, 50);
display.println("hPa\n");
display.display();
display.clearDisplay();
}
long lecture_icones_meteo()
{
TCA9548A(4);
display.clearDisplay();
KalmanFilter t_filter; //temperature filter
KalmanFilter p_filter; //pressure filter
KalmanFilter a_filter;
Serial.println("------------------\n");
long Temper = HP20x.ReadTemperature();
Serial.println("Temper:");
float t = Temper / 100.0;
Serial.print(t);
Serial.println("C.\n");
Serial.println("Filter:");
Serial.print(t_filter.Filter(t));
Serial.println("C.\n");
long Pressure = HP20x.ReadPressure();
t = Pressure / 100.0;
if (t >= 960.00 && t <= 989.99) {
int16_t positionImageAxeHorizontal = 00; // Position de la gauche de l’image à 20 pixels du bord gauche de l’écran
int16_t positionImageAxeVertical = 00; // Position du haut de l’image à 16 pixels du bord haut de l’écran OLED
int16_t largeurDeLimage = 128; // Largeur de l’image à afficher : 64 pixels
int16_t hauteurDeLimage = 64; // Hauteur de l’image à afficher : 64 pixels
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, Orage, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
}
if (t >= 990.00 && t <= 1005.99) {
int16_t positionImageAxeHorizontal = 30; // Position de la gauche de l’image à 20 pixels du bord gauche de l’écran
int16_t positionImageAxeVertical = 00; // Position du haut de l’image à 16 pixels du bord haut de l’écran OLED
int16_t largeurDeLimage = 64; // Largeur de l’image à afficher : 64 pixels
int16_t hauteurDeLimage = 64; // Hauteur de l’image à afficher : 64 pixels
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, Pluie, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
}
if (t >= 1006.00 && t <= 1014.99) {
int16_t positionImageAxeHorizontal = 30; // Position de la gauche de l’image à 20 pixels du bord gauche de l’écran
int16_t positionImageAxeVertical = 00; // Position du haut de l’image à 16 pixels du bord haut de l’écran OLED
int16_t largeurDeLimage = 64; // Largeur de l’image à afficher : 64 pixels
int16_t hauteurDeLimage = 55; // Hauteur de l’image à afficher : 64 pixels
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, Nuage, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
}
if (t >= 1015.00 && t <= 1040.00) {
int16_t positionImageAxeHorizontal = 30; // Position de la gauche de l’image à 20 pixels du bord gauche de l’écran
int16_t positionImageAxeVertical = 00; // Position du haut de l’image à 16 pixels du bord haut de l’écran OLED
int16_t largeurDeLimage = 68; // Largeur de l’image à afficher : 64 pixels
int16_t hauteurDeLimage = 64; // Hauteur de l’image à afficher : 64 pixels
display.drawBitmap(positionImageAxeHorizontal, positionImageAxeVertical, Soleil, largeurDeLimage, hauteurDeLimage, WHITE);
display.display();
}
}
/* ---------------------------------------------- Déclaration de la sonde de luminosité ---------------------------------------------*/
#include <DFRobot_B_LUX_V30B.h>
DFRobot_B_LUX_V30B myLux(13, 21, 20);
void Lecture_luminosite() {
TCA9548A(6);
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(8, 00); // Start at top-left corner
display.print("Luminosite");
display.setCursor(30, 25);
display.print(myLux.lightStrengthLux());
display.setCursor(8, 48);
display.println(" Luxmetre");
display.display();
display.clearDisplay();
}
/* _______________________________________________________________________________ SETUP _________________________________________________________________________________________________________________*/
void setup() {
Serial.begin(115200);
Wire.begin(); // démarrage I2C
sonde_mini_serre.begin(); // démarrage de la sonde DHT22 mini serre
sonde_serre_principale.begin(); // démarrage de la sonde DHT22 serre principale
delay(150);
HP20x.begin();
/* ---------------------- Initialisation SETUP de l'horloge --------------------------------*/
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(2022, 1, 26, 22, 22, 31));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
TCA9548A(0); // démarrage de l'écran OLED du bus N°0
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(1); // démarrage de l'écran OLED du bus N°1
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(2); // démarrage de l'écran OLED du bus N°2
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(3); // démarrage de l'écran OLED du bus N°3
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(4); // démarrage de l'écran OLED du bus N°4
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(5); // démarrage de l'écran OLED du bus N°5
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(6); // démarrage de l'écran OLED du bus N°6
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
TCA9548A(7); // démarrage de l'écran OLED du bus N°7
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
// Ecriture sur l'écran OLED du bus N°5
TCA9548A(5);
display.clearDisplay();
display.setTextSize(8);
display.setTextColor(WHITE);
display.setCursor(45, 10);
// Display static text
display.println("5");
display.display();
display.clearDisplay();
// Ecriture sur l'écran OLED du bus N°7
TCA9548A(7);
display.clearDisplay();
display.setTextSize(8);
display.setTextColor(WHITE);
display.setCursor(45, 10);
// Display static text
display.println("7");
display.display();
display.clearDisplay();
lecture_temperature_mini_serre();
regulation_temperature_mini_serre();
}
void loop() {
printTime();
lecture_temperature_mini_serre();
lecture_temperature_serre_principale();
lecture_barometre();
lecture_icones_meteo();
Lecture_luminosite();
}
/*___________________________________________________________________________________________________________________________________________________________________________*/
/* -------------- FONCTIONS --------------*/
void regulation_temperature_mini_serre() {
/* ----------------- Ventilateurs d'entrée et sortie de la DHT22 mini serre -----------------*/
if (temperature_mini_serre >= 19.00 && temperature_mini_serre <= 21.98) { // vitesse venti1ateur 1
analogWrite (ventilateur_air_frais, 57);
analogWrite (ventilateur_air_sortie, 57);
}
if (temperature_mini_serre >= 21.99 && temperature_mini_serre <= 22.98) { // vitesse venti1ateur 2
analogWrite (ventilateur_air_frais, 97);
analogWrite (ventilateur_air_sortie, 97);
}
if (temperature_mini_serre >= 22.99 && temperature_mini_serre <= 23.98) { // vitesse venti1ateur 3
analogWrite (ventilateur_air_frais, 140);
analogWrite (ventilateur_air_sortie, 140);
}
if (temperature_mini_serre >= 23.99 && temperature_mini_serre <= 24.98) { // vitesse venti1ateur 4
analogWrite (ventilateur_air_frais, 187);
analogWrite (ventilateur_air_sortie, 187);
}
if (temperature_mini_serre >= 24.99 && temperature_mini_serre <= 25.98) { // vitesse venti1ateur 5
analogWrite (ventilateur_air_frais, 220);
analogWrite (ventilateur_air_sortie, 220);
}
if (temperature_mini_serre >= 25.99 && temperature_mini_serre <= 60.00) { // vitesse venti1ateur 6
analogWrite (ventilateur_air_frais, 250);
analogWrite (ventilateur_air_sortie, 250);
}
}
[/code]
Merci d'avance pour votre analyse.
Ludo