I face a problem.

File B has import from gpiozero which controls LED. The default GPIO mode is a BCM. While in file A, it allows NFC reader to read card which imports MFRC522. However, MFRC522 gpio mode is set to BOARD.

I imported file B into file A. I called the function in file B. However when I attempt to run file A, it gave me this error.

Traceback (most recent call last):
File "NFC_Security.py", line 53, in <module>

File "/home/pi/Garage_Parking/rpi_components/LEDs.py", line 13, in 

greenLed = LED(6)  # Green LED lights up when the user is authorised
File "/usr/lib/python2.7/dist-packages/gpiozero/devices.py", line 134, in 
self = super(GPIOMeta, cls).__call__(*args, **kwargs)

File "/usr/lib/python2.7/dist-packages/gpiozero/output_devices.py", line 
131, in __init__ super(DigitalOutputDevice, self).__init__(pin, active_high, initial_value)

File "/usr/lib/python2.7/dist-packages/gpiozero/output_devices.py", line 41, in __init__
super(OutputDevice, self).__init__(pin)

File "/usr/lib/python2.7/dist-packages/gpiozero/mixins.py", line 69, in __init__
super(SourceMixin, self).__init__(*args, **kwargs)

File "/usr/lib/python2.7/dist-packages/gpiozero/devices.py", line 381, in __init__
pin = pin_factory(pin)

File "/usr/lib/python2.7/dist-packages/gpiozero/pins/rpigpio.py", line 82, in __new__

ValueError: A different mode has already been set!
Exception AttributeError: "'LED' object has no attribute '_controller'" in <bound method LED.__del__ of <gpiozero.LED object closed>> ignored

Is there any way I can overcome this error? How can I call the function in file B so that I can run it in file A? I appreciate a lot. Thank You.

  • You can't use both BOARD and BCM in one script. Calling BOARD sets the mode. You can't set the mode to BCM after that. It's probably best to rewrite file A to BOARD. – 88weighed Jun 18 '18 at 10:25
  • @88weighed, file A gpio mode is already Board. Do u have any ways to change mode in file B?? so that I can import in file A? – Sofia Jun 18 '18 at 10:40
  • I do not understand what you are doing. It seems like you are trying to use an RPi.GPIO script within a gpiozero script. Do not do that. That is like pasting C code into a FORTRAN program. – joan Jun 18 '18 at 10:41
  • @joan, Are there any alternative ways other than rewriting the code in file B? – Sofia Jun 18 '18 at 10:44
  • You probably need to rewrite the simpler LED script as the MFRC522 code is likely to be impenetrable to understanding. – joan Jun 18 '18 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.