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.

DHT11 and PIC code

Status
Not open for further replies.
What are those
If you are going to continue with these one line questions that mean nothing, then I will wait until a specific understandable set of questions are asked!!

I am here to help you, but you seem to be going backwards...
 
I think i should stop more post and serach in google becuse point are creatd by people other.
Thanks bye
god bless every one no enenemy
 
Hello,
The code bin file are not understandable.
Code:
'8mhz+Xtal /8 off Attiny44 Fuse FF DF FF
'8mhz+Xtal /8 Attiny44 Fuse 7F DF FF
'8mhz intRC /8 off Attiny44 Fuse E2 DF FF
'8mhz intRC /8 Attiny44 Fuse 62 DF FF


DDRA = 0xff  'Port A all outputs, TrisA=0x00 for PIC
Define CLOCK_FREQUENCY = 8

Define SPI_CS_REG = PORTA  'Set up ports for SPI
Define SPI_CS_BIT = 5  'CS port
Define SPI_SCK_REG = PORTA
Define SPI_SCK_BIT = 4  'Clock
Define SPI_SDO_REG = PORTA
Define SPI_SDO_BIT = 6  'Data out
Symbol signal = PORTB.2  'port for DHT22 signal
Dim humin As Word  'Relative Humidity
Dim tempin As Word  'Temperature
Dim check As Byte  'used to calculate humidity and temp
Dim l As Byte  'calculated temp
Dim dew As Byte  'calculated humidity
Dim sign As Byte  'minus temperature
Dim hsign As Byte  'minus dewpoint
Dim c As Byte  'bit collector
Dim b(32) As Byte  'used to process data
Dim t As Byte  'temperature tens
Dim u As Byte  'temperature units
Dim th As Byte  'dew point tens
Dim uh As Byte  'dew point units
Dim bi As Byte  'bit in
Dim x As Byte  'calculation bit
SPIPrepare  'Set up 7 segment LEDs
SPICSOn
SPISend 0xfc  'Shutdown Mode
SPISend 0xff  'Normal
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xff  'Test On, All segments ON
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xfe  'Test Off
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xfa  'intensity
SPISend 0xf7  '13/32
SPICSOff
WaitMs 10
SPICSOn
SPISend 0x0b  'scan limit
SPISend 0x07  '7 Eight 7 segment LEDs
SPICSOff

loop:
WaitMs 1500  'wait for initial response from DHT22
DDRB.2 = 1  'data pin to output. TrisB.2 = 0 for PIC
signal = 0  'Start initiation of DHT22
WaitMs 2
signal = 1
WaitUs 30
DDRB.2 = 0  'set data pin to input. TrisB.2 = 1 for PIC

ServoIn PORTB.2, b(0)  'Wait for dht22 response
For c = 31 To 0 Step -1  'capture data stream humidity and temp.
ServoIn PORTB.2, b(c)
Next c
'Because of time limit all data is capured without processing.
For c = 31 To 0 Step -1  'process data 0 or 1
If b(c) > 7 Then b(c) = 1 Else b(c) = 0
Next c
For c = 7 To 0 Step -1  'process humidity HB
bi = c + 24
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
humin.HB = check
For c = 7 To 0 Step -1  'process humidity LB
bi = c + 16
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
humin.LB = check
For c = 7 To 0 Step -1  'process temp HB
bi = c + 8
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
tempin.HB = check
For c = 7 To 0 Step -1  'process temp LB
If b(c) = 1 Then check.c = 1 Else check.c = 0
Next c
tempin.LB = check
'Check for minus temperature
If tempin.HB > 127 Then sign = 0x01 Else sign = 0x00
If tempin.HB > 127 Then tempin.HB = tempin.HB - 0x80
'convert data to humidty and temp
tempin = tempin / 10
humin = humin / 10
dew = tempin - ((100 - humin) / 5)  'dewpoint
hsign = sign  'calculate Neg dewpoint + Pos temperature
If humin > 50 And tempin < 15 Then hsign = 0x01
If humin > 60 And tempin < 10 Then hsign = 0x01
If humin > 70 And tempin < 7 Then hsign = 0x01
If humin > 80 And tempin < 4 Then hsign = 0x01
If humin > 90 And tempin < 1 Then hsign = 0x01
If dew = 0 Then hsign = 0x00
t = tempin / 10  'Extract 10's
u = tempin Mod 10  'Extract unit's
th = dew / 10
uh = dew Mod 10
x = t  'convert temperature 10's for gosub look
Gosub look
t = l
If tempin < 10 Then t = 0x00
x = u
Gosub look
u = l
x = th
Gosub look
th = l
If dew < 10 Then th = 0x00
x = uh
Gosub look
uh = l

If th = 0 Then th = 0x00  'if tens = 0 set segment to Blank
If t = 0 Then t = 0x00
SPICSOn  'Start 7 segment LEDs
SPISend 0x09  'set decode mode
SPISend 0x00  'set to None, direct segment control
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000001  'D1
SPISend 0x0d  'c = Centigrade
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000010  'D2
SPISend uh  'hunit
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000011  'D3
SPISend th  'hten or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000100  'D4
SPISend hsign  '- or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000101  'D5
SPISend 0x0d  'c = Centigrade
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000110  'D6
SPISend u  'Units
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000111  'D7
SPISend t  'tens or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00001000  'D8
SPISend sign  '- or blank
SPICSOff
WaitMs 10
Goto loop
End                                             
look:  'convert 10's & units for direct segment control
l = LookUp(0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b), x
Return
 
Last edited by a moderator:
I think i should stop more post and serach in google becuse point are creatd by people other.
Thanks bye
god bless every one no enenemy

Probably should have googled first :p

Hello,
The code bin file are not understandable.

'8mhz+Xtal /8 off Attiny44 Fuse FF DF FF
'8mhz+Xtal /8 Attiny44 Fuse 7F DF FF
'8mhz intRC /8 off Attiny44 Fuse E2 DF FF
'8mhz intRC /8 Attiny44 Fuse 62 DF FF


DDRA = 0xff 'Port A all outputs, TrisA=0x00 for PIC
Define CLOCK_FREQUENCY = 8

Define SPI_CS_REG = PORTA 'Set up ports for SPI
Define SPI_CS_BIT = 5 'CS port
Define SPI_SCK_REG = PORTA
Define SPI_SCK_BIT = 4 'Clock
Define SPI_SDO_REG = PORTA
Define SPI_SDO_BIT = 6 'Data out
Symbol signal = PORTB.2 'port for DHT22 signal
Dim humin As Word 'Relative Humidity
Dim tempin As Word 'Temperature
Dim check As Byte 'used to calculate humidity and temp
Dim l As Byte 'calculated temp
Dim dew As Byte 'calculated humidity
Dim sign As Byte 'minus temperature
Dim hsign As Byte 'minus dewpoint
Dim c As Byte 'bit collector
Dim b(32) As Byte 'used to process data
Dim t As Byte 'temperature tens
Dim u As Byte 'temperature units
Dim th As Byte 'dew point tens
Dim uh As Byte 'dew point units
Dim bi As Byte 'bit in
Dim x As Byte 'calculation bit
SPIPrepare 'Set up 7 segment LEDs
SPICSOn
SPISend 0xfc 'Shutdown Mode
SPISend 0xff 'Normal
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xff 'Test On, All segments ON
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xfe 'Test Off
SPICSOff
WaitMs 10
SPICSOn
SPISend 0xfa 'intensity
SPISend 0xf7 '13/32
SPICSOff
WaitMs 10
SPICSOn
SPISend 0x0b 'scan limit
SPISend 0x07 '7 Eight 7 segment LEDs
SPICSOff

loop:
WaitMs 1500 'wait for initial response from DHT22
DDRB.2 = 1 'data pin to output. TrisB.2 = 0 for PIC
signal = 0 'Start initiation of DHT22
WaitMs 2
signal = 1
WaitUs 30
DDRB.2 = 0 'set data pin to input. TrisB.2 = 1 for PIC

ServoIn PORTB.2, b(0) 'Wait for dht22 response
For c = 31 To 0 Step -1 'capture data stream humidity and temp.
ServoIn PORTB.2, b(c)
Next c
'Because of time limit all data is capured without processing.
For c = 31 To 0 Step -1 'process data 0 or 1
If b(c) > 7 Then b(c) = 1 Else b(c) = 0
Next c
For c = 7 To 0 Step -1 'process humidity HB
bi = c + 24
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
humin.HB = check
For c = 7 To 0 Step -1 'process humidity LB
bi = c + 16
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
humin.LB = check
For c = 7 To 0 Step -1 'process temp HB
bi = c + 8
If b(bi) = 1 Then check.c = 1 Else check.c = 0
Next c
tempin.HB = check
For c = 7 To 0 Step -1 'process temp LB
If b(c) = 1 Then check.c = 1 Else check.c = 0
Next c
tempin.LB = check
'Check for minus temperature
If tempin.HB > 127 Then sign = 0x01 Else sign = 0x00
If tempin.HB > 127 Then tempin.HB = tempin.HB - 0x80
'convert data to humidty and temp
tempin = tempin / 10
humin = humin / 10
dew = tempin - ((100 - humin) / 5) 'dewpoint
hsign = sign 'calculate Neg dewpoint + Pos temperature
If humin > 50 And tempin < 15 Then hsign = 0x01
If humin > 60 And tempin < 10 Then hsign = 0x01
If humin > 70 And tempin < 7 Then hsign = 0x01
If humin > 80 And tempin < 4 Then hsign = 0x01
If humin > 90 And tempin < 1 Then hsign = 0x01
If dew = 0 Then hsign = 0x00
t = tempin / 10 'Extract 10's
u = tempin Mod 10 'Extract unit's
th = dew / 10
uh = dew Mod 10
x = t 'convert temperature 10's for gosub look
Gosub look
t = l
If tempin < 10 Then t = 0x00
x = u
Gosub look
u = l
x = th
Gosub look
th = l
If dew < 10 Then th = 0x00
x = uh
Gosub look
uh = l

If th = 0 Then th = 0x00 'if tens = 0 set segment to Blank
If t = 0 Then t = 0x00
SPICSOn 'Start 7 segment LEDs
SPISend 0x09 'set decode mode
SPISend 0x00 'set to None, direct segment control
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000001 'D1
SPISend 0x0d 'c = Centigrade
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000010 'D2
SPISend uh 'hunit
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000011 'D3
SPISend th 'hten or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000100 'D4
SPISend hsign '- or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000101 'D5
SPISend 0x0d 'c = Centigrade
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000110 'D6
SPISend u 'Units
SPICSOff
WaitMs 10
SPICSOn
SPISend %00000111 'D7
SPISend t 'tens or blank
SPICSOff
WaitMs 10
SPICSOn
SPISend %00001000 'D8
SPISend sign '- or blank
SPICSOff
WaitMs 10
Goto loop
End
look: 'convert 10's & units for direct segment control
l = LookUp(0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b), x
Return

That looks a bit like BASIC, but I have not used BASIC before. Also, PLEASE use code formatting. We have code tags here for a reason.
 
Hi Matt

Also, PLEASE use code formatting. We have code tags here for a reason

I have to say, I would have done exactly the same because I don't know about code tags either .. .. .

Would you be kind enough to enlighten me Pls ?

S
 
Code tags!!!! This is what I type...

upload_2015-8-10_13-37-54.png

The "code" tags can equal C, basic, text, PHP or many more... The "C" gives the C syntax highlighting ( colours )...
 
Code:
Define SPI_CS_REG = PORTA  'Set up ports for SPI
Define SPI_CS_BIT = 5  'CS port
Define SPI_SCK_REG = PORTA
Define SPI_SCK_BIT = 4  'Clock
Define SPI_SDO_REG = PORTA
Define SPI_SDO_BIT = 6  'Data out
Symbol signal = PORTB.2  'port for DHT22 signal
Dim humin As Word  'Relative Humidity
Dim tempin As Word  'Temperature
Dim check As Byte  'used to calculate humidity and temp
Dim l As Byte  'calculated temp
Dim dew As Byte  'calculated humidity
Dim sign As Byte  'minus temperature
Dim hsign As Byte  'minus dewpoint
Dim c As Byte  'bit collector
Dim b(32) As Byte  'used to process data
Dim t As Byte  'temperature tens
Dim u As Byte  'temperature units
Dim th As Byte  'dew point tens
Dim uh As Byte  'dew point units
Dim bi As Byte  'bit in
Dim x As Byte  'calculation bit
SPIPrepare  'Set up 7 segment LEDs

Did it work for me ?
 
Hey ... Eureka !!

Thanks very much .. .. .

You said that without moving your lips Matt !! :D

S
 
Sorry guys, didn't occur to me that people may be unaware of how it works.

I generally use the "insert" menu:

insert.png

code.png

window.png



You should be able to use the dropdown (that defaults to "General Code") to select your language. However, I just noticed it only offers the options for PHP and HTML, while it supports a lot of others. Wonder if this is a bug....?

Ian's method seems to be the most effective at this point.

matt
 
Ian, I think it's hopeless. This thread is going nowhere, just like every other thread Ritesh has started.

I still have not seen any effort whatsoever put forth from Ritesh to actually learn. Until he studies on his own and attempts to LEARN the material, rather than just stealing other peoples' projects and code, I feel like this is a lost cause.
 
Not entirely hopeless.... .. .. I learnt from both of you today .. .. TY :)

S

I didn't say it wouldn't be useful to people who read it (or participate). It's only useless to people who don't put forth any effort to understand the material (like the OP). :p
 
I think what Rittesh needs is help with actual code, not criticism of how he posts it. So far as I can tell, he is eking out a living doing what he does, and he wants to better his product. I can remember some of his experiments with PWM for a helicopter. It was really quite impressive for something held together with not much more than duct tape. I share Ian's concern, though, that he needs to put a few more words into his questions. Unfortunately, I cannot help with C.

John
 
I think what Rittesh needs is help with actual code, not criticism of how he posts it. So far as I can tell, he is eking out a living doing what he does, and he wants to better his product. I can remember some of his experiments with PWM for a helicopter. It was really quite impressive for something held together with not much more than duct tape. I share Ian's concern, though, that he needs to put a few more words into his questions. Unfortunately, I cannot help with C.

John
Ritesh is a victim of the language barrier.... When I read his posts several times I begin to see the difficulty of his posts.. If he just uses google translate, he can ask questions in his mother tongue and we will get a better jist!!!

Some of his code is pretty good, repetitive, but good enough.. I don't mind helping! As I have said before, the threads are helping others!!! He is definitely a trier!
 
Most of the code is copied and pasted from people who are trying to help him. I can understand the language barrier, but I see no "trying" on his part. If you ask him to explain his code step by step, I am willing to bet he will not be able to, since he simply took it from someone else.
 
The code is an exact copy of the Oshonsoft Basic File I posted in #7
Ok if you know nothing it's not easy to understand but it works so if you really do use Oshonsoft as per the Forum Name
it is a tool for understanding how to use the DHT11/22
Converting data from the DHT11/22 into a digital number isn't all that easy (well I didn't think so).
The hard bit was figuring out the datasheet explanation then capturing the data and converting it.
If KoolGuy really can program in "C" then I think he'd be better off studying the DHT11/22 data sheet then applying his "C" to it.
Although the whole thing is quite complicated, it uses the regular building blocks of programming.
If KoolGuy doesn't understand that, he really needs to go back to studying loops and passing variables.
The basic program is:
Capture the data (40 bits worth 32 if you don't want the Checksum
Separate data into 3 groups, Temp, Humidiy and Check sum.
Interrogate data for 0 or 1
Convert data into a value
Convert value into a format for 7 segment LED

Maybe Koolguy would prefer it if I learnt "C" and did it for him?
I think some of you are being too reasonable, If I want an explanation of how to program a device using Oshonsoft Basic
and I went to a Russian speaking site for Pascal, I wouldn't expect much sympathy or help.

As Derstrom8 says this thread is going nowhere it should have stopped at post #7
 
Last edited:
Question to the Moderators here.
What have you done to these posts? They aren't connected anymore.
Also it has been renamed to DHT11 PIC code. The code is for DHT22 and AVR I added comments for PIC users.
If I search for DHT22 from the main search window the thread does not come up.
The only way I can find the post is by going into My Content
The last time I looked the number of downloads of the code was about 60 so it looks like a lot of people found it useful.
Also about 50% of them came back for the modified version which does not have as many comments so again that suggests it was helpful to them.

I know Koolguy was the OP but I and I assume many other people learn from answers/suggestions given to other people.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top