Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Asm file for a dht11/dht22 temp/humid sensor.

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
Does anyone have a link to an asm library or file for a pic 16 series to read the dht11/22 sensor?
I dont want to write bit bang code if I dont have to.
Also is the on board rc osc good enough or do I need an external xtal?
 
Last edited:
Cheers Eric, gonna print that out and suss out what it does.
Porting the code to 16 series shouldnt be difficult.
The only change I'd like to change is the 18mS delay, I wouldnt want to tie up the processor for that long so I'll adapt the software to return to the main program for enough interrupts to create the delay.
First Just making the thing read from the dht would be a great start.
 
Last edited:
First Just making the thing read from the dht would be a great start.

Hi,

Just don't expect the DHT11 humidity and temperature readings to be super accurate.

I bought a couple and compared them, the hum readings were 5% different and the temps 1 deg c different .
 
Well actually I'm not using the dht11, rather the dht22, the protocol is the same, its just that the temp value is signed because the '22 goes to -40 degrees, and its sposed to be more accurate than the '11.
 
Ok then, so I've adapted the code from pic 18 to pic 16, wasnt all that difficult, mplab assembles it ok.
I now have registers with integrals and decimals for both humidity and temperature, however the datasheet doesnt specify the format for these 4 bytes, are they bcd or hex, I'm guessing that bit 7 of the temperature integral is a sign bit so maybe the output is hex.
 
OK so O copied and pasted the example code on the specified link into my program, and I cant get it to work.
The code reads the first measurments from the dht which is 55% humididty and 25 degrees, then on every subsequent read it allways jumps to the timeout error routine.
I'm using a pic16f88 and osscon is setup to run at 4mc's, is the inbuilt osc nt accurate enough for these dht sensors, I'dve thought it would have been.
The only other thing is I modded the code a little as the 'f88 doesnt have an instruction movff, I had to replace that with 2 lines, so if the code is sensitive to the number of instructions then that might be the screwup, I'll check that now, then I'll try a 4 mc xtal.
 
Turns out the dht I got from china is dead, I get the same results when I downloaded a hex file from the net for a thermo/hygro display and tried the sensor with that and a different pic chip.
2 new sensors ordered.
I did find another example of asm that reads the dht, it looks well structured, but it uses one of timer modules(which would be usefull if I wnated to change the clock freq), which unfortunately in my project are all being used, so I'll stick with the above.
 
Last edited:
Hi,

I've used the Dht11 with a 4mhz internal osc without problems and the program, reading the sensor every 90 seocnd, has run for over a year.

Cannot see the extra instructions to convert the movff would make any difference.
Are you allowing 2 seconds between successive reads.
Assume you have still got the interrupts disabled during the routine.

Think I have got a F88 chip somewhere, if you want to post or pm your code I could try a live test on my dht11 sensor..
 
I think my code will work, as when I tried the dht with a known program that displays the humidity and temp on an lcd I get the same phony readings as my own code, making me think that the dht22 I have is defunct.

I thought the mods I did to the code would affect the timings as the code executes a loop controlled by a counter, therefore the number of lines within the loop are important as they are taken into account, and with me replacing one line of movff with 2 lines that will lengthen the loop time by a uS, probably not going to be an issue, but when I was trying to find why the code didnt work it was on my mind.

I have ordered a couple of replacement dht's, if my code doesnt work when they get here then yes I'll take up your offer of testing the code for me thanks.
 
Last edited:
Sussed it in the end.
It was a dead dht22, possibly I plugged it into the wishboard the wrong way round.
New dht11 sensor works well, I had to adjust the delay routines, it seems that built in rc oscs on pic chips like to run slow, I know the 'f628 has an osctune reg but I just fudged the delay constants till it worked.
I presume that the dht22 outputs a 2's complement value, setting bit 7 when the temperature is negative.
Thanks for your help chaps.
I'll still send you the code if you want to see how I've done it wp, my version creates error codes if theres a bombout for some reason within the pulse trai output.
 
Last edited:
Ok then so I got the software working well reading a dht11, even used the checksum byte all fine.
Till the dht22's came in the post today, plugged one in - checksum error, tried the other one that came today, the same.
Theres obviously a diffo bewteen the dht11 and the dht22.
 
Ok then so I got the software working well reading a dht11, even used the checksum byte all fine.
Till the dht22's came in the post today, plugged one in - checksum error, tried the other one that came today, the same.
Theres obviously a diffo bewteen the dht11 and the dht22.

Hi,

Looking at the datasheets the only possible difference in the data stream seems to be the 1ms opening low for the dht22 from the micro; its 18ms on the dht11.

Seems there are two versions of the DHT22, the Aosong AM2303; its noticable in its datasheet that it does not show or state it should have a pull up on the data line.

There is also the MaxDetect version, RHT03, its datasheet almost identical but shows a 1k pull up on the data line.
 
Thanks for your help wp, I dont think this time I'm helpable.

I have a dht11 working well, after I'd tweaked the timings, the '11 seems to be ok unlike the '22.

I cannot get the dht22 to work, I've tried the shorter request pulse and various pullups including none, and altered the timings.

I looked up on the net to see if others have used the dht22, and when I did that I found that loads have had trouble, saying things like the data sheet is a lie and timings are off by near 100%, making me think this sensor is pants (or should I say unuseable without an accurate datasheet), no wonder the better suppliers dont sell them.

I see there are files available for the arduino that do work.

I think these can go in the bin and I'll go get a dallas temp sensor and a discrete humidity sensor and go through the salt bath callibration procedure, I dont have time to mess about code breaking to get the sensor to work.
 
Last edited:
I'm interested in this since a while ago I started designing a super wizzbang multi-room temperature control system for my son's house (currently shelved), and looked at dht11's as the sensors (additional humidity info seeming appropriately wizzbang). Apart from what's been said above, what's the general consensus on these little blue sweeties? I mean sensors?
 
Hi,

Was not aware of such problems with the 22; and yes that would have been my last suggestion to look in the Arduino forum as a lot of folk seem to sell them.

Depends on what accuracy / use you need a humidity sensor for ? the 11 meets my needs, its just a general indicator.

If you want serious quality then perhaps look at the SHT11 sensors, the original ones made the DHT11s code look simple ! but they now produce a range with i2c bus - see the SHT20,21,25 on Farnells site.
Though accurate the downside is the price - but some of the SHT10 are around for under a tenner.
 
I'm interested in this since a while ago I started designing a super wizzbang multi-room temperature control system for my son's house (currently shelved), and looked at dht11's as the sensors (additional humidity info seeming appropriately wizzbang). Apart from what's been said above, what's the general consensus on these little blue sweeties? I mean sensors?

Have used the same dht11 for a couple of years now in a greenhouse enviroment - I only use it as a general indicator, the humidity part is not that accurate and neither is the temperature, I use a ntc or ds18b20 for good temp control.
 
Are they reasonably linear? I'm supposing if so I could add/subtract an offset for each one - it only needs to be accurate to within a degree within a fairly narrow range (from around 5 to 20-something degrees I'm guessing). I'm asking because I can't spend much money, but can take plenty of time, and dht11's are cheap.
 
Are they reasonably linear? I'm supposing if so I could add/subtract an offset for each one - it only needs to be accurate to within a degree within a fairly narrow range (from around 5 to 20-something degrees I'm guessing). I'm asking because I can't spend much money, but can take plenty of time, and dht11's are cheap.


Hi,

I purchased two dht11s and tested the humidity in a salt box which should be 75%, but they measured 80 and 85%.
No way of checking the humiditys lineararity.

On the temp side they were a degree or so out, but never checked their lineararity.

If you are not needing such accuaracy then yes you could probably do as you say and compensate in your program code.

The cheapest temp sensor with accuaracy down to 0.1c that I know of is the humble ntc.

The DS18B20 is also good and can be bought on ebay ready made in a steel case with a 3 mtr lead and connector for around £5
 
I'd advise you stay away from the dht22 throbs, unless you have a code sample you know works, or your using an arduino, if you try to get this thing working on a pic then I think you'll be banging your head on a wall for a while.

The dht11 on the other hand is behaving itself and provides a usefull reading probably as accurate as one of those mechanical wall hygrometers.

I dont know this for certain (but I might be finding out) however the dht sensors contain a ds18b20 as the temp sensor.

I can help you interface to a dht11 to a pic, if your coding in asm.
 
Status
Not open for further replies.

Latest threads

Back
Top