Jump to content

DHT11 Module and Orange PI Zero


phyesix

Recommended Posts

Hello everyone,
 
I need use gpio pins in my Orange Pi Zero. I found the pyA20 library: orangepi_PC_gpio_pyH3: https://github.com/duxingkei33/orangepi_PC_gpio_pyH3...
I bought the DHT11 sensor, but I could not get it to work in any way. Is there anyone working on this subject?
For example, my code block: 
 
#!/usr/bin/env python
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector
from time import sleep

def bin2dec(string_num):
    return str(int(string_num, 2))
   
data = []

#GPIO.setmode(GPIO.BCM)
PIN = port.PA6

gpio.init()
gpio.setcfg(PIN, gpio.OUTPUT)

gpio.output(PIN,gpio.HIGH)
sleep(0.025)
gpio.output(PIN,gpio.LOW)
sleep(0.02)

#gpio.setup(PIN, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setcfg(PIN, gpio.INPUT)
gpio.pullup(PIN, 0)
gpio.pullup(PIN, gpio.PULLDOWN)
gpio.pullup(PIN, gpio.PULLUP)

for i in range(0,500):
    data.append(gpio.input(PIN))
   
bit_count = 0
tmp = 0
count = 0
HumidityBit = ""
TemperatureBit = ""
crc = ""


try:
   while data[count] == 1:
      tmp = 1
      count = count + 1
        

   for i in range(0, 32):
      bit_count = 0
      
      while data[count] == 0:
         tmp = 1
         count = count + 1

      while data[count] == 1:
         bit_count = bit_count + 1
         count = count + 1

      if bit_count > 3:
         if i>=0 and i<8:
            HumidityBit = HumidityBit + "1"
         if i>=16 and i<24:
            TemperatureBit = TemperatureBit + "1"
      else:
         if i>=0 and i<8:
            HumidityBit = HumidityBit + "0"
         if i>=16 and i<24:
            TemperatureBit = TemperatureBit + "0"
            
except:
   print "ERR_RANGE"
   exit(0)

   
try:
   for i in range(0, 8):
      bit_count = 0
      
      while data[count] == 0:
         tmp = 1
         count = count + 1

      while data[count] == 1:
         bit_count = bit_count + 1
         count = count + 1

      if bit_count > 3:
         crc = crc + "1"
      else:
         crc = crc + "0"
except:
   print "ERR_RANGE"
   exit(0)
      
      
Humidity = bin2dec(HumidityBit)
Temperature = bin2dec(TemperatureBit)

if int(Humidity) + int(Temperature) - int(bin2dec(crc)) == 0:
   print Humidity
   print Temperature
else:
   print "ERR_CRC"

In the meantime, as in the following photo: 

 
HayYkr2.jpg
 
Thanks
Link to comment
Share on other sites

Hi,

 

I'm not fluent with pyA20 but I worked with DH11/DHT12 (before using onewire, si7201 or bme280 and never getting back)

 

I would remove all PULLUP or PULLDOWN from your code, Looking at the photo you don't use the bare sensor but an all-in-one -> I'm almost sure you already have an embedded pullup (between 1kΩ and 4kΩ so way better than the integrated ones) and you may also have a small decoupling cap as a bonus.

 

Did you try your pin with a simple led to check if you are using the good one ?

 

Back then I had a lot problem with the cpu speed, try to force a higher frequency (that will help all the sleeps to be more accurate) and try to kill all other daemon that you don't need.

Link to comment
Share on other sites

I am using various DHT sensors. The one in picture indeed does have internal resistor. You can see it when loot at actual circuit board part.

I have one running on Raspberry Pi Zero for now about a half of a year using Java JNI to C bridge.
The DHT-11 fails quite often on read even with the 5 rereads cycle, the Linux is just too unreliable for the correct input counting.

 

On Arduino like ESP8266 there is no multithreading and the timing is therefore more accurate than on Linux installations.

It would be better using 1Wire sensor like DSDB1820 although at least on Raspberry Pi the whole 1Wire buss takes a lot of the CPU power as it always scans for new instances of the sensors.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines