Problem in reading the DHT11 sensor

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Problem in reading the DHT11 sensor

Post by Oderlando »

Hi. I set up my flowchart to show the humidity values, read by a DHT11 sensor, to be shown on a 7-digit 4-digit display. Flowcode simulation works, but does not work on Proteus. The proteus shows the display with a zero value. I noticed that for some reason the sensor is not being read because the variable "SampleSensor" returns a value of 1. Can anyone identify the error here? I've exhausted my possibilities and I've been thinking about it for days.
Attachments
Controle_Umidade.fcfx
(13.42 KiB) Downloaded 264 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Benj »

Hello,

Is the Proteus simulation of the DHT11 sensor known to work well?

I would test on actual hardware if you can to rule out any potential problems with the Proteus software.

Which version of Flowcode are you using? Can you post your project file so we can see if your maybe doing anything incorrectly?

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

I used this same hardware to simulate the proteus for reading an ADC and it worked perfectly. I do not think it's a proteus problem. The problem only arises when I try to read the DHT11 sensor. I'm sending the zipped proteus file. proteus showed no problems emulating DTH11 with another code
Attachments
Controlador_Umidade.zip
(16.65 KiB) Downloaded 300 times
Last edited by Oderlando on Fri Nov 23, 2018 1:00 pm, edited 1 time in total.

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

I am using version 7 of FlowCode

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Benj »

Hello,

v7 of Flowcode is known to work well with the DHT11, it could be that our code and the proteus code is just not getting on but in real life the code works fine with the sensor so this sounds like a Proteus problem to me.

I don't have access to the Proteus simulator so I cant try and replicate the problem here.

I suggest you rig up a real world micro with the DHT11 and see how you get on. Simulation is great but I wouldn't rely on it 100%.

Now if you tell me the real world code isn't working then that is something I can investigate for you.

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

Hi, Benj. I mounted the circuit according to the proteus simulation and recorded the microcontroller with the HEX file generated by FlowCode and the result of the circuit was the same as the one emulated by the proteus: the DHT11 sensor returns with value 1 (error). The value that was shown in the display was the one that was emulated by the proteus. I am sending the Flowcode flowchart and circuit diagram to the attached proteus. I hope you can help me. Thank you.
Attachments
FlowCode_Error.zip
(19.58 KiB) Downloaded 244 times
Last edited by Oderlando on Sun Nov 25, 2018 9:27 pm, edited 1 time in total.

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by mnf »

Hi Oderlando,

Try - the following code. I have it working here with a DHT11 sensor and it works AOK.

A couple of things - don't have the output in an interrupt routine. Interrupts are best kept as short as possible, not really the place for outputting to a display.
The DHT11 sensor is fairly slow - I've used a two second delay between readings.
I've output data to the UART - I don't have the same display as you..
dht11.fcfx
(11.45 KiB) Downloaded 315 times
Gives me:
Temp = 19.0
Humidity = 65.0
Sample = 0
Temp = 19.0
Humidity = 65.0
Sample = 0
(I'm using 'putty' as a terminal program)

Martin
Note - also that I use MCU pins to power the DHT11 - I never like jumper wires? - but the board I have has data at the 's' end, VCC as the centre pin and GND as the third pin - and I'd wired the DHT11 incorrectly in the first instance - so here the pins don't tally (and I had to use jumpers :-( )

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by mnf »

& a jumperless version:
PB250030.jpg
PB250030.jpg (191.67 KiB) Viewed 8323 times
This with the DHT11 pins at D4-D6 of the Arduino.
dht11.fcfx
(11.45 KiB) Downloaded 287 times
Modified for D4 as data D5 as VCC and D6 as Gnd

Martin

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

Hi ! I have a flow chart for the Atmega8. It worked well on proteus simulation. Probably works well in real life. I'm sending the flowchart and proteus file. I tried to modify the flowchart to work with PIC16F88 and I am not able to compile the file. Can you take a look at me? I could not identify the problem. I've been there a few days, but I've learned a lot so far. Thanks for all the help you have so far.
Attachments
Nova pasta (4).zip
(25.86 KiB) Downloaded 232 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by mnf »

Hi Oderlando,

- what errors are you getting. I've modified the file slightly (take a look at PriemBitovSimplified - you can index into your array much more simply) - what are you trying to accomplish here? read of the dht11 by bit-banging port A5?? Did you get things to work using the DHT11 component?

Also - see the comments in VivoD/H - I'm not sure why you are writing the digits to the display repeatedly rather than just once followed by a delay.

Please could you add some comments on what each macro is trying to do, and we'll try and help some more....
DHT11_Modified.fcfx
(31.88 KiB) Downloaded 225 times
Martin

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

I'm more lost than I imagined. I think I'll need some time to study FlowCode and then go back to doing projects :( I decided to use this diagram to read the DTH11 because the other diagram I sent here had a problem reading the sensor, but it ended up becoming even more complicated to follow this path.Can you take a look at the "FlowCode_Error" file and say what may be wrong? In Flowcode simulation it works fine but in real life the sensor is not read.I apologize for my lack of knowledge. I'll have to study a lot more :(

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Benj »

Hello,

Using your DHT11_16F88 program I get this error being generated by the compiler.
DHT11_16F88.c: 262: (1089) recursive function call to "_FCM_InitDat"
This basically means you have called a function which ends up calling itself and at a certain point you will run out of stack and the program will crash and become unpredictable or the microcontroller will reset.
it ended up becoming even more complicated to follow this path
I can see why, here is a potential call chain.

Main -> InitDat -> PriemBitov -> ProverkaCRC -> InitDat -> ....

So there is a recursive loop going on which needs to be resolved.

Ideally to keep things easy to follow and straightforward you should always return back to Main and avoid functions calling functions calling functions unless this helps the overall program flow. Move as many of the function calls as you can into Main and this will free up stack giving you more usable RAM.

Start off simple with the basics, test on the hardware as you're going and add to the functionality as you get things working. This is the best way to achieve the end goal in a timely manner.

Oderlando
Posts: 37
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problem in reading the DHT11 sensor

Post by Oderlando »

Thank you all for the help and support you have given me. I will continue the studies with the flowcode and gradually evolve with it. Thank you.

Post Reply