Quantcast
Viewing all articles
Browse latest Browse all 1234

Python • gpiozero.exc.GPIOPinInUse from imported module

Hi!

I´m still relatively new to phyton so there could be an easy answer to this question.

I´m making my first project that is (at least for me) a bit larger on my PI.

what i´m trying to do is import a module from where i check if a button is pushed into my "master"-module where i collect a bunch of results from different modules in i while loop to have it running 24/7.

when i import the module that has the button-code i get a

gpiozero.exc.GPIOPinInUse: pin 27 is already in use by <gpiozero.Button object on pin GPIO27, pull_up=True, is_active=False>

as soon as python executes

Code:

importlib.reload(GPIO_Door_And_Relays)
The simple way would be to move the

Code:

switch = Button("BCM27")
outside the while-loop but as the module is imported to another module´s while loop i don´t se how this can be done.

Does anyone have any ideas?

I don´t know if the code would be of use but here it is:

The module where the button is handeled (GPIO_Door_And_Relays) (the relay-part is still to come):

Code:

from gpiozero import Buttonswitch = Button("BCM27")if switch.is_pressed:    Door_Is_Open = True    print("Door is open")

The "Master"-module code (the parts that has something to do with the issue:

Code:

import GPIO_Door_And_Relaysimport importlibNew_Phase = Truetry:    while True:            importlib.reload(one_wire)                importlib.reload(Temp_And_hum_calc)             importlib.reload(GPIO_Door_And_Relays)            print ("GPIO_Door updated")            if GPIO_Door_And_Relays.Door_Is_Open == True:                 New_Phase = True


As i normally code in IEC 61131-3 (languages for PLC-programming) so i feel like I´m trying to learn how to walk different, doing something you know but just a bit off all the time.

Any ideas is welcome. As there will be alot more in the GPIO_Door_And_Relays-modules i don´t see it as a option to move everythong into the master-module unless its the last restort.

Best,

Martin

Statistics: Posted by Martin1234567 — Sat Jan 06, 2024 3:24 pm



Viewing all articles
Browse latest Browse all 1234

Trending Articles