Преглед изворни кода

setup comprobador de sensores configurado

dacowars пре 2 недеља
родитељ
комит
806c804d22
1 измењених фајлова са 54 додато и 34 уклоњено
  1. 54 34
      V1/V1.ino

+ 54 - 34
V1/V1.ino

@@ -47,45 +47,71 @@ void ARDUINO_ISR_ATTR onTimer(void) {
 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
 void DHT_test() {
+  dht.begin();
   float h = dht.readHumidity();
   float t = dht.readTemperature();
   if (isnan(h) || isnan(t)) {
     Serial.println("Failed to read from DHT sensor!");
-    return;
+    OLED_print("DHT22", "Error");
+    while(1); // Detener si hay error
   }
-  Serial.print("Humidity: ");
-  Serial.print(h);
-  Serial.print(" %\t");
-  Serial.print("Temperature: ");
-  Serial.print(t);
-  Serial.println(" *C");
+  else OLED_print("DHT22", "Correcto");
 }
 
 void OLED_test() {  //pantallazo a blanco y luego iniciando
+  // Inicia I2C en pines default ESP32 (21 SDA, 22 SCL)
+  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Dirección común: 0x3C
+    Serial.println(F("Error: OLED no encontrado!"));
+    for (;;);  // Para siempre
+  }
   display.clearDisplay();
   display.fillScreen(SSD1306_WHITE); // Pantalla blanca
+  delay(500);
   display.display();
-  delay(5000);
   display.clearDisplay();
   display.setTextSize(2);         // Tamaño texto
   display.setTextColor(SSD1306_WHITE);
   display.setCursor(0, 0);        // Posición
-  display.println("¡Hola ESP32!");
-  display.println("OLED OK!");
+  display.println("Iniciando...");
   display.display();              // Muestra
   delay(1000);
 }
 
-void setup() {
-  Serial.begin(115200);
-
-  Serial.println(F("DHTxx test!"));
-  dht.begin();
+void OLED_print(const char* line1, const char* line2) {
+  display.clearDisplay();
+  display.setTextSize(1);
+  display.setTextColor(SSD1306_WHITE);
+  display.setCursor(0, 0);
+  display.println(line1);
+  display.println(line2);
+  display.display();
+}
 
-  Serial.println("Iniciando prueba de GPS con temporizador (API 3.x)...");
+void SD_test() {
+  if (!SD.begin()) {
+    Serial.println("SD Card Mount Failed");
+    OLED_print("SD Card", "Error");
+    while(1); // Detener si hay error
+  } 
+  else OLED_print("SD Card", "Correcto");
+}
 
+void GPS_test_wait() {
   // Iniciar Serial2 para GPS
   gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RX_PIN, TX_PIN);
+  while ((gpsSerial.available() > 0) && !gps.location.isValid()) {
+    gps.encode(gpsSerial.read());
+    delay(10);
+    OLED_print("GPS", "Esperando.");
+    OLED_print("GPS", "Esperando..");
+    OLED_print("GPS", "Esperando...");
+  }
+  OLED_print("GPS", "Encontrado");
+}
+
+void setup() {
+  Serial.begin(115200);
+
 
   // Configurar temporizador hardware con frecuencia de 1 MHz (tick cada 1 us)
   hw_timer_t *timer = timerBegin(1000000);  // Frecuencia en Hz
@@ -96,35 +122,29 @@ void setup() {
   // Configurar alarma para 1 segundo (1,000,000 ticks), autoreload activado, unlimited
   timerAlarm(timer, 1000000, true, 0);
 
-    // Inicia I2C en pines default ESP32 (21 SDA, 22 SCL)
-  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Dirección común: 0x3C
-    Serial.println(F("Error: OLED no encontrado!"));
-    for (;;);  // Para siempre
-  }
-
-  display.clearDisplay();
-  display.setTextSize(2);         // Tamaño texto
-  display.setTextColor(SSD1306_WHITE);
-  display.setCursor(0, 0);        // Posición
-  display.println("¡Hola ESP32!");
-  display.println("OLED OK!");
-  display.display();              // Muestra
-  delay(1000);
-
   // SD Card initialization
   if (!SD.begin()) {
     Serial.println("SD Card Mount Failed");
   } else {
     Serial.println("SD Card Mounted");
   }
-
+  // OLED check
   OLED_test();
-
+  delay(500);
   // DHT check
   DHT_test();
+  delay(500);
+  // SD Card check
+  SD_test();
+  delay(500);
+  // GPS check
+  GPS_test_wait();
+  delay(2000);
 
 }
-//revisar toda esta parte, generada por copilot##########################################################
+
+
+
 void loop() {