Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8051

Beginners • I'm having some issue's and I hope someone Knows why??

$
0
0
I'm still very new to using Linux/Raspberry and I bought several Kits online so I could learn while doing... I run into error codes and have no clue why but this one is the worst I have seen so...

Code:

 from gpiozero import OutputDevice, InputDeviceimport timeclass DHT11():    MAX_DELAY_COUINT = 100    BIT_1_DELAY_COUNT = 10    BITS_LEN = 40    def __init__(self, pin, pull_up=False):        self._pin = pin        self._pull_up = pull_up    def read_data(self):        bit_count = 0        delay_count = 0        bits = ""        # -------------- send start --------------        gpio = OutputDevice(self._pin)        gpio.off()        time.sleep(0.02)        gpio.close()        gpio = InputDevice(self._pin, pull_up=self._pull_up)        # -------------- wait response --------------        while gpio.value == 1:            pass                # -------------- read data --------------        while bit_count < self.BITS_LEN:            while gpio.value == 0:                pass            # st = time.time()            while gpio.value == 1:                delay_count += 1                # break                if delay_count > self.MAX_DELAY_COUINT:                    break            if delay_count > self.BIT_1_DELAY_COUNT:                bits += "1"            else:                bits += "0"            delay_count = 0            bit_count += 1        # -------------- verify --------------        humidity_integer = int(bits[0:8], 2)        humidity_decimal = int(bits[8:16], 2)        temperature_integer = int(bits[16:24], 2)        temperature_decimal = int(bits[24:32], 2)        check_sum = int(bits[32:40], 2)        _sum = humidity_integer + humidity_decimal + temperature_integer + temperature_decimal        # print(bits)        # print(humidity_integer, humidity_decimal, temperature_integer, temperature_decimal)        # print(f'sum:{_sum}, check_sum:{check_sum}')        # print()        if check_sum != _sum:            humidity = 0.0            temperature = 0.0        else:            humidity = float(f'{humidity_integer}.{humidity_decimal}')            temperature = float(f'{temperature_integer}.{temperature_decimal}')        # -------------- return --------------        return humidity, temperatureif __name__ == '__main__':    dht11 = DHT11(17)    while True:        humidity, temperature = dht11.read_data()        print(f"{time.time():.3f}  temperature:{temperature}°C  humidity: {humidity}%")        time.sleep(2)
I get all these error's................

Code:

>>> %Run 2.2.3_DHT.pyTraceback (most recent call last):  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 411, in pin    pin = self.pins[info]KeyError: PinInfo(number=11, name='GPIO17', names=frozenset({'WPI0', 17, '17', 'BOARD11', 'BCM17', 'J8:11', 'GPIO17'}), pull='', row=6, col=1, interfaces=frozenset({'', 'gpio', 'spi', 'dpi', 'uart'}))During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/home/Krampapas/raphael-kit/python/2.2.3_DHT.py", line 79, in <module>    humidity, temperature = dht11.read_data()  File "/home/Krampapas/raphael-kit/python/2.2.3_DHT.py", line 21, in read_data    gpio = OutputDevice(self._pin)  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 108, in __call__    self = super().__call__(*args, **kwargs)  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", line 74, in __init__    super().__init__(pin, pin_factory=pin_factory)  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 75, in __init__    super().__init__(*args, **kwargs)  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 553, in __init__    pin = self.pin_factory.pin(pin)  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 413, in pin    pin = self.pin_class(self, info)  File "/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py", line 126, in __init__    lgpio.gpio_claim_input(  File "/usr/lib/python3/dist-packages/lgpio.py", line 755, in gpio_claim_input    return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))  File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i    raise error(error_text(v))lgpio.error: 'GPIO busy'>>> 
Is there something wrong with my Pi5 or is it in the code I downloaded this is a SunFounder Kit "Raphael" I believe.
Thank you for any Advice in advance.
Krampapas

Statistics: Posted by Krampapas — Mon Apr 28, 2025 8:01 pm



Viewing all articles
Browse latest Browse all 8051

Trending Articles