Problemas con los sensores digitales y analógicos en la conexion inmediata usando el esp32 ttgo sim7600g

Hola amigos, tengo un problema con la esp32 ttgo sim7600g usando los sensores dht22, tengo errores al momento de iniciar la tarjeta. Cuando el programa corre en ocasiones parece q los sensores se desconectaran mandando 200 de humedad y 0 de temperatura, pero en otras ocasiones se conecta con normalidad. ¿Alguna sugerencia? , algo q tambien tengo problemas es en el adc, ya que varía mucho según lo que leí el esp32 es un pésimo lector y pues la variación es mucho casi no lee y en ocasiones es como si se desconectara también.

#define BLYNK_TEMPLATE_ID "XXXXXXXXXXXXXXX"
#define BLYNK_TEMPLATE_NAME "XXXXXXXXXXXXXXXXXXXXX"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXXXXXXX"

// Select your modem:
#define TINY_GSM_MODEM_SIM7600

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1

// See all AT commands, if wanted
#define DUMP_AT_COMMANDS

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
#define BLYNK_HEARTBEAT 70

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

#include <Arduino.h>
#include <Wire.h>

#include <SPI.h>
#include <SD.h>

BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "";
char user[] = "";
char pass[] = "";

#define SerialAT Serial1
#define UART_BAUD           115200

#define MODEM_TX            27
#define MODEM_RX            26
#define MODEM_PWRKEY        4
#define MODEM_DTR           32
#define MODEM_RI            33
#define MODEM_FLIGHT        25
#define MODEM_STATUS        34
#define BAT_ADC             35

#define SD_MISO             2
#define SD_MOSI             15
#define SD_SCLK             14
#define SD_CS               13

#define LED_PIN             12
bool reply = false;


//// sensores de humedad dht22
#include <DHT22.h>
#define pinDATA1 12 // SDA, or almost any other I/O pin
#define pinDATA2 13
DHT22 dht22a(pinDATA1); 
DHT22 dht22b(pinDATA2); 
//sensores de voltaje dc
#define bateria 34
#define panelsolar 33
//sensores voltaje ac
#define entradaAC 27
#include <ZMPT101B.h>
#define SENSITIVITY 454.5f
ZMPT101B voltageSensor(entradaAC, 50.0);
//sensores de corriente
#define corrSubminAC 32
#define corrPanelDC 39
//Syncing the output state with the app at startup

float getCorriente(uint32_t pin)
{
  float voltage;
  float corrienteSum = 0;
 
  voltage = analogRead(pin) * 3.3 / 4095.0;
  corrienteSum = (voltage - 2.5) / 0.066;
  
  return(corrienteSum );
}

float readvoltPanel(uint8_t pin)
{
  uint16_t volt = analogRead(pin);
  float voltage = (volt*70)/4096.0;
  return voltage;
}
float readvoltBatt(uint8_t pin)
{
  uint16_t volt = analogRead(pin);
  float voltage = (volt*24)/4096.0;
  return voltage;
}


BLYNK_CONNECTED()
{
    Blynk.syncVirtual(V0);  // will cause BLYNK_WRITE(V3) to be executed
    delay(200);
    Blynk.syncVirtual(V1);
    delay(200);
    Blynk.syncVirtual(V2);
    delay(200);
    Blynk.syncVirtual(V3);
    delay(200);
    Blynk.syncVirtual(V4);
    delay(200);
    Blynk.syncVirtual(V5);
    delay(200);
    Blynk.syncVirtual(V6);
    delay(200);
    Blynk.syncVirtual(V7);
    delay(200);
    Blynk.syncVirtual(V8);
    delay(200);
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
    float temp1 = dht22a.getTemperature();
    delay(200);
    float temp2 = dht22b.getTemperature();
    delay(200);
    float hum1 = dht22a.getHumidity();
    delay(200);
    float hum2 = dht22b.getHumidity();
    delay(200);
    float VPanel = readvoltPanel(panelsolar);
    delay(200);
    float VBatt = readvoltBatt(bateria);
    delay(200);
    float CoPanel = getCorriente(corrPanelDC);
    delay(200);
    float cototalSubAC = getCorriente(corrSubminAC);
    delay(200);

    Blynk.virtualWrite(V0, temp1);
    delay(200);
    Blynk.virtualWrite(V1, hum1);
    delay(200);
    Blynk.virtualWrite(V2, temp2);
    delay(200);
    Blynk.virtualWrite(V3, hum2);
    delay(200);
    Blynk.virtualWrite(V4,VBatt);
    delay(200);
    Blynk.virtualWrite(V5,CoPanel);
    delay(200);
    Blynk.virtualWrite(V6,VPanel);
    delay(200);     
    Blynk.virtualWrite(V8,cototalSubAC); 
   
}

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif


void setup()
{
    // Set console baud rate
    SerialMon.begin(115200);
    delay(10);
    voltageSensor.setSensitivity(SENSITIVITY);
    // Set GSM module baud rate
    SerialAT.begin(UART_BAUD, SERIAL_8N1, MODEM_RX, MODEM_TX);

    /*
      The indicator light of the board can be controlled
    */
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, HIGH);

    /*
      MODEM_PWRKEY IO:4 The power-on signal of the modulator must be given to it,
      otherwise the modulator will not reply when the command is sent
    */
    pinMode(MODEM_PWRKEY, OUTPUT);
    digitalWrite(MODEM_PWRKEY, HIGH);
    delay(300); //Need delay
    digitalWrite(MODEM_PWRKEY, LOW);

    /*
      MODEM_FLIGHT IO:25 Modulator flight mode control,
      need to enable modulator, this pin must be set to high
    */
    pinMode(MODEM_FLIGHT, OUTPUT);
    digitalWrite(MODEM_FLIGHT, HIGH);

    //Initialize SDCard
    SPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
    if (!SD.begin(SD_CS)) {
        Serial.println("SDCard MOUNT FAIL");
    } else {
        uint32_t cardSize = SD.cardSize() / (1024 * 1024);
        String str = "SDCard Size: " + String(cardSize) + "MB";
        Serial.println(str);
    }



    // Restart takes quite some time
    // To skip it, call init() instead of restart()
    Serial.println("Initializing modem...");
    if (!modem.restart()) {
        Serial.println("Failed to restart modem, attempting to continue without restarting");
    }

    String name = modem.getModemName();
    delay(500);
    Serial.println("Modem Name: " + name);

    Blynk.begin(auth, modem, apn, user, pass);
    // Setup a function to be called every second
    delay(5000);
    timer.setInterval(5000L, sendSensor);
}

void loop()
{
  
  
  Blynk.run();
  timer.run();
  BLYNK_CONNECTED();

}

Sensores que estoy usando: DHT22 X2(pin 12 y 13), sensor acs712 de 30A x2 pin(32 y 39), sensor de voltaje elaboración propia por divisor de voltaje para 24v y 70v(pin 34,33), sensor de voltaje alterno ZMPT101(no estoy usando ya no tengo entradas adc al parecer al igual que el wifi los adc1 del esp32 se desactivan o existe una mala interacción por lo que solamente estoy usando el adc0).

He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español @israsho.

En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.

De antemano, muchas gracias por cooperar.

1 Like

Probaste los DHT22 individualmente y luego juntos? Ese código con 200 mseg entre lectura y lectura no puede funcionar porque el DHT22 requiere 2000 mseg entre lecturas.
Asi que lee uno, completo, espera 2 seg y lee el otro completo.

1 Like

Gracias no sabía esa parte, pero lee normal te cuento le puse un delay de 3 segundos en cada loop y normal talvez sea otra como el pin 12 que otros tienen problema con ese pin. Lo probé en un atmega y todo normal, lo reinicie, desconecte, le quite la energía y todo normal sin problemas, talvez sea algo con la tarjeta y el sim7600G

Te funciona porque la librería está bien hecha y si no pasaron 2 segundos devuelve el último valor leído. Recién pasados 2 devuelve una nueva lectura.

1 Like

Gracias por responder, entonces debo poner un delay en cada lectura de dos segundos aproximadamente para la lectura de humedad y temperatura o solo entre sensores?

Por otro lado, leí un poco más de los pines y al parecer el pin 12 el q estoy usando para el dht22 tiene un inconveniente, dice: Debe ser LOW al arrancar
Debug JTAG. Cambiare de pin talvez con eso se resuelva

El tiempo de 2 segundos es entre lecturas de un mismo sensor, en cada lectura obtienes ambas mediciones.

A riesgo de ser reiterativo:
Qué parte no se entiende de Lee 1 completo y luego lee el otro completo
Y no uses el pin 12, tienes una serie de pines, si alguno tiene restricción simplemente usa otro.
Tengo el mismo board. mañana veré si lo pruebo a ver.

1 Like

Buenas tardes amiwos, tengo un problema cada vez que existe un corte de luz o desconexión en mi esp32 tengo que ir y quitar mi tierra para luego reiniciar y que vuelva a funcionar. En mi alimentación están mis 8 sensores por lo que opte en hacerlos funcionar con una fuente externa y esta fuente debe compartir tierra con mi esp32. ¿Existe alguna forma de corregirlo ya sea por código o la implementación de algún circuito?

#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxx"

// Select your modem:
#define TINY_GSM_MODEM_SIM7600

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1

// See all AT commands, if wanted
#define DUMP_AT_COMMANDS

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
#define BLYNK_HEARTBEAT 70

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

#include <Arduino.h>
#include <Wire.h>

#include <SPI.h>
#include <SD.h>

BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "";
char user[] = "";
char pass[] = "";

#define SerialAT Serial1
#define UART_BAUD           115200

#define MODEM_TX            27
#define MODEM_RX            26
#define MODEM_PWRKEY        4
#define MODEM_DTR           32
#define MODEM_RI            33
#define MODEM_FLIGHT        25
#define MODEM_STATUS        34
#define BAT_ADC             35

#define SD_MISO             2
#define SD_MOSI             15
#define SD_SCLK             14
#define SD_CS               13

#define LED_PIN             12
bool reply = false;


//// sensores de humedad dht22
#include <DHT22.h>
#define pinDATA1 14 // SDA, or almost any other I/O pin
#define pinDATA2 15
DHT22 dht22a(pinDATA1); 
DHT22 dht22b(pinDATA2); 
//sensores de voltaje dc
#define bateria 34
#define panelsolar 33
//sensores voltaje ac
#define entradaAC 27
#include <ZMPT101B.h>
#define SENSITIVITY 454.5f
ZMPT101B voltageSensor(entradaAC, 50.0);
//sensores de corriente
#define corrSubminAC 32
#define corrPanelDC 39
///////////////////////////////////
//filtro de media movil
#include "MeanFilterLib.h"
MeanFilter<float> meanFilter(10);
//Syncing the output state with the app at startup

float getCorriente(uint32_t pin)
{
  float rawvoltage;
  float corrienteSum = 0;
  float Measure;
  float salida;
  rawvoltage=analogRead(pin);
  Measure=meanFilter.AddValue(rawvoltage);
  salida = Measure * 3.3 / 4095.0;
  corrienteSum = (salida - 2.5) / 0.066;
  
  return(corrienteSum );
}

float readvoltPanel(uint8_t pin)
{
  float Measure;
  uint16_t volt = analogRead(pin);
  Measure=meanFilter.AddValue(volt);
  float voltage = (Measure*70)/4096.0;
  return voltage;
}
float readvoltBatt(uint8_t pin)
{
  float Measure;
  uint16_t volt = analogRead(pin);
  Measure=meanFilter.AddValue(volt);
  float voltage = (Measure*24)/4096.0;
  return voltage;
}


BLYNK_CONNECTED()
{
    Blynk.syncVirtual(V0);  // will cause BLYNK_WRITE(V3) to be executed
    delay(200);
    Blynk.syncVirtual(V1);
    delay(200);
    Blynk.syncVirtual(V2);
    delay(200);
    Blynk.syncVirtual(V3);
    delay(200);
    Blynk.syncVirtual(V4);
    delay(200);
    Blynk.syncVirtual(V5);
    delay(200);
    Blynk.syncVirtual(V6);
    delay(200);
    Blynk.syncVirtual(V7);
    delay(200);
    Blynk.syncVirtual(V8);
    delay(200);
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{ 
    delay(300);
    float temp1 = dht22a.getTemperature();
    delay(200);
    float hum1 = dht22a.getHumidity();
    delay(3000);
    float temp2 = dht22b.getTemperature();
    delay(200);
    float hum2 = dht22b.getHumidity();
    delay(300);
    float VPanel = readvoltPanel(panelsolar);
    delay(300);
    float VBatt = readvoltBatt(bateria);
    delay(300);
    float CoPanel = getCorriente(corrPanelDC);
    delay(300);
    float cototalSubAC = getCorriente(corrSubminAC);
    delay(300);

    Blynk.virtualWrite(V0, temp1);
    delay(200);
    Blynk.virtualWrite(V1, hum1);
    delay(200);
    Blynk.virtualWrite(V2, temp2);
    delay(200);
    Blynk.virtualWrite(V3, hum2);
    delay(200);
    Blynk.virtualWrite(V4,VBatt);
    delay(200);
    Blynk.virtualWrite(V5,CoPanel);
    delay(200);
    Blynk.virtualWrite(V6,VPanel);
    delay(200);     
    Blynk.virtualWrite(V8,cototalSubAC); 
   
}

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif


void setup()
{
    // Set console baud rate
    SerialMon.begin(115200);
    delay(10);
    voltageSensor.setSensitivity(SENSITIVITY);
    // Set GSM module baud rate
    SerialAT.begin(UART_BAUD, SERIAL_8N1, MODEM_RX, MODEM_TX);

    /*
      The indicator light of the board can be controlled
    */
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, HIGH);

    /*
      MODEM_PWRKEY IO:4 The power-on signal of the modulator must be given to it,
      otherwise the modulator will not reply when the command is sent
    */
    pinMode(MODEM_PWRKEY, OUTPUT);
    digitalWrite(MODEM_PWRKEY, HIGH);
    delay(300); //Need delay
    digitalWrite(MODEM_PWRKEY, LOW);

    /*
      MODEM_FLIGHT IO:25 Modulator flight mode control,
      need to enable modulator, this pin must be set to high
    */
    pinMode(MODEM_FLIGHT, OUTPUT);
    digitalWrite(MODEM_FLIGHT, HIGH);

    //Initialize SDCard
    SPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
    if (!SD.begin(SD_CS)) {
        Serial.println("SDCard MOUNT FAIL");
    } else {
        uint32_t cardSize = SD.cardSize() / (1024 * 1024);
        String str = "SDCard Size: " + String(cardSize) + "MB";
        Serial.println(str);
    }



    // Restart takes quite some time
    // To skip it, call init() instead of restart()
    Serial.println("Initializing modem...");
    if (!modem.restart()) {
        Serial.println("Failed to restart modem, attempting to continue without restarting");
    }

    String name = modem.getModemName();
    delay(500);
    Serial.println("Modem Name: " + name);

    Blynk.begin(auth, modem, apn, user, pass);
    // Setup a function to be called every second
    delay(5000);
    timer.setInterval(5000L, sendSensor);
}

void loop()
{
  
  
  Blynk.run();
  timer.run();
  BLYNK_CONNECTED();
  
}

Mis conexiones para que entiendan mi situación.

No deberías tener ningún problema, la conexión es correcta y el código funciona sino no correría nunca.
Prueba poniendo un condensador (capacitor) de 10uF entre los pines Reset y GND del ESP32 a ver si ayuda en algo.

1 Like

Moderador
Mira tu privado.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.