Rchrd
(Richard Caldwell)
December 8, 2024, 6:46pm
1
The following line of code is throwing a GPIO not defined error!!
GPIO.output(PWR_LED, not GPIO.input(PWR_LED))'
As you can see I have defined the pin =number and set it up as as output.
Abort_In_Pin = 37
Dir_Pin = 18
Rdy_LED = 40
PWR_LED = 37
IntensitySelect_Pins = (32,26,24,22)
Buzzer_Pin =38
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Busy_Pin, GPIO.IN)
GPIO.setup(Run_Pin, GPIO.OUT)
GPIO.setup(Rdy_LED, GPIO.OUT)
GPIO.setup(PWR_LED, GPIO.OUT)
GPIO.setup(Toy_Sel_Pins, GPIO.OUT)
GPIO.setup(Abort_Out_Pin, GPIO.OUT)
So what could be wrong?
bschubert
(Brian Schubert)
December 8, 2024, 6:49pm
2
I don’t see where GPIO
is defined in that code. Are you missing an import for it? Maybe
import RPi.GPIO as GPIO
You need to import GPIO
or define it, e.g. from a function call, or as an instance of a class.
Hello,
I think that you accidently added the last apostrophe (or quote) '
by mistake.
Rchrd
(Richard Caldwell)
December 8, 2024, 7:06pm
5
Pual the extra apostrophe was a copy-paste error. The actual code does not have the extra apostrophe.
Yes, I have included the RPi.GPIO library.
import RPi.GPIO as GPIO
from time import sleep
Busy_Pin = 36
Run_Pin = 16
Toy_Sel_Pins = (8,10)
Abort_Out_Pin = 12
Abort_In_Pin = 37
Dir_Pin = 18
Rdy_LED = 40
PWR_LED = 37
Sorry, I did not include it in the original post.
All other GPIOs work as expected. It’s the only one not working throwing an error.
There is only one i
in import
. You have two.
Why do you have the same pin assigned to two variable names.
This is a no-no:
Abort_In_Pin = 37
PWR_LED = 37
Same pin, two masters.
Rchrd
(Richard Caldwell)
December 8, 2024, 7:28pm
8
Sticking head in the sand with a blushing face.
Paul, you are right. The Abort_In_Pin should be pin 35. not 37
Thank you for pointing out my bad typing.
Sorry, man. I didn’t want to have to do this. But you’ve got detention for the next two weeks.
1 Like