3
votes

I'm trying to learn how to do some cool things with my Raspberry Pi. I am trying to run a NMOS transistor with the 3.3V gpio pin on my raspberry pi. I am pretty sure it is capable of 3.3V output, but i keep on getting an error. I checked my wiring and my code. I don't see any problems. Please take a look at my code below and let me know if you see anything wrong. Thanks!

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17,GPIO.OUT)
GPIO.output(17,GPIO.HIGH)
while True:
    input_state = GPIO.input(12)
    if input_state == False:
        #command for running 5v/3.3v output below
        GPIO.output(17,GPIO.LOW)
        time.sleep(3.5)
        GPIO.output(17,GPIO.HIGH)

I ran my script using "sudo python myscript.py". This is the error I keep getting:

GPIO.setup(17,GPIO.OUT) ValueError: The channel sent is invalid on a Raspberry Pi

3
Maybe take a look at APPENDIX 1. A TECHNICAL NOTE ON PIN NUMBERING. raspberrypi.org/documentation/usage/gpio. Hope that helps.dudeman

3 Answers

5
votes

http://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/

Check out the section "Pin Numbering". You can either number the GPIOs according to the pin that's on the chip that contains the GPIO (the BCM numbering), or the number that's on the pin header you connect to (the BOARD). If you want GPIO17, that's the BCM pin number and it's pin 11 on the board header. You don't want board pin 17, because that is not a controllable output; it's the 3.3V supply.

GPIO.setmode(GPIO.BOARD)
# or
GPIO.setmode(GPIO.BCM)
0
votes

Why not use 2 (5.0v) instead of 17 and using an LM1117T 3.3v Regulator with a Pi-T breakout board on a breadboard. By connecting positive and negative, and two 10uF Capacitors, you should be able to receive a 3.3v output with pin 2

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12,GPIO.IN)
GPIO.setup(2,GPIO.OUT)
GPIO.output(2,GPIO.HIGH)
while True:
    input_state = GPIO.input(12)
    if input_state == False:
    GPIO.output(2,GPIO.LOW)
    time.sleep(3.5)
    GPIO.output(2,GPIO.HIGH)
0
votes

In one of the cases it might be that in one of the libraries, which are in-use the mode was already set to BCM or BOARD.

Then I had to find out the mode previously in use and to stick with that mode.

I also to avoid using: GPIO.cleanup() or re-setting GPIO.setmode()