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).