def read(self): GPIO.setup(self.__pin,GPIO.OUT) # send initial high self.__send_and_sleep(GPIO.HIGH, 0.05) # pull down to low self.__send_and_sleep(GPIO.LOW, 0.02) # change to input using pull up GPIO.setup(self.__pin,GPIO.IN,GPIO.PUD_UP) # collect data into an array data = self.__collect_input() # parse lengths of all data pull up periods pull_up_lengths = self.__parse_data_pull_up_lengths(data) # if bit count mismatch, return error (4 byte data + 1 byte checksum) if len(pull_up_lengths) != 40: return DHTResult(DHTResult.ERR_MISSING_DATA, 0, 0) # calculate bits from lengths of the pull up periods bits = self.__calculate_bits(pull_up_lengths) print(bits) # we have the bits, calculate bytes the_bytes = self.__bits_to_bytes(bits) print(the_bytes) # calculate checksum and check checksum = self.__calculate_checksum(the_bytes) if the_bytes[4] != checksum: return DHTResult(DHTResult.ERR_CRC, 0, 0) # ok, we have valid data, return it return DHTResult(DHTResult.ERR_NO_ERROR, the_bytes[2], the_bytes[0])
except KeyboardInterrupt: print "Exit" GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit if __name__ == '__main__': #Riferimento ai GPIO per numero pin GPIO.setmode(GPIO.BOARD) #GPIO.setwarnings(False) RED = "J4.40" YELLOW = "J4.38" GREEN = "J4.36" GPIO.setup(RED, GPIO.OUT) GPIO.setup(YELLOW, GPIO.OUT) GPIO.setup(GREEN, GPIO.OUT) GPIO.output(RED, 0) GPIO.output(YELLOW, 0) GPIO.output(GREEN, 0) GPIO.pwm_export(0) GPIO.pwm_period(0, 20000000) main()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle() except KeyboardInterrupt: print "Exit" GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit if __name__ == '__main__': #Riferimento ai GPIO per numero pin GPIO.setmode(GPIO.BOARD) #GPIO.setwarnings(False) RED="J4.40" YELLOW="J4.38" GREEN="J4.36" GPIO.setup(RED, GPIO.OUT) GPIO.setup(YELLOW, GPIO.OUT) GPIO.setup(GREEN, GPIO.OUT) GPIO.output(RED, 0) GPIO.output(YELLOW, 0) GPIO.output(GREEN, 0) main()
error_eth = 1 print "" #*********************************************************************** # Test GPIO #*********************************************************************** print "Test GPIO" # Ciclo di scansione e test dei GPIO error_counter=0 for test in testlistPE20PE26: acmepins.setup(test[0],acmepins.OUT,0) acmepins.setup(test[1],acmepins.IN,0) if step == 1: print "%s -> %s" % (test[0],test[1]) print "test0=1" acmepins.output(test[0],1) if step == 1: raw_input("Press Enter") if acmepins.input(test[1])==0: print (color_warning + "%s=1 --> %s==1 ?" + color_normal) % (test[0],test[1]), print (color_warning + "Errore ! %s in corto verso massa oppure %s o %s a circuito aperto" + color_normal) % (test[1]) error_counter = error_counter + 1 if step == 1: raw_input(" Press Enter") acmepins.output(test[0],0) if step == 1:
# log all errors dp.addErrorHandler(error) # Start the Bot update_queue = updater.start_polling() try: # Run the bot until the you presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle() except KeyboardInterrupt: print "Exit" GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit if __name__ == '__main__': #Riferimento ai GPIO per numero pin GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) INFRAROSSO="J4.35" GPIO.setup(INFRAROSSO, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(INFRAROSSO, GPIO.RISING, pir_handler, 200) main()
dp.addErrorHandler(error) # Start the Bot update_queue = updater.start_polling() try: # Run the bot until the you presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle() except KeyboardInterrupt: print "Exit" GPIO.cleanup() # clean up GPIO on CTRL+C exit GPIO.cleanup() # clean up GPIO on normal exit if __name__ == '__main__': #Riferimento ai GPIO per numero pin GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) INFRAROSSO = "J4.35" GPIO.setup(INFRAROSSO, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(INFRAROSSO, GPIO.RISING, pir_handler, 200) main()