Jump to content

phyesix

Members
  • Posts

    1
  • Joined

  • Last visited

  1. 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: Thanks
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines