1

In my project I invoke a python script via node.js on my Rapberrypi B+ model and what the python script does is that it turns on the BCM GPIO ports as per the python arguments passed through the node.js

$>python my_gpio.py 27 1

where 27 is the pin no and 1 is the on/off state

#my_gpio.py code


import sys
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)


f= open("GPIO","a+")


pin = sys.argv[1]
gpin = int(sys.argv[1])
state = sys.argv[2]

GPIO.setup(gpin, GPIO.OUT)

if state == "1" :
    f.write("\nPIN " +pin + " is on "+ state )
    GPIO.output(gpin, GPIO.HIGH)

else:
    f.write("\nPIN " +pin + " is off "+ state)
    GPIO.output(gpin, GPIO.LOW)

f.close
print("Done")
sys.stdout.flush()

What my objective is that I want to keep my LED HIGH until next event from the node to turn it off or turn it on

  • Should I be worried of not using GPIO.cleanup()? If i use GPIO.cleanup it will turn of the LED right?
  • Will there be any issue if I execute the above code like this,
    $>python my_gpio.py 27 1
    $>python my_gpio.py 27 1
    ie, calling GPIO.output(gpin, GPIO.HIGH) on a GPIO.HIGH
  • What are the risk i should avoid, so that i wont fry my board?

1 Answer 1

1

I would have no concern at all. My pigpio Python module has no equivalent of the cleanup method.

As far as I am aware the only GPIO libraries which have a cleanup method are RPi.GPIO and RPIO.GPIO (which is based on RPi.GPIO).

If a GPIO is already in the state you command (high when you command high, low when you command low) the command is in effect a no operation. It does no harm (or good).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.