4

I'm currently searching for a possibility to get to know if there is power in a circuit with a Pin of the J8 Header (Pin 26). I bought a tutorial Book to a starter Kit and a huge Book about the raspberry Pi itself, but now I'm stuck. In both books they said it would be possible to detect by programming if there is a circuit running between a Pin and GND. How to do that, I've got no idea.

3 Answers 3

2

You read the GPIO. If there is a high voltage (3V3) it will read 1, if there is a low voltage (ground, 0V) it will read 0.

Pin 26 is (Broadcom) GPIO 7.

Ensure that you do not feed a voltage greater then 3V3 into a Pi GPIO. You will likely damage the GPIO and/or the Pi itself.

There are several Python GPIO libraries.

See http://elinux.org/RPi_GPIO_Code_Samples#Python

2
  • Just like this: GPIO.read(26)? Will this return 1 or 0? Aug 21, 2016 at 16:47
  • Yes, 1 or 0 will be returned (assuming read is the correct method for the library you want to use).
    – joan
    Aug 21, 2016 at 16:52
3
import RPi.GPIO as GPIO

GPIO.setup(26, 'output')

# Switch on
GPIO.output(26, GPIO.HIGH)

# To read the state
state = GPIO.input(26)
if state:
   print('on')
else:
   print('off')
1
  • I get the error : RuntimeError: You must setup() the GPIO channel firstRuntimeError: You must setup() the GPIO channel first Sep 17, 2022 at 14:15
1

It didn't work, but it might be the version, for python 2.6 or 3 this is working

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)

GPIO.output(26, GPIO.HIGH)

state = GPIO.input(26)
if state:
   print('on')
else:
   print('off')

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.