Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: DHT11 anyone?

Re: DHT11 anyone? 8 years 2 months ago #8673

  • red_kooga
  • red_kooga's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 1
I have found a more recent version that works properly, it is working on an amicus board.
I have also got it working with oshonsoft basic with assembler if you are interested.

[proton filename=code.bas]'Declare Xtal 16 'declare xtal to give exact delays
Dim ip As Byte 'hi pulse from sensor
Dim temp As Byte
Dim hum As Byte
Dim chksm As Byte
Dim temp1 As Byte
Dim hum1 As Byte
Dim temp2 As Word
Dim hum2 As Word
Dim test As Byte
Dim i As Byte
DelayMS 1000 'give sensor time to settle
loop]
The following user(s) said Thank You: Graham Mitchell

Re: DHT11 anyone? 8 years 2 months ago #8682

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Thanks for the code, I'd never figured that one out!! I got one of the units being shipped now, will be a while... from China (but then again, what DOESNT come from there??).

Thanks again friend!
Andrew

Re: DHT11 anyone? 8 years 1 month ago #8833

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
The program cycles to "SENSOR NOT READY" and I never get any readings...
'18f25k22 blank with serial lcd out example

Device = 18F25K22



 Xtal = 16

 
 
Config_Start
MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled
   FOSC = INTIO67 ; Internal oscillator block, port function on RA6 and RA7
   'pLLCFG = On ; Oscillator multiplied by 4
   
Config_End



 OSCCON = %01110000;
 'OSCTUNE = %00100000;
 

   'All_Digital = true
   
 DelayMS 1500  

SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10   
SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["Program Start"]
DelayMS 1000
SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10

'Declare Xtal 16  'declare xtal to give exact delays
Dim ip As Byte  'hi pulse from sensor
Dim temp As Byte
Dim hum As Byte
Dim chksm As Byte
Dim temp1 As Byte
Dim hum1 As Byte
Dim temp2 As Word
Dim hum2 As Word
Dim test As Byte
Dim i As Byte
DelayMS 1000    'give sensor time to settle


loop:
chksm=0
TRISB.0 = 0     'portb o/p
PORTB.0=1        'make high
DelayMS 50    'wait for a while
PORTB.0=0:DelayMS 18 'send 18ms low
PORTB.0=1:DelayUS 30 'send 30us hi
ip = PulsIn PORTB.0,1  'wait for hi
If ip < 130 Then GoTo loop1  ' if < 80us loop
ip = 0
For i = 7 To 0 Step -1
ip = PulsIn PORTB.0,1  'recieve pulses from sensor
If ip >70 Then
SetBit hum,i
Else
ClearBit hum,i
EndIf
Next i
For i = 7 To 0 Step -1
ip = PulsIn PORTB.0,1  'recieve pulses from sensor
If ip >70 Then
SetBit hum1,i
Else
ClearBit hum1,i
EndIf
Next i
For i = 7 To 0 Step -1
ip = PulsIn PORTB.0,High  'recieve pulses from sensor
If ip >70 Then
SetBit temp,i
Else
ClearBit temp,i
EndIf
Next i
For i = 7 To 0 Step -1
ip = PulsIn PORTB.0,High  'recieve pulses from sensor
If ip >70 Then
SetBit temp1,i
Else
ClearBit temp1,i
EndIf
Next i
For i = 7 To 0 Step -1
ip = PulsIn PORTB.0,High
If ip >70 Then
SetBit chksm,i
Else
ClearBit chksm,i
EndIf
Next i
'HRSOut "check sum ",Dec chksm,13 ' = chksm -1   'fudge to correct mis-read?

SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["humidity ",Dec hum,".",Dec hum1,"%"]
 SerOut PORTC.4 , 84 , [$fe,$c0]
SerOut PORTC.4 , 84 , ["temp ",Dec temp,".",Dec temp1,"C"]

test = (temp1 + hum1 + hum + temp)
If chksm <> test Then 
 SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["error"]

EndIf


DelayMS 3000 'give sensor time to settle
GoTo loop


loop1:
 SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["SENSOR NOT READY"]
GoTo loop


Andrew

Re: DHT11 anyone? 8 years 1 month ago #8847

Given Red's success with the software, it would be worth having a look at your hardware setup. Double check the basics.. device type, pin out, power, wiring, run a quick LED flash program etc.


Without any TME to help with the fault finding, next best bet would be to see what exactly the PIC is detecting from the sensor.. Especially given how the program lands at "Loop1"

Re: DHT11 anyone? 8 years 1 month ago #8864

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
I hope to have time to look at it further today, Id like to look at the output through a scope. I didnt have a 5k so I used a 4.7k instead. I doubled checked the pinout on the DHT11 and the PIC.

I will post back with more info.
Andrew

Re: DHT11 anyone? 8 years 1 month ago #8868

  • be80be
  • be80be's Avatar
  • Offline
  • Senior Boarder
  • Posts: 79
  • Thanks received: 90
You have a pickit2 you watch it with it.


PICkit 2 Logic Analyzer Help
Time to create page: 0.282 seconds