RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD),GPIO.setmode(GPIO.BCM),GPIO.setmode(GPIO.TEGRA_SOC) GPIO.setmode(GPIO.CVM)

Hi,

Below is the Python code I have prepared. I set it using GPIO and I’m trying to run the led driver. I prepared the python code I prepared by changing it from the .cpp extension of a different arduino example. I get errors when I run it. I find it ridiculous that I get a run time error because when I run the code I wrote inside the function outside, I don’t get an error and I already set it above. What is the reason of this? How can I fix the errors I get?

Code;

from __future__ import print_function
import Jetson.GPIO as GPIO
import time
# import ctypes

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(18, GPIO.OUT)      # data pin
GPIO.setup(24, GPIO.OUT)    # clock pin
# GPIO.output(24, 0)   #1/0 true/false

#def begin():
#    sendZero()
#
#def end():
#    sendZero()

def clkRise():

    GPIO.output(24, 0)
    time.sleep(1)
    GPIO.output(24, 1)
    time.sleep(1)

def sendZero():
    
    for i in range (32):
        GPIO.output(24, 1)
        clkRise()
            
def takeAntiCode(dat):
    
    tmp = 0
    
    if (( dat and 0x80)  == 0 ):
        tmp |= 0x02
        
    if (( dat and 0x40)  == 0 ):
        tmp |= 0x01
        
    return tmp

def datSend(dx):
    
    for i in range (32):
        
        if (( dx and 0x80000000)  != 0 ):
            GPIO.output(24, 1)
             
        else:
            GPIO.output(24, 0)
     
    dx <<= 1
    clkRise()
    
def setColor(Red, Green, Blue):
    
    dx = 0
    
    dx |= 0x30 << 30
    
    dx |= takeAntiCode(Blue) << 28
    dx |= takeAntiCode(Green) << 26
    dx |= takeAntiCode(Red) << 24
    
    dx |= Blue << 16
    dx |= Green << 8
    dx |= Red
    
    datSend(dx)
       
GPIO.cleanup()

sendZero()
#setColor(100,0,0) # red
#sendZero()

Error:

x@x-desktop:~$ python3 /home/x/Desktop/gpiodeneme3.py
Traceback (most recent call last):
  File "/home/x/Desktop/gpiodeneme3.py", line 76, in <module>
    sendZero()
  File "/home/x/Desktop/gpiodeneme3.py", line 30, in sendZero
    GPIO.output(24, 1)
  File "/home/x/.local/lib/python3.6/site-packages/Jetson/GPIO/gpio.py", line 449, in output
    ch_infos = _channels_to_infos(channels, need_gpio=True)
  File "/home/x/.local/lib/python3.6/site-packages/Jetson/GPIO/gpio.py", line 119, in _channels_to_infos
    _validate_mode_set()
  File "/home/x/.local/lib/python3.6/site-packages/Jetson/GPIO/gpio.py", line 83, in _validate_mode_set
    raise RuntimeError("Please set pin numbering mode using "
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD), GPIO.setmode(GPIO.BCM), GPIO.setmode(GPIO.TEGRA_SOC) or GPIO.setmode(GPIO.CVM)

hello bugrahan.ismailoglu,

please check which mode has be set, you may calling mode = GPIO.getmode().
if that’s returning None, it’ll failed due to unknown gpio modes.

if you’re having exist code using the RPi library, the module can also be imported using the name RPi.GPIO.

thank you for the answer.

first of all i use BCM or BOARD as i dont use rasp. in the first part of the code, i already did the set operation, but im getting an error, i couldnt find the reason. and can you answer my other question?

Thank you.

please calling mode = GPIO.getmode() for checking return values.

actually i dont understand what you mean? its already there. now it doesnt give runtime error. i did sendZ instead of sendZero and i dont get any errors but when i run it it works but i cant render the colors as i want. can you help?

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

hello bugrahan.ismailoglu,

is it still shown RuntimeError? please share the failure message now you’ve seen.