dacowars 1 місяць тому
коміт
0f5722219f

+ 80 - 0
Prueba DHT/V1/V1.ino

@@ -0,0 +1,80 @@
+// Example testing sketch for various DHT humidity/temperature sensors
+// Written by ladyada, public domain
+
+// REQUIRES the following Arduino libraries:
+// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
+// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
+
+#include "DHT.h"
+
+#define DHTPIN 4     // Digital pin connected to the DHT sensor
+// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
+// Pin 15 can work but DHT must be disconnected during program upload.
+
+// Uncomment whatever type you're using!
+//#define DHTTYPE DHT11   // DHT 11
+#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
+//#define DHTTYPE DHT21   // DHT 21 (AM2301)
+
+// Connect pin 1 (on the left) of the sensor to +5V
+// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
+// to 3.3V instead of 5V!
+// Connect pin 2 of the sensor to whatever your DHTPIN is
+// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
+// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
+// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
+
+// Initialize DHT sensor.
+// Note that older versions of this library took an optional third parameter to
+// tweak the timings for faster processors.  This parameter is no longer needed
+// as the current DHT reading algorithm adjusts itself to work on faster procs.
+DHT dht(DHTPIN, DHTTYPE);
+
+unsigned long Tini, Tfin;
+
+void setup() {
+  Serial.begin(9600);
+  Serial.println(F("DHTxx test!"));
+
+  dht.begin();
+}
+
+void loop() {
+  // Wait a few seconds between measurements.
+  delay(2000);
+  
+  // Reading temperature or humidity takes about 250 milliseconds!
+  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
+  Tini = millis();
+  float h = dht.readHumidity();
+  // Read temperature as Celsius (the default)
+  Serial.println(millis()-Tini);
+  float t = dht.readTemperature();
+  
+  // Read temperature as Fahrenheit (isFahrenheit = true)
+  float f = dht.readTemperature(true);
+
+  // Check if any reads failed and exit early (to try again).
+  if (isnan(h) || isnan(t) || isnan(f)) {
+    Serial.println(F("Failed to read from DHT sensor!"));
+    return;
+  }
+  
+  // Compute heat index in Fahrenheit (the default)
+  float hif = dht.computeHeatIndex(f, h);
+  // Compute heat index in Celsius (isFahreheit = false)
+  float hic = dht.computeHeatIndex(t, h, false);
+  
+
+  Serial.print(F("Humidity: "));
+  Serial.print(h);
+  Serial.print(F("%  Temperature: "));
+  Serial.print(t);
+  Serial.print(F("°C "));
+  Serial.print(f);
+  Serial.print(F("°F  Heat index: "));
+  Serial.print(hic);
+  Serial.print(F("°C "));
+  Serial.print(hif);
+  Serial.println(F("°F"));
+}

+ 43 - 0
Prueba GPS/Barrido_baudios_grok/Barrido_baudios_grok.ino

@@ -0,0 +1,43 @@
+#define RXD2 16
+#define TXD2 17
+HardwareSerial gpsSerial(2);
+
+void setup() {
+  Serial.begin(115200);
+  delay(2000);
+  Serial.println("\n=== BAUD SCANNER GPS NEO-6M ===");
+}
+
+void loop() {
+  int bauds[] = {4800, 9600, 19200, 38400, 57600, 115200};
+  for(int i = 0; i < 6; i++) {
+    int baud = bauds[i];
+    gpsSerial.end();
+    gpsSerial.begin(baud, SERIAL_8N1, RXD2, TXD2);
+    
+    Serial.print("🔍 Probando ");
+    Serial.print(baud);
+    Serial.print(" baud... ");
+    delay(1000);
+    
+    int dollars = 0;
+    unsigned long start = millis();
+    while(millis() - start < 3000) {  // 3 seg
+      if(gpsSerial.available()) {
+        char c = gpsSerial.read();
+        Serial.print(c);
+        if(c == '$') dollars++;
+        if(dollars >= 5) break;  // ¡Encontró NMEA!
+      }
+    }
+    Serial.println("\n---");
+    
+    if(dollars >= 3) {
+      Serial.println("🎉 *** ¡BAUD CORRECTO! Usa este: " + String(baud) + " ***");
+      Serial.println("Copia los datos NMEA arriba ^");
+      delay(10000);  // Pausa para leer
+    }
+  }
+  Serial.println("🔄 Reiniciando scan...\n");
+  delay(5000);
+}

+ 91 - 0
Prueba GPS/V1/V1.ino

@@ -0,0 +1,91 @@
+/*********
+  Código basado en tutoriales para ESP32 con NEO-6M GPS y temporizadores (API 3.x).
+  Utiliza interrupciones de temporizador para lecturas periódicas cada 1 segundo.
+  Imprime datos GPS parseados en el Monitor Serial.
+*********/
+
+#include <TinyGPSPlus.h>
+
+// Pines para UART2 (Serial2)
+#define RX_PIN 16  // RX del ESP32 conectado a TX del GPS
+#define TX_PIN 17  // TX del ESP32 conectado a RX del GPS
+#define GPS_BAUD 115200
+
+// Objeto TinyGPS++
+TinyGPSPlus gps;
+
+// Serial para GPS
+HardwareSerial gpsSerial(2);
+
+// Bandera volátil para interrupción
+volatile bool gpsFlag = false;
+int i =0;
+
+// Función ISR para el temporizador (debe ser ARDUINO_ISR_ATTR para ejecución rápida)
+void ARDUINO_ISR_ATTR onTimer(void) {
+  gpsFlag = true;  // Activa bandera para procesar GPS en el loop
+}
+
+void setup() {
+  // Iniciar Serial para depuración
+  Serial.begin(115200);
+  Serial.println("Iniciando prueba de GPS con temporizador (API 3.x)...");
+
+  // Iniciar Serial2 para GPS
+  gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RX_PIN, TX_PIN);
+
+  // Configurar temporizador hardware con frecuencia de 1 MHz (tick cada 1 us)
+  hw_timer_t *timer = timerBegin(1000000);  // Frecuencia en Hz
+  
+  // Adjuntar interrupción al temporizador
+  timerAttachInterrupt(timer, &onTimer);
+  
+  // Configurar alarma para 1 segundo (1,000,000 ticks), autoreload activado, unlimited
+  timerAlarm(timer, 1000000, true, 0);
+  
+  // No se necesita timerAlarmEnable; timerAlarm lo habilita automáticamente
+}
+
+void loop() {
+  // Procesar solo cuando la interrupción active la bandera
+  if (gpsFlag) {
+    // Leer y codificar datos disponibles del GPS
+    
+    while (gpsSerial.available() > 0) {
+      gps.encode(gpsSerial.read());
+    }
+    
+
+    // Mostrar información si hay datos actualizados
+    if (gps.location.isValid()) {
+      Serial.print("Latitud: ");
+      Serial.println(gps.location.lat(), 6);
+      Serial.print("Longitud: ");
+      Serial.println(gps.location.lng(), 6);
+      Serial.print("Altitud (m): ");
+      Serial.println(gps.altitude.meters());
+      Serial.print("Velocidad (km/h): ");
+      Serial.println(gps.speed.kmph());
+      Serial.print("Satélites: ");
+      Serial.println(gps.satellites.value());
+      Serial.print("HDOP (precisión): ");
+      Serial.println(gps.hdop.hdop());
+      Serial.print("Fecha/Hora UTC: ");
+      Serial.print(gps.date.year()); Serial.print("/");
+      Serial.print(gps.date.month()); Serial.print("/");
+      Serial.print(gps.date.day()); Serial.print(" ");
+      Serial.print(gps.time.hour()); Serial.print(":");
+      Serial.print(gps.time.minute()); Serial.print(":");
+      Serial.println(gps.time.second());
+      Serial.println("-------------------");
+    } else {
+      i++;
+      Serial.print("Esperando fix GPS...");
+      Serial.println(i);
+
+    }
+
+    // Resetear bandera
+    gpsFlag = false;
+  }
+}

+ 26 - 0
Prueba GPS/V2/V2/V2.ino

@@ -0,0 +1,26 @@
+#define RXD2 16
+#define TXD2 17
+
+#define GPS_BAUD 115200
+
+// Create an instance of the HardwareSerial class for Serial 2
+HardwareSerial gpsSerial(2);
+
+void setup(){
+  // Serial Monitor
+  Serial.begin(115200);
+  
+  // Start Serial 2 with the defined RX and TX pins and a baud rate of 9600
+  gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
+  Serial.println("Serial 2 started at 9600 baud rate");
+}
+
+void loop(){
+  while (gpsSerial.available() > 0){
+    // get the byte data from the GPS
+    char gpsData = gpsSerial.read();
+    Serial.print(gpsData);
+  }
+  delay(1000);
+  Serial.println("-------------------------------");
+}

+ 259 - 0
Prueba SD/V1/V1.ino

@@ -0,0 +1,259 @@
+/*
+ * pin 1 - not used          |  Micro SD card     |
+ * pin 2 - CS (SS)           |                   /
+ * pin 3 - DI (MOSI)         |                  |__
+ * pin 4 - VDD (3.3V)        |                    |
+ * pin 5 - SCK (SCLK)        | 8 7 6 5 4 3 2 1   /
+ * pin 6 - VSS (GND)         | ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄  /
+ * pin 7 - DO (MISO)         | ▀ ▀ █ ▀ █ ▀ ▀ ▀ |
+ * pin 8 - not used          |_________________|
+ *                             ║ ║ ║ ║ ║ ║ ║ ║
+ *                     ╔═══════╝ ║ ║ ║ ║ ║ ║ ╚═════════╗
+ *                     ║         ║ ║ ║ ║ ║ ╚══════╗    ║
+ *                     ║   ╔═════╝ ║ ║ ║ ╚═════╗  ║    ║
+ * Connections for     ║   ║   ╔═══╩═║═║═══╗   ║  ║    ║
+ * full-sized          ║   ║   ║   ╔═╝ ║   ║   ║  ║    ║
+ * SD card             ║   ║   ║   ║   ║   ║   ║  ║    ║
+ * Pin name         |  -  DO  VSS SCK VDD VSS DI CS    -  |
+ * SD pin number    |  8   7   6   5   4   3   2   1   9 /
+ *                  |                                  █/
+ *                  |__▍___▊___█___█___█___█___█___█___/
+ *
+ * Note:  The SPI pins can be manually configured by using `SPI.begin(sck, miso, mosi, cs).`
+ *        Alternatively, you can change the CS pin and use the other default settings by using `SD.begin(cs)`.
+ *
+ * +--------------+---------+-------+----------+----------+----------+----------+----------+
+ * | SPI Pin Name | ESP8266 | ESP32 | ESP32‑S2 | ESP32‑S3 | ESP32‑C3 | ESP32‑C6 | ESP32‑H2 |
+ * +==============+=========+=======+==========+==========+==========+==========+==========+
+ * | CS (SS)      | GPIO15  | GPIO5 | GPIO34   | GPIO10   | GPIO7    | GPIO18   | GPIO0    |
+ * +--------------+---------+-------+----------+----------+----------+----------+----------+
+ * | DI (MOSI)    | GPIO13  | GPIO23| GPIO35   | GPIO11   | GPIO6    | GPIO19   | GPIO25   |
+ * +--------------+---------+-------+----------+----------+----------+----------+----------+
+ * | DO (MISO)    | GPIO12  | GPIO19| GPIO37   | GPIO13   | GPIO5    | GPIO20   | GPIO11   |
+ * +--------------+---------+-------+----------+----------+----------+----------+----------+
+ * | SCK (SCLK)   | GPIO14  | GPIO18| GPIO36   | GPIO12   | GPIO4    | GPIO21   | GPIO10   |
+ * +--------------+---------+-------+----------+----------+----------+----------+----------+
+ *
+ * For more info see file README.md in this library or on URL:
+ * https://github.com/espressif/arduino-esp32/tree/master/libraries/SD
+ */
+
+#include "FS.h"
+#include "SD.h"
+#include "SPI.h"
+
+/*
+Uncomment and set up if you want to use custom pins for the SPI communication
+#define REASSIGN_PINS
+int sck = -1;
+int miso = -1;
+int mosi = -1;
+int cs = -1;
+*/
+
+void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
+  Serial.printf("Listing directory: %s\n", dirname);
+
+  File root = fs.open(dirname);
+  if (!root) {
+    Serial.println("Failed to open directory");
+    return;
+  }
+  if (!root.isDirectory()) {
+    Serial.println("Not a directory");
+    return;
+  }
+
+  File file = root.openNextFile();
+  while (file) {
+    if (file.isDirectory()) {
+      Serial.print("  DIR : ");
+      Serial.println(file.name());
+      if (levels) {
+        listDir(fs, file.path(), levels - 1);
+      }
+    } else {
+      Serial.print("  FILE: ");
+      Serial.print(file.name());
+      Serial.print("  SIZE: ");
+      Serial.println(file.size());
+    }
+    file = root.openNextFile();
+  }
+}
+
+void createDir(fs::FS &fs, const char *path) {
+  Serial.printf("Creating Dir: %s\n", path);
+  if (fs.mkdir(path)) {
+    Serial.println("Dir created");
+  } else {
+    Serial.println("mkdir failed");
+  }
+}
+
+void removeDir(fs::FS &fs, const char *path) {
+  Serial.printf("Removing Dir: %s\n", path);
+  if (fs.rmdir(path)) {
+    Serial.println("Dir removed");
+  } else {
+    Serial.println("rmdir failed");
+  }
+}
+
+void readFile(fs::FS &fs, const char *path) {
+  Serial.printf("Reading file: %s\n", path);
+
+  File file = fs.open(path);
+  if (!file) {
+    Serial.println("Failed to open file for reading");
+    return;
+  }
+
+  Serial.print("Read from file: ");
+  while (file.available()) {
+    Serial.write(file.read());
+  }
+  file.close();
+}
+
+void writeFile(fs::FS &fs, const char *path, const char *message) {
+  Serial.printf("Writing file: %s\n", path);
+
+  File file = fs.open(path, FILE_WRITE);
+  if (!file) {
+    Serial.println("Failed to open file for writing");
+    return;
+  }
+  if (file.print(message)) {
+    Serial.println("File written");
+  } else {
+    Serial.println("Write failed");
+  }
+  file.close();
+}
+
+void appendFile(fs::FS &fs, const char *path, const char *message) {
+  Serial.printf("Appending to file: %s\n", path);
+
+  File file = fs.open(path, FILE_APPEND);
+  if (!file) {
+    Serial.println("Failed to open file for appending");
+    return;
+  }
+  if (file.print(message)) {
+    Serial.println("Message appended");
+  } else {
+    Serial.println("Append failed");
+  }
+  file.close();
+}
+
+void renameFile(fs::FS &fs, const char *path1, const char *path2) {
+  Serial.printf("Renaming file %s to %s\n", path1, path2);
+  if (fs.rename(path1, path2)) {
+    Serial.println("File renamed");
+  } else {
+    Serial.println("Rename failed");
+  }
+}
+
+void deleteFile(fs::FS &fs, const char *path) {
+  Serial.printf("Deleting file: %s\n", path);
+  if (fs.remove(path)) {
+    Serial.println("File deleted");
+  } else {
+    Serial.println("Delete failed");
+  }
+}
+
+void testFileIO(fs::FS &fs, const char *path) {
+  File file = fs.open(path);
+  static uint8_t buf[512];
+  size_t len = 0;
+  uint32_t start = millis();
+  uint32_t end = start;
+  if (file) {
+    len = file.size();
+    size_t flen = len;
+    start = millis();
+    while (len) {
+      size_t toRead = len;
+      if (toRead > 512) {
+        toRead = 512;
+      }
+      file.read(buf, toRead);
+      len -= toRead;
+    }
+    end = millis() - start;
+    Serial.printf("%u bytes read for %lu ms\n", flen, end);
+    file.close();
+  } else {
+    Serial.println("Failed to open file for reading");
+  }
+
+  file = fs.open(path, FILE_WRITE);
+  if (!file) {
+    Serial.println("Failed to open file for writing");
+    return;
+  }
+
+  size_t i;
+  start = millis();
+  for (i = 0; i < 2048; i++) {
+    file.write(buf, 512);
+  }
+  end = millis() - start;
+  Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end);
+  file.close();
+}
+
+void setup() {
+  Serial.begin(115200);
+
+#ifdef REASSIGN_PINS
+  SPI.begin(sck, miso, mosi, cs);
+  if (!SD.begin(cs)) {
+#else
+  if (!SD.begin()) {
+#endif
+    Serial.println("Card Mount Failed");
+    return;
+  }
+  uint8_t cardType = SD.cardType();
+
+  if (cardType == CARD_NONE) {
+    Serial.println("No SD card attached");
+    return;
+  }
+
+  Serial.print("SD Card Type: ");
+  if (cardType == CARD_MMC) {
+    Serial.println("MMC");
+  } else if (cardType == CARD_SD) {
+    Serial.println("SDSC");
+  } else if (cardType == CARD_SDHC) {
+    Serial.println("SDHC");
+  } else {
+    Serial.println("UNKNOWN");
+  }
+
+  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
+  Serial.printf("SD Card Size: %lluMB\n", cardSize);
+
+  listDir(SD, "/", 0);
+  createDir(SD, "/mydir");
+  listDir(SD, "/", 0);
+  removeDir(SD, "/mydir");
+  listDir(SD, "/", 2);
+  writeFile(SD, "/hello.txt", "Hello ");
+  appendFile(SD, "/hello.txt", "World!\n");
+  readFile(SD, "/hello.txt");
+  deleteFile(SD, "/foo.txt");
+  renameFile(SD, "/hello.txt", "/foo.txt");
+  readFile(SD, "/foo.txt");
+  testFileIO(SD, "/test.txt");
+  Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
+  Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
+}
+
+void loop() {}

+ 44 - 0
Prueba pantalla/V1/V1.ino

@@ -0,0 +1,44 @@
+#include <Wire.h>
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1306.h>
+
+#define SCREEN_WIDTH 128  // Ancho píxeles
+#define SCREEN_HEIGHT 64  // Alto píxeles
+#define OLED_RESET -1     // Reset pin (no usado)
+
+Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
+
+void setup() {
+  Serial.begin(115200);  // Para debug en Monitor Serie
+
+  // 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);
+}
+
+void loop() {
+  // Animación simple: corazón parpadeante
+  display.clearDisplay();
+  display.setTextSize(1);
+  display.setCursor(0, 0);
+  display.println("¡Funciona!");
+  
+  display.drawRect(20, 32, 20,20,SSD1306_WHITE);  // Dibuja corazón en centro
+  display.display();
+  delay(500);
+  
+  display.fillRect(20, 32, 20,20, SSD1306_WHITE);  // Lleno
+  display.display();
+  delay(500);
+}