0

When I try to toggle the Raspi pin no 40 using the code it gives me message

RuntimeWarning : The channel is already in use, continuing anways and asks to disable warnings. Even after doing GPIO.setwarnings(False), the warning doesn't pop but the port does not toggle at all. I had tested the RPI.GPIO library quite a while ago their was no problem, in toggling the ports.

#! /usr/bin/python import array import os import time import RPi.GPIO as GPIO def main(): GPIO.setmode(GPIO.BCM) GPIO.setup(40,GPIO.OUT) time.sleep(1) while True: GPIO.output(40,GPIO.HIGH) time.sleep(5) GPIO.output(40,GPIO.LOW) time.sleep(5) if __name__=='__main__': try: main() except KeyboardInterrupt: spi.close() GPIO.cleanup() finally: GPIO.cleanup() 

1 Answer 1

2

Unless you are using a compute module you will have no access to Broadcom gpio 40 (I'm not even sure if RPi.GPIO will run on the compute module).

You probably mean to use pin 40 which is gpio21. Either use 21 in your code or change GPIO.setmode(GPIO.BCM) to GPIO.setmode(GPIO.BOARD).

GPIO.setmode(GPIO.BCM) says to use Broadcom gpio numbering.

GPIO.setmode(GPIO.BOARD) says to use pin numbering.


Pins and gpios

 pin pin 3V3 1 2 5V 0/2 (SDA) 3 4 5V 1/3 (SCL) 5 6 0V 4 7 8 14 (TXD) 0V 9 10 15 (RXD) 17 (ce1) 11 12 18 (ce0) 21/27 13 14 0V 22 15 16 23 3V3 17 18 24 10 (MOSI) 19 20 0V 9 (MISO) 21 22 25 11 (SCLK) 23 24 8 (CE0) 0V 25 26 7 (CE1) ....... 0 (ID_SD) 27 28 1 (ID_SC) 5 29 30 0V 6 31 32 12 13 33 34 0V 19 (miso) 35 36 16 (ce2) 26 37 38 20 (mosi) 0V 39 40 21 (sclk) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.