Esp32 collegato a dht11

Ciao a tutti, ho collegato il sensore dht11 per la rilevazione della temperatura/umidita all'esp32 tramite l'ingresso gpio34.
Non viene rilevato, Esp32 non riceve nessun valore... mentre se lo collego ad un altro ingresso funziona perfettamente riceve i valori inviati dal sensore
Ho letto che gli ingressi dal gpio34 al gpio39 si possono usare solo come input come ho fatto..
ho provato a collegare una resistenza da 10k tra il gpio34 e il +3v3 ma niente non funziona..
Come mai?
Ne sapete qualcosa??

Metti il codice che stai utilizzando per fare le prove con i GPIO e ... tu sai vero che la tensione minima di alimentazione del DHT11, come da datasheet: DHT11.pdf (466.5 KB)

... è 3.5V e che quindi, molto probabilmente, con i 3.3V che fornisce il ESP32, può non funzionare correttamente ... :roll_eyes:

Guglielmo

... esatto, puoi seguire questa tabella :wink: :

Guglielmo

Ciao Guglielmo, come ho scritto se cambio ingresso funziona perfettamente
di conseguenza non credo che si l'alimentazione, nel datasheet del esp32 ho letto che i gpio34 al 39 devono essere utilizzati per input e basta.. se vuoi ti spedisco il codice ma secondo me non centra nulla perche come gia scritto se al dht11 cambio l'ingresso funzia

Ho seguito ben quella tabella
e dunque il gpio34 e' input

... funziona, togli il perfettamente, il datasheet parla chiaro ... spera solo che funzioni sempre "correttamente" (fuori specifiche) :wink:

Ripeto, metti comunque il programma che stai utilizzando per provare i GPIO e gli diamo un'occhiata :slight_smile:

Guglielmo

ATTENZIONE: REGOLAMENTO, punto 16.15, NON sono tollerate risposte se non in lingua Italiana o, perlomeno, con annessa la traduzione in Italiano. Risposte in linque diverse dall'Italiano saranno rimosse.

Guglielmo

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>
#include "DHT.h"
// ========================================

// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Sender" and "ESP32 Receiver" must use the same Wi-Fi channel.
#define CHANNEL 1

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2

// ======================================== DHT sensor settings (DHT11).
#define DHTPIN 34 //--> Defines the Digital Pin connected to the DHT11 sensor.
#define DHTTYPE DHT11 //--> Defines the type of DHT sensor used. Here used is the DHT11 sensor.
DHT dht11_sensor(DHTPIN, DHTTYPE); //--> Initialize DHT sensor.
// ========================================

// ======================================== REPLACE WITH THE MAC ADDRESS OF YOUR MASTER / RECEIVER / ESP32 RECEIVER.
// 78:21:84:9D:CB:84
uint8_t broadcastAddress[] = {0x78, 0x21, 0x84, 0x9D, 0xCB, 0x84};
// ========================================

// ======================================== Variable for millis / timer.
unsigned long previousMillis = 0;
const long interval = 5000;
// ========================================

// ======================================== Variables to accommodate the data to be sent.
String send_ID_Board = "#1";
float send_Temp;
int send_Humd;
String send_Status_Read_DHT11 = "";
// ========================================

// ======================================== Structure example to send data
// Must match the receiver structure
typedef struct struct_message_send {
String ID_Board;
float Temp;
int Humd;
String Status_Read_DHT11;
} struct_message_send;

struct_message_send send_Data; //--> Create a struct_message to send data.
// ========================================

// ________________________________________________________________________________ Callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
digitalWrite(ON_Board_LED, HIGH); //--> Turn on ON_Board_LED.
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
Serial.println(">>>>>");
digitalWrite(ON_Board_LED, LOW); //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ Subroutine to read and get data from the DHT11 sensor.
void read_and_get_DHT11_sensor_data() {
Serial.println();
Serial.println("-------------");
Serial.print("ESP32 ");
Serial.println(send_ID_Board);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

// Read temperature as Celsius (the default)
send_Temp = dht11_sensor.readTemperature();

// Read Humidity
send_Humd = dht11_sensor.readHumidity();

// Read temperature as Fahrenheit (isFahrenheit = true)
// float ft = dht11_sensor.readTemperature(true);

// Check if any reads failed.
if (isnan(send_Temp) || isnan(send_Humd)) {
Serial.println("Failed to read from DHT sensor!");
send_Temp = 0.00;
send_Humd = 0;
send_Status_Read_DHT11 = "FAILED";
} else {
send_Status_Read_DHT11 = "SUCCEED";
}

Serial.printf("Temperature : %.2f °C\n", send_Temp);
Serial.printf("Humidity : %d %%\n", send_Humd);
Serial.printf("Status Read DHT11 Sensor : %s\n", send_Status_Read_DHT11);
Serial.println("-------------");
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
// put your setup code here, to run once:

Serial.begin(115200);
Serial.println();

pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output
digitalWrite(ON_Board_LED, LOW); //--> Turn off Led On Board

WiFi.mode(WIFI_STA); //--> Set device as a Wi-Fi Station.

// ---------------------------------------- Set the Wi-Fi channel.
// "ESP32 Sender" and "ESP32 Receiver" must use the same Wi-Fi channel.

int cur_WIFIchannel = WiFi.channel();

if (cur_WIFIchannel != CHANNEL) {
//WiFi.printDiag(Serial); // Uncomment to verify channel number before
esp_wifi_set_promiscuous(true);
esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
esp_wifi_set_promiscuous(false);
//WiFi.printDiag(Serial); // Uncomment to verify channel change after
}

Serial.println("-------------");
Serial.print("Wi-Fi channel : ");
Serial.println(WiFi.channel());
Serial.println("-------------");
// ----------------------------------------

// ---------------------------------------- Init ESP-NOW
Serial.println("-------------");
Serial.println("Start initializing ESP-NOW...");
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
Serial.println("Restart ESP32...");
Serial.println("-------------");
delay(1000);
ESP.restart();
}
Serial.println("Initializing ESP-NOW was successful.");
Serial.println("-------------");
// ----------------------------------------

// ---------------------------------------- Once ESPNow is successfully Init, we will register for Send CB to get the status of Trasnmitted packet
Serial.println();
Serial.println("get the status of Trasnmitted packet");
esp_now_register_send_cb(OnDataSent);
// ----------------------------------------

// ---------------------------------------- Register Peer
Serial.println();
Serial.println("Register peer");
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.encrypt = false;
// ----------------------------------------

// ---------------------------------------- Add Peer
Serial.println();
Serial.println("-------------");
Serial.println("Starting to add Peers...");
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
Serial.println("-------------");
return;
}
Serial.println("Adding Peers was successful.");
Serial.println("-------------");
// ----------------------------------------

// ----------------------------------------
Serial.println();
Serial.println("Setting up the DHT sensor (DHT11).");
dht11_sensor.begin(); //--> Setting up the DHT sensor (DHT11).
// ----------------------------------------

Serial.println();
Serial.println("Waiting to start sending data to the Recipient...");
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID LOOP()
void loop() {
// put your main code here, to run repeatedly:

unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
read_and_get_DHT11_sensor_data();

send_Data.ID_Board = send_ID_Board;
send_Data.Temp = send_Temp;
send_Data.Humd = send_Humd;
send_Data.Status_Read_DHT11 = send_Status_Read_DHT11;
// ::::::::::::::::: 

Serial.println();
Serial.print(">>>>> ");
Serial.println("Send data");

// ::::::::::::::::: Send message via ESP-NOW
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &send_Data, sizeof(send_Data));
 
if (result == ESP_OK) {
  Serial.println("Sent with success");
}
else {
  Serial.println("Error sending the data");
}

}

}

@nicdaddy: ... come richiesto al punto 7 del succitato regolamento, per favore edita il tuo post qui sopra (quindi NON scrivendo un nuovo post, ma utilizzando il bottone a forma di piccola matita :pencil2: che si trova in basso del tuo post), seleziona la parte di codice e premi l'icona </> nella barra degli strumenti per contrassegnarla come codice. Inoltre, così com'è, non è molto leggibile ... assicurati di averlo correttamente indentato nell'IDE prima di inserirlo (questo lo si fa premendo ctrlT su un PC o cmd T su un Mac, sempre all'interno del IDE).

Grazie,

Guglielmo

P.S.: NON ho chiesto tutto il programma del con il DHT, ho chiesto il programmino con cui provi i GPIO per dire che non funzionano anche con una semplice resistenza !

per provarlo:

// ======================================== DHT sensor settings (DHT11).
#define DHTPIN 34 //--> Defines the Digital Pin connected to the DHT11 sensor.
#define DHTTYPE DHT11 //--> Defines the type of DHT sensor used. Here used is the DHT11 sensor.
DHT dht11_sensor(DHTPIN, DHTTYPE); //--> Initialize DHT sensor.
// ========================================

quando vado a leggere dht11_sensor leggo valori a zero,
mentre se utilizzo questo

// ======================================== DHT sensor settings (DHT11).
#define DHTPIN 33 //--> Defines the Digital Pin connected to the DHT11 sensor.
#define DHTTYPE DHT11 //--> Defines the type of DHT sensor used. Here used is the DHT11 sensor.
DHT dht11_sensor(DHTPIN, DHTTYPE); //--> Initialize DHT sensor.
// ========================================

quando vado a leggere dht11_sensor leggo i valori corretti

@nicdaddy: Ti ricordo che, purtroppo, fino a quando non sarà sistemato il codice del post #10, come richiesto sopra, nel rispetto del regolamento nessuno ti risponderà (eventuali risposte verrebbero temporaneamente nascoste), quindi ti consiglio di farla al più presto.

Guglielmo

DEVI sistemare il post #10 ... cosa non è chiero nel mio post #11 e #13 ??? :open_mouth:

Guglielmo

@nicdaddy: NON DEVI POSTARE NULLA DI NUOVO, DEVI CORREGGERE E SISTEMARE QUANTO GIA' POSTATO ... PIU' CHIARO COSI' ? ? ? ? ? ? ? ?

Guglielmo

ma scusa devo sriveri un nuovo codice per il solo dht11??
le info sono gia scritte, inizializzazione e print...
Un po' piu Easy!!!

su Guglie'

Visto che NON si riesce ad ottenere la correzione di quanto postato come CHIARAMENTE chiesto al post #11 (con tutte le indicazioni di come fare), il thread viene chiuso e quindi cancellato.

Si consiglia la creazione di un nuovo thread, pulito e nel rispetto del REGOLAMENTO. Grazie.

Guglielmo