Someone could help me? I want to use dht11 with arduino and esp. Both will read data from dht11 the problem is that simultaneously cannot be done. So the solution will be to set one as a master and the other one as a slave. the control will be done like so... another wire from arduino pin->set as output ->esp pin->set as input. if wire == 1 then dht11 will be read by arduino if wire == 0 then esp will read dht. with some delay ofcourse. but the problem is that i dk how to stop the communication between one board and the sensor when the other board will read it. so does it not exist any conflict
2 Answers
Disclaimer:
I've never used an ESP chip based board I know almost nothing about them. I am going to assume that it works, in software terms, like an Arduino, and base my answer on Arduino code. If the esp chip works differently, you'll need to adapt my suggestion.
Try something like this:
Connect a GPIO line between the microcontrollers. Also connect that line - through a 10K resistor - to +5V.
Have both microcontrollers set up it's GPIO as an input.
(We'll call the GPIO pin on both microcontrollers the "DHT_available" line. It will be HIGH when the DHT sensor is not being used by the other controller.)
When one of the microcontrollers wants to read the DHT11, have it check the GPIO line. If it's HIGH switch the GPIO line to an output and pull it low, then take a reading. When the reading is complete, switch the GPIO line back to an input.
If the GPIO line is LOW, wait and check again.
Alternately you could attach each of the microcontroller's GPIO lines to interrupt handlers on a rising edge. Then have the interrupt handler set the GPIO line to an output, pull it to LOW, and set a flag that means "begin reading".
Have your loop function check the "begin reading" flag, and if true, trigger a read from the DHT, and once it's complete, set the GPIO back to an input.
With the first option, each microcontroller would need to poll the "DHT_available" line continuously until it goes HIGH before beginning reading.
With the second option, as soon as one of your microcontrollers is done taking a reading, it would stop pulling the communications line LOW, the other one's rising edge interrupt would fire, and the other one would immediately begin reading.
-
I don;t know how to write code for all of that stuff. i am a beginner in microcontrollers Commented Apr 13, 2019 at 2:13
-
So use 2 separate DHT11 sensors, one for each microcontroller. They're cheap.– Duncan CCommented Apr 13, 2019 at 12:19
Also.. i would see a problem there. Lets say so.. Sensor data. Gnd. Vcc uC 2560 uC Esp If sensor data is linked to both uC And use a line dht_available btween 2560 and esp to handle the uC reading.. then.. If dht_available == HIGH then 2560 read after switch dht line to Low If dht_available == LOW then esp read after reading dhtline》 HIGH But the sensor wil continue to send data to both.. regqrding the dhtline is high or low. I dk how to say to sensor.. if dhtline is LOW stop sending data to 2560 because is esp time to read.