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)