nvidia / jetson-gpio Goto Github PK
View Code? Open in Web Editor NEWA Python library that enables the use of Jetson's GPIOs
License: MIT License
A Python library that enables the use of Jetson's GPIOs
License: MIT License
Installed with source and pip both i tried ,but for python2 it is showing the following error...
RuntimeError: This module can only be run on a Raspberry Pi!
nvidia@tegra-ubuntu:~/jetson_gpio/jetson-gpio-master$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing lib/python/Jetson.GPIO.egg-info/PKG-INFO
writing top-level names to lib/python/Jetson.GPIO.egg-info/top_level.txt
writing dependency_links to lib/python/Jetson.GPIO.egg-info/dependency_links.txt
reading manifest file 'lib/python/Jetson.GPIO.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'LICENCE.txt'
writing manifest file 'lib/python/Jetson.GPIO.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
creating build/bdist.linux-aarch64/egg
creating build/bdist.linux-aarch64/egg/Jetson
copying build/lib.linux-aarch64-2.7/Jetson/init.py -> build/bdist.linux-aarch64/egg/Jetson
creating build/bdist.linux-aarch64/egg/Jetson/GPIO
copying build/lib.linux-aarch64-2.7/Jetson/GPIO/init.py -> build/bdist.linux-aarch64/egg/Jetson/GPIO
copying build/lib.linux-aarch64-2.7/Jetson/GPIO/gpio_pin_data.py -> build/bdist.linux-aarch64/egg/Jetson/GPIO
copying build/lib.linux-aarch64-2.7/Jetson/GPIO/99-gpio.rules -> build/bdist.linux-aarch64/egg/Jetson/GPIO
copying build/lib.linux-aarch64-2.7/Jetson/GPIO/gpio.py -> build/bdist.linux-aarch64/egg/Jetson/GPIO
copying build/lib.linux-aarch64-2.7/Jetson/GPIO/gpio_event.py -> build/bdist.linux-aarch64/egg/Jetson/GPIO
creating build/bdist.linux-aarch64/egg/RPi
copying build/lib.linux-aarch64-2.7/RPi/init.py -> build/bdist.linux-aarch64/egg/RPi
creating build/bdist.linux-aarch64/egg/RPi/GPIO
copying build/lib.linux-aarch64-2.7/RPi/GPIO/init.py -> build/bdist.linux-aarch64/egg/RPi/GPIO
byte-compiling build/bdist.linux-aarch64/egg/Jetson/init.py to init.pyc
byte-compiling build/bdist.linux-aarch64/egg/Jetson/GPIO/init.py to init.pyc
byte-compiling build/bdist.linux-aarch64/egg/Jetson/GPIO/gpio_pin_data.py to gpio_pin_data.pyc
byte-compiling build/bdist.linux-aarch64/egg/Jetson/GPIO/gpio.py to gpio.pyc
byte-compiling build/bdist.linux-aarch64/egg/Jetson/GPIO/gpio_event.py to gpio_event.pyc
byte-compiling build/bdist.linux-aarch64/egg/RPi/init.py to init.pyc
byte-compiling build/bdist.linux-aarch64/egg/RPi/GPIO/init.py to init.pyc
creating build/bdist.linux-aarch64/egg/EGG-INFO
copying lib/python/Jetson.GPIO.egg-info/PKG-INFO -> build/bdist.linux-aarch64/egg/EGG-INFO
copying lib/python/Jetson.GPIO.egg-info/SOURCES.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying lib/python/Jetson.GPIO.egg-info/dependency_links.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying lib/python/Jetson.GPIO.egg-info/top_level.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/Jetson.GPIO-2.0.1-py2.7.egg' and adding 'build/bdist.linux-aarch64/egg' to it
removing 'build/bdist.linux-aarch64/egg' (and everything under it)
Processing Jetson.GPIO-2.0.1-py2.7.egg
Removing /usr/local/lib/python2.7/dist-packages/Jetson.GPIO-2.0.1-py2.7.egg
Copying Jetson.GPIO-2.0.1-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Jetson.GPIO 2.0.1 is already the active version in easy-install.pth
Installed /usr/local/lib/python2.7/dist-packages/Jetson.GPIO-2.0.1-py2.7.egg
Processing dependencies for Jetson.GPIO==2.0.1
Finished processing dependencies for Jetson.GPIO==2.0.1
nvidia@tegra-ubuntu:/jetson_gpio/jetson-gpio-master$ cd samples//jetson_gpio/jetson-gpio-master/samples$ python simple_input.py
nvidia@tegra-ubuntu:
Traceback (most recent call last):
File "simple_input.py", line 22, in
import RPi.GPIO as GPIO
File "/home/nvidia/.local/lib/python2.7/site-packages/RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
nvidia@tegra-ubuntu:~/jetson_gpio/jetson-gpio-master/samples$ python3 simple_input.py
Starting demo now! Press CTRL+C to exit
Value read from pin 18 : LOW
$ ls -l /proc/device-tree/chosen/plugin-manager/ids
total 0
-r--r--r-- 1 root root 26 Jan 29 10:21 3448-0000-400
drwxr-xr-x 3 root root 0 Jan 29 10:21 connection
-r--r--r-- 1 root root 4 Jan 29 10:21 name
Library reports:
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
In def _setup_single_in(channel, pull_up_down=PUD_OFF):
(https://github.com/NVIDIA/jetson-gpio/blob/master/lib/python/Jetson/GPIO/gpio.py#L218) the pull_up_down
function parameter appears unused.
it doesn't seem to support NX fan PWM pin-230/GPIO14 that is out of the 40 pin GPIO header
Describe the bug
A clear and concise description of what the bug is, including
Traceback (most recent call last):
File "./test_all_apis.py", line 622, in <module>
test()
File "./test_all_apis.py", line 289, in test_out_in_init_high
assert(val == GPIO.LOW)
AssertionError
To Reproduce
Steps to reproduce the behavior:
sudo ./run_sample.sh test_all_apis.py
Expected behavior
For all tests to run successfully.
Additional context
Add any other context about the problem here.
Hello, I'm trying to measure the input pwm duty cycle (see #7).
import RPi.GPIO as GPIO
import time
but_pin = 23 # Board pin 18
t = time.time()
def callback_one(channel):
global t
print(GPIO.input(channel), (time.time() - t) * 100000)
t = time.time()
def main():
GPIO.setmode(GPIO.BOARD) # BOARD pin-numbering scheme
GPIO.setup(but_pin, GPIO.IN) # button pin set as input
GPIO.add_event_detect(but_pin, GPIO.BOTH)
GPIO.add_event_callback(but_pin, callback_one)
try:
while True:
pass
Example output looks like:
1 2555.6087493896484
0 2555.561065673828
0 2562.1652603149414
0 2051.234245300293
0 2558.2313537597656
0 2553.6537170410156
0 547.2898483276367
0 1540.8754348754883
0 2555.537223815918
1 1574.6116638183594
0 558.7100982666016
0 13.73291015625
1 1337.4090194702148
0 1032.3286056518555
0 523.2572555541992
0 1030.6119918823242
1 519.4664001464844
Since because API doesn't allow to handle each type of edge FALLING, RISING separately, the only method to know what level was switched is using GPIO.input(channel)
, but as you can notice it doesn't work well (first column of the output). Possibly because level is not yet switched at the moment when edge is triggered. I'm 100% sure that's the PWM in the input, I checked it using signal analyzer so that output must be 0, 1, 0, 1, 0... etc. Can you please update the API and provide an optional argument to callback function specifying what type of edge has triggered the event?
Hi!
I'm testing the GPIO with button_event.py example. Sometimes when I press the button the event "button pressed" is activated. Sometimes that does not happen (I need to wait and try again). I'm using a 4.7k resistor as pull-up.
Board: Jetson TX2.
Thanks!
Mauricio
Hello, I am trying to run ROS automatically when booting up my Xavier NX using the robot_upstart package. The ROS core and most of the nodes get up and running successfully however when trying to load the Jetson-GPIO library I get the following error:
File "/../../../button_input.py", line 6 import Jetson.GPIO as GPIO File "/usr/lib/python2.7/dist-packages/Jetson/GPIO/__init__.py", line 1, in <module> from .gpio import * File "/usr/lib/python2.7/dist-packages/Jetson/GPIO/gpio.py", line 33, in <module> raise RuntimeError("The current user does not have permissions set to " RuntimeError: The current user does not have permissions set to access the library function
It looks like 99-gpio.rules isn't granting gpio permission to the daemon process started by robot_upstart. I've tried adding the following line to the bottom of 99-gpio.rules:
ACTION=="add", KERNEL=="gpio", MODE="0666"
but this hasn't made a difference. Do you know how I can make the gpio/pwm interfaces accessible to the daemon?
Thanks
I'm trying to run simple_pwm.py code but .pwm is not working, do we have to change the pinmux configuration to make it work. i'm unable to find any documentation on pinmux configuration.
Updated to include uname -a && pip3 --version && python3 --version && python3 -m pip install --user adafruit-blinka && error traceback
Jetson.GPIO 2.0.0
Running on Raspberry Pi 3B+
$ uname -a
Linux ubiquityrobot 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l armv7l arm7l GNU/Linux
$ pip3 --version
pip 19.2.2. from /home/ubuntu/.local/lib/python3.5/site-packages/pip (python 3.5)
$ python3 --version
Python 3.5.2
$ python3 -m pip install --user adafruit-blinka
Requirement already satisfied: adafruit-blinka in ./.local/lib/python3.5/site-packages (2.3.2)
Requirement already satisfied: Jetson.GPIO in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (2.0.0)
Requirement already satisfied: sysv-ipc in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (1.0.0)
Requirement already satisfied: Adafruit-PlatformDetect in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (1.3.2)
Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (from adafruit-blinka) (3.0)
Requirement already satisfied: RPi.GPIO in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (0.7.0)
Requirement already satisfied: rpi-ws281x>=4.0.0 in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (4.2.2)
Requirement already satisfied: Adafruit-PureIO in ./.local/lib/python3.5/site-packages (from adafruit-blinka) (0.2.3)
$ python3 blinkatest.py
Traceback (most recent call last):
File "blinkatest.py", line 1, in <module>
import board
File "/home/ubuntu/.local/lib/python3.5/site-packages/board.py", line 47, in <module>
from adafruit_blinka.board.raspi_40pin import *
File "/home/ubuntu/.local/lib/python3.5/site-packages/adafruit_blinka/board/raspi_40pin.py", line 3, in <module>
from adafruit_blinka.microcontroller.bcm283x import pin
File "/home/ubuntu/.local/lib/python3.5/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 1, in <module>
import RPi.GPIO as GPIO
File "/home/ubuntu/.local/lib/python3.5/site-packages/RPi/GPIO/__init__.py", line 1, in <module>
from Jetson.GPIO import *
File "/home/ubuntu/.local/lib/python3.5/site-packages/Jetson/GPIO/__init__.py", line 1, in <module>
from .gpio import *
File "/home/ubuntu/.local/lib/python3.5/site-packages/Jetson/GPIO/gpio.py", line 70, in <module>
model, JETSON_INFO, _channel_data_by_mode = gpio_pin_data.get_data()
File "/home/ubuntu/.local/lib/python3.5/site-packages/Jetson/GPIO/gpio_pin_data.py", line 260, in get_data
raise Exception('Could not determine Jetson model')
Exception: Could not determine Jetson model
Installation of adafruit's adafruit-blinka has a Jetson.GPIO dependency which was downloaded and installed using pip3.
Error returns 'Could not determine Jetson model' from gpio_pin_data.py.
My /proc/device-tree/compatible looks like:
raspberrypi,3-model-b-plus^@brcm,bcm2837^@
Question: Does jetson-gpio not support raspberry pi hardware? Can I manually modify my compatible file to include a compatible board, and if so which one? Thanks
import RPi.GPIO as GPIO
import time
output_pins = {
'JETSON_XAVIER': 18,
'JETSON_NANO': 33,
}
out_pin = output_pins.get(GPIO.model, None)
def main():
GPIO.setmode(GPIO.BOARD)
print('board is set')
GPIO.setup(out_pin, GPIO.OUT, initial=GPIO.HIGH)
print('pin out set to high')
p = GPIO.PWM(out_pin, 50)
print('pwm pin set')
p.start(0)
print('pwm is started')
try:
while 1:
for dc in range(0, 101, 5):
print('+ve Duty cycle')
p.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, -5):
print('-ve duty cycle')
p.ChangeDutyCycle(dc)
time.sleep(0.1)
except KeyboardInterrupt:
pass
p.stop()
GPIO.cleanup()
print('pwm cycle completed')
if __name__ == '__main__':
main()
Once while loop start executing motors stops running. It seems pwm signal is not reaching pin 33. using L298N pwm motor controller.
Hello, I'm trying to use a servo SG90 with a Jetson nano, but without successes.
This servo go to 90 degrees with 10% of DC and -90 with 5%, but it always rotate to a maximum of one side, not the other. And after rotate it do not have any resistance to be move back to any position.
I'm using a simple copy of simple_pwm.py just changing the p.start()
My question are: can pwm using python be accurate enough to do this task and I have other problem than the python script? Is pwm sending continuous?
I am trying to use pwm on the GPIO 33 of the Xavier NX board but the sample script is not working. I have seen that I might have to configure the pinmux. However, there is a document called "Jetson Nano Developer Kit 40-Pin Expansion Header Configuration" for the Nano but there is nothing for the Xavier NX.
What should I do ? How can I configure the board properly ?
Describe the bug
Jetson.GPIO failed work in kubernetes but docker.
Have to apparently mount /sys/class/gpio into pods
Hey guys, i test the Jetson.GPIO in python3, my code is realy very simple.
device XavierNX
Jetpack : 4.4
import Jetson.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
print(GPIO.getmode())
channel = 13
GPIO.setup(channel, GPIO.OUT)
while True:
print('setting pin 13 high')
GPIO.output(channel, GPIO.HIGH)
time.sleep(2)
print('setting pin 13 low')
GPIO.output(channel, GPIO.LOW)
time.sleep(2)
print()
but some pins not working, you can see that my code is just set a pin up and down,
the pin12 35 38 40 works fine, but the others maintain 1.6V.
why is that??
Hi,
I reviewed the code of test_all_apis.py script, and I belive in test_setup_one_out_no_init function it should be GPIO.OUT (rather then GPIO.IN)
jetson-gpio/samples/test_all_apis.py
Line 142 in 34f0f46
The tests probably passed anyway due to the fact that and digital output pin is also input pin.
Add any other context about the problem here.
/jetson-gpio/samples$ python3 simple_pwm.py
/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py:352: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings
RuntimeWarning)
/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py:593: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings
RuntimeWarning)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple_pwm.py", line 61, in
main()
File "simple_pwm.py", line 41, in main
p = GPIO.PWM(output_pin, 13)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 597, in init
self._reconfigure(frequency_hz, 50.0)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 635, in _reconfigure
_set_pwm_period(self._ch_info, self._period_ns)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 245, in _set_pwm_period
f.write(str(period_ns))
OSError: [Errno 22] Invalid argument
HI, do you have a C code for GPIO control
To Reproduce
Steps to reproduce the behavior:
import Jetson.GPIO as GPIO
GPIO.setmode(GPIO.TEGRA_SOC)
in_pin = 'SPI2_MISO'
GPIO.setup(in_pin, GPIO.IN)
def cb_fn(channel):
pass
GPIO.add_event_detect(in_pin, GPIO.RISING, callback=cb_fn, bouncetime=200)
in_pin
GPIO.remove_event_detect(in_pin)
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-6-6287b623d9e5> in <module>
----> 1 GPIO.remove_event_detect(in_pin)
/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py in remove_event_detect(channel)
501 def remove_event_detect(channel):
502 ch_info = _channel_to_info(channel, need_gpio=True)
--> 503 event.remove_edge_detect(ch_info.gpio)
504
505
/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio_event.py in remove_edge_detect(gpio)
134 _set_edge(gpio, NO_EDGE)
135
--> 136 _mutex.acquire()
137 del _gpio_event_list[gpio]
138 _mutex.release()
KeyboardInterrupt:
Expected behavior
GPIO.remove_event_detect(in_pin)
should run successfully.
Is there a dockerfile for installing nvidia jetson-gpio on docker
I tried to write the Dockerfile myself but when I import the library in my python file I get this error:
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
Describe the bug
Not working with systemd
A clear and concise description of what the bug is, including
To Reproduce
Steps to reproduce the behavior:
a. Creat a python script
[Service]
#ExecStart=/home/nvidia/shutdown.sh
WorkingDirectory=/home/nvidia/
ExecStart=/usr/bin/python3 /home/nvidia/yolov3/shutdown_jutson.py
Restart=always
StandardOutput=inherit
StandardError=inherit
User=root
#Group=nvidia
#RestartSec=10s
Type=simple
[Install]
WantedBy=graphical.target
#WantedBy=multi-user.target
Expected behavior
It is expected to work on boot up.
However, it seems the GPIO is not working at the begging.
If I reset the P12 such as GPIO.setup(12, GPIO.IN) or reboot the python script.
it works normally as expected.
Here is my script
import Jetson.GPIO as GPIO
import time
import os
input_pin = 18 # BCM pin 18, BOARD pin 12
def main():
TimeToDown = 6
mytimer = 0
value = GPIO.LOW
GPIO.setmode(GPIO.BCM) # BCM pin-numbering scheme from Raspberry Pi
GPIO.setup(input_pin, GPIO.IN) # set pin as an input pin
print("Starting demo now! Press CTRL+C to exit")
try:
while True:
value = GPIO.input(input_pin)
if mytimer != TimeToDown:
if value != GPIO.HIGH:
if mytimer != 0:
print("Power supply recovered!")
mytimer = 0
else:
print("{} seconds left to down".format(TimeToDown - mytimer))
mytimer = mytimer + 1
time.sleep(1)
else:
print("Shut OS down...")
time.sleep(2)
os.system('shutdown now')
finally:
GPIO.cleanup()
if name == 'main':
main()
I wonder if there is an updated version for the Xavier NX?
Add any other context about the problem here.
/jetson-gpio/samples$ python3 simple_pwm.py
/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py:352: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings
RuntimeWarning)
/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py:593: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings
RuntimeWarning)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple_pwm.py", line 61, in
main()
File "simple_pwm.py", line 41, in main
p = GPIO.PWM(output_pin, 13)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 597, in init
self._reconfigure(frequency_hz, 50.0)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 635, in _reconfigure
_set_pwm_period(self._ch_info, self._period_ns)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 245, in _set_pwm_period
f.write(str(period_ns))
OSError: [Errno 22] Invalid argument
After the last update I get permission errors in my dockerized builds:
Traceback (most recent call last):
File "./listen_input.py", line 2, in
import RPi.GPIO as GPIO
File "/usr/local/lib/python2.7/site-packages/RPi/GPIO/init.py", line 1, in
from Jetson.GPIO import *
File "/usr/local/lib/python2.7/site-packages/Jetson/GPIO/init.py", line 1, in
from .gpio import *
File "/usr/local/lib/python2.7/site-packages/Jetson/GPIO/gpio.py", line 33, in
raise RuntimeError("The current user does not have permissions set to "
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
I also tried this with python3, but also the same error there:
Traceback (most recent call last):
File "./listen_input.py", line 2, in
import RPi.GPIO as GPIO
File "/usr/local/lib/python3.8/site-packages/RPi/GPIO/init.py", line 1, in
from Jetson.GPIO import *
File "/usr/local/lib/python3.8/site-packages/Jetson/GPIO/init.py", line 1, in
from .gpio import *
File "/usr/local/lib/python3.8/site-packages/Jetson/GPIO/gpio.py", line 33, in
raise RuntimeError("The current user does not have permissions set to "
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
This used to work ~2 weeks ago without issue.
I ran the
sudo groupadd -f -r gpio
sudo usermod -a -G gpio your_user_name
and copied the 99-gpio.rules and rebooted several times and rebuilt the image several times.
id -a
uid=1000(edgeai) gid=1000(edgeai) groups=1000(edgeai),4(adm),24(cdrom),27(sudo),29(audio),30(dip),44(video),46(plugdev),108(i2c),118(lpadmin),124(gdm),127(docker),130(sambashare),131(iotedge),998(weston-launch),999(gpio)
ls -l /sys/class/gpio/export
--w--w---- 1 root gpio 4096 feb 28 10:00 /sys/class/gpio/export
ls -l /sys/class/gpio/unexport
--w--w---- 1 root gpio 4096 feb 28 10:00 /sys/class/gpio/unexport
Any ideas?
Hello, I have a question. I'm interested in operating GPIO on Jetson NANO from within container and then from K3s.
I encountered errors when tried to activate simple_out.py
example from docker container.
My dockerfile is:
#FROM ubuntu:20.04
#FROM python:2
FROM nvcr.io/nvidia/l4t-base:r32.4.3
ARG uid
ARG gid
ARG gid_gpio
RUN groupadd -f -r -g $gid_gpio gpio
RUN groupadd -f -r -g 1000 user
RUN apt-get update && \
apt-get install -y python-pip && \
pip install Jetson.GPIO
# gpio needs to be main group, otherwise we get permission problems
RUN useradd -M --uid $uid -g $gid_gpio user --groups uucp,$gid,user
RUN mkdir -p /etc/sudoers.d \
&& echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/user \
&& echo 'Defaults exempt_group+=user' >> /etc/sudoers.d/user \
&& chmod a=r,o= /etc/sudoers.d/user
WORKDIR /app
COPY simple_out.py /app
CMD ["/bin/sh", "-c", "python /app/simple_out.py"]
I am running the container with following script:
#!/bin/bash
source ../configure.sh
docker run --rm -it \
--runtime=nvidia --gpus all\
-v /sys:/sys \
--device /dev/spidev0.0:/dev/spidev0.0:rw \
--group-add $(cut -d: -f3 < <(getent group gpio)) "poc/gpio:${POC_VER}_${MY_KUBECTL_VERSION}_${MY_TARGETPLATFORM}" /bin/bash
and the errors are printed:
root@46ede1d99ba7:/app# python simple_out.py
Traceback (most recent call last):
File "simple_out.py", line 22, in <module>
import RPi.GPIO as GPIO
File "/usr/local/lib/python2.7/dist-packages/RPi/GPIO/__init__.py", line 1, in <module>
from Jetson.GPIO import *
File "/usr/local/lib/python2.7/dist-packages/Jetson/GPIO/__init__.py", line 1, in <module>
from .gpio import *
File "/usr/local/lib/python2.7/dist-packages/Jetson/GPIO/gpio.py", line 70, in <module>
model, JETSON_INFO, _channel_data_by_mode = gpio_pin_data.get_data()
File "/usr/local/lib/python2.7/dist-packages/Jetson/GPIO/gpio_pin_data.py", line 373, in get_data
with open(compatible_path, 'r') as f:
IOError: [Errno 2] No such file or directory: '/proc/device-tree/compatible'
I have tried with the NVIDIA base container (nvcr.io/nvidia/l4t-base:r32.4.3
) but it didn't help. I understand that the /sys
contains files that should be mapped into container, (/proc/device-tree/compatible
is a symlink to one of the files in that directory)
Any ideas ?
Thanks for jetson.gpio.
Currently I'm not able to read PWM signal by Jetson nano (Jetson.GPIO) from RC receiver. PWM signal can be red by RPi but not by Jetson Nano, please find link to the code below for read_pwm on RPi:
http://abyz.me.uk/rpi/pigpio/code/read_PWM_py.zip
Is there any way Jetson.GPIO can read PWM signal as on RPi pigpio?
Please don't submit questions
Please use this form to report specific bugs in Jetson.GPIO. All general questions or support requests should be directed at NVIDIA's forums; see:
https://developer.nvidia.com/embedded/community/support-resources
Please delete this section from your bug report.
Describe the bug
A clear and concise description of what the bug is, including
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
Describe the bug
There is a short voltage drop to 0V when a Pin is setup via the GPIO.setup function. This drop is around 300μs long and occures if you use the initial optional flag or if you put the pin HIGH afterwards. If you setup the pin multiple times in one script, preferably with a delay in between, you can also observe the behavior.
To Reproduce
Steps to reproduce the behaviour:
Expected behavior
Because of the internal pull-up I think, the Jetson GPIO pin is at a steady 1.8V level. If you setup the pin as an output while setting initial to HIGH, then you should not see any difference in the pin level. But in reality, the level drops down to 0V which is not acceptable in our use case.
Additional context
Please look at the provided picture of the oscilloscope, you also need to know, that the output is level shifted to 5V.
Hello,
I want to contorl the HC-SR04 ultrasonic sensor with the Jetson Nano's GPIO pins. It needs a 0.01ms Trigger signal and sends an Echo signal as soon as the sonic wave arrives. Here is my simple code to do that:
# Import libraries
import RPi.GPIO as GPIO`
import time`
# GPIO Mode (BOARD / BCM)
GPIO.setmode(GPIO.BCM)
print("Distance measurement in process")
# Assign GPIO Pins
GPIO_TRIGGER = 19
GPIO_ECHO = 21
# Set direction of GPIO Pins (IN / OUT)
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
# Start the sensor
GPIO.output(GPIO_TRIGGER, GPIO.LOW)
print("Sensor is starting!")
time.sleep(2)
# Set Trigger to HIGH
GPIO.output(GPIO_TRIGGER, GPIO.HIGH)
# Set Trigger after 0.01ms to LOW
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, GPIO.LOW)
#Save start time
while GPIO.input(GPIO_ECHO) == GPIO.LOW:
StartTime = time.time()
# Save arrival time
while GPIO.input(GPIO_ECHO) == GPIO.HIGH:
StopTime = time.time()
# Difference between start and arrival
TimeElapsed = StopTime - StartTime
distance = (TimeElapsed * 34300) / 2
print("Distance: ", distance)
GPIO.cleanup()
Here is my problem: It gets stuck in the first 'while'-loop, which means that the Echo signal never comes. I use a voltage translator to connect the sensor to the Jetson. I remember that I connected the 5V power supply pin first and then connected the Ground-pin, could that be the problem? Or my other assumption is related to the pin numbering definition. The numbers I entered in the definition are the ones that I can read from my Jetson Nano board. Are they right with the BCM-Mode? I also tested the state of the pins in a seperate program and I have different results when I type import Jetson.GPIO as GPIO and import RPi.GPIO as GPIO.
Can someone tell me where the problem could be originated?
Thanks for the help in advance!
Hi, sorry for if i miss something.
This is my code for taking input from GPIO 10.
import Jetson.GPIO as GPIO
class CheckGPIO():
def __init__(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
self.CONVEYOR_BACKWARD_PIN = 10
GPIO.setup(self.CONVEYOR_BACKWARD_PIN, GPIO.IN)
def _check_conveyor(self):
if GPIO.input(self.CONVEYOR_BACKWARD_PIN):
print("LOW")
else:
print("HIGH")
checkclass = CheckGPIO()
checkclass._check_conveyor()
But i got an error. Here is error log;
Traceback (most recent call last):
File "karalama.py", line 55, in <module>
check = CheckGPIO()
File "karalama.py", line 22, in __init__
GPIO.setup(self.CONVEYOR_BACKWARD_PIN, GPIO.IN)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 358, in setup
ch_infos = _channels_to_infos(channels, need_gpio=True)
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 121, in _channels_to_infos
for c in _make_iterable(channels)]
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 121, in <listcomp>
for c in _make_iterable(channels)]
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", line 104, in _channel_to_info_lookup
raise ValueError("Channel %s is invalid" % str(channel))
ValueError: Channel 10 is invalid
cp: cannot stat 'lib/python/Jetson/GPIO/99-gpio.rules': No such file or directory
This seems to be similar to #32, but only happening on Jetson AGX Xavier with 32 GB eMMC and symptom is that I2C and PWM do not work anymore on the pins. GPIO pins 3.3V & 5V still work as expected.
jetson@agx:~$ sudo python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Jetson.GPIO as GPIO
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
>>> GPIO.JETSON_INFO
{'P1_REVISION': 1, 'RAM': '16384M', 'REVISION': 'Unknown', 'TYPE': 'Jetson Xavier', 'MANUFACTURER': 'NVIDIA', 'PROCESSOR': 'ARM Carmel'}
>>> GPIO.VERSION
'2.0.16'
>>>
jetson@agx:~$ cat /etc/nv_tegra_release
# R32 (release), REVISION: 5.0, GCID: 25531747, BOARD: t186ref, EABI: aarch64, DATE: Fri Jan 15 23:21:05 UTC 2021
jetson@agx:~$
jetson@agx:~$ cat /proc/device-tree/compatible
nvidia,galennvidia,jetson-xaviernvidia,p2822-0000+p2888-0001nvidia,tegra194
jetson@agx:~$ ls -l /proc/device-tree/chosen/plugin-manager/ids
total 0
-r--r--r-- 1 root root 25 Feb 25 21:40 2888-0004-400
-r--r--r-- 1 root root 25 Feb 25 21:40 framos-imx464-0
-r--r--r-- 1 root root 4 Feb 25 21:40 name
jetson@agx:~$
The strange thing, this particular board worked before, so we don't really understand what happened and what can be the problem/debug actions. HDMI for example is working, so the board is clearly connected.
Thank you in advance!
R
Describe the bug
Which version of Jetson.GPIO you are using.
Jetson.GPIO (2.0.6)
Which version of L4T (not JetPack) you are using.
To Reproduce
Expected behavior
I expect GPIO pins to function, but they are not functioning
Additional context
$ ls -l /proc/device-tree/chosen/plugin-manager/ids
total 0
-r--r--r-- 1 root root 26 Feb 25 10:38 3448-0000-200
drwxr-xr-x 3 root root 0 Feb 25 10:38 connection
-r--r--r-- 1 root root 4 Feb 25 10:38 name
$ cat /etc/nv_tegra_release
R32 (release), REVISION: 3.1, GCID: 18186506, BOARD: t210ref, EABI: aarch64, DATE: Tue Dec 10 06:58:34 UTC 2019
--not sure if relevant-- install cuda, deepstream, various libs required for jetson-inference using apt.
https://github.com/dusty-nv/jetson-inference
For jetson-inference I followed instructions to build from source.
https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md
Hi, I'm using Jetson Nano(I installed jebot image version 0p3p2)
I've just downloaded the pakage using pip.
And I set up the user permissions following Readme.md and it works fine.
( I downloaded 99-gpio.rules from the repository.)
I can run almost every samples on the repository without using sudo,
but I can't run simple_pwm.py without using sudo. With sudo, it works fine.
I chcecked the source, and I found out that when I run it without using sudo, it stucks in the loop in _export_pwm function.
I checked the permission in /sys/devices/7000a000.pwm/pwm/pwmchip0/pwm2
duty_cycle, enable and period files' permissions are -rw-r--r--
Because I don't have permission to write enable, the program stucks in loop
(while not os.access(enable_path, os.R_OK | os.W_OK))
I also checked the permission in /sys/devices/7000a000.pwm/pwmchip0 ,
export and unexport files' permissions are --w--w--- , which are set correctly.
Can you give some advice?
Please don't submit questions
Please use this form to report specific bugs in Jetson.GPIO. All general questions or support requests should be directed at NVIDIA's forums; see:
https://developer.nvidia.com/embedded/community/support-resources
Please delete this section from your bug report.
Describe the bug
A clear and concise description of what the bug is, including
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
`python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
import Jetson.GPIO as GPIO
mode = GPIO.getmode()
GPIO.JETSON_INFO
{'P1_REVISION': 1, 'RAM': '16384M', 'REVISION': 'Unknown', 'TYPE': 'Jetson Xavier', 'MANUFACTURER': 'NVIDIA', 'PROCESSOR': 'ARM Carmel'}
`
>>> import Jetson.GPIO as GPIO
>>> GPIO.setmode(GPIO.TEGRA_SOC)
>>> mode = GPIO.getmode()
>>> GPIO.getmode()
1000
Is there any knowledge about sensors that worked with the Jetson.GPIO approach?
Any insights on how to read from dht11 that driver is integrated into tegra kernel?
Hi,
I am trying to control a device (Unicorn HAT HD) using Jetson Nano through SPI. Unicorn HAT HD has been commonly used with Raspberry Pi. In this case, the required python package python-spidev is somehow interfaced with RPi.GPIO. I wonder if I use Jetson.GPIO, what should I do to replace RPi.GPIO to avoid conflict? Do I need to do that?
And where should I call GPIO.setmode()?
Hope my questions make sense.
Tom
Jetson Nano GPIO in python.
This is error code:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import Jetson.GPIO as GPIO
File "/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/__init__.py", line 1, in <module>
from .gpio import *
File "/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py", line 70, in <module>
model, JETSON_INFO, _channel_data_by_mode = gpio_pin_data.get_data()
File "/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio_pin_data.py", line 286, in get_data
revision = f.split('-')[-1]
AttributeError: '_io.TextIOWrapper' object has no attribute 'split'
I found this error "split" from .egg packages.
Hi,
I just followed the installation instruction to install Jetson.GPIO and after executing the Permission setup step, I have this error:
raise RuntimeError("The current user does not have permissions set to "
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
I'm using virtualenv and I installed it using pip inside the virtualenv, is that an issue ?
I'm on Jetson TX2 by the way.
Thanks
I'm playing with the button_interrupt.py sample and I'm getting some strange behavior.
I'm running Jetson.GPIO 2.0.8 on L4T # R32 (release), REVISION: 4.2, GCID: 20074772, BOARD: t210ref. Jetson Nano Development Kit B01.
I have connected a button to the J41 pin 31 (which is supposed to be by default configured as pull up, correct me if I'm wrong here). The pin is configured as input as per the sample.
With the original sample, I get the event triggered twice. When I use a not-so-low debounce time (even up to a second), I get an event triggered twice. If I raise the debounce time up to a point where I don't get the event repeated (e.g.: two seconds), I get the event triggered once, but the button stops responding and the python program will need two Ctrl+C until it gets the keyboard interrupt. I guess this indicates the thread gets stuck somewhere, looks like waiting for some mutex unlock.
Here's the traceback after the double Ctrl+C:
Starting demo now! Press CTRL+C to exit
Blink LED 2
^C^CTraceback (most recent call last):
File "./test_button.py", line 57, in main
time.sleep(2)
KeyboardInterrupt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./test_button.py", line 62, in <module>
main()
File "./test_button.py", line 59, in main
GPIO.cleanup() # cleanup all GPIOs
File "/usr/local/lib/python3.7/dist-packages/Jetson/GPIO/gpio.py", line 396, in cleanup
_cleanup_all()
File "/usr/local/lib/python3.7/dist-packages/Jetson/GPIO/gpio.py", line 293, in _cleanup_all
_cleanup_one(ch_info)
File "/usr/local/lib/python3.7/dist-packages/Jetson/GPIO/gpio.py", line 283, in _cleanup_one
event.event_cleanup(ch_info.gpio)
File "/usr/local/lib/python3.7/dist-packages/Jetson/GPIO/gpio_event.py", line 369, in event_cleanup
remove_edge_detect(gpio)
File "/usr/local/lib/python3.7/dist-packages/Jetson/GPIO/gpio_event.py", line 136, in remove_edge_detect
_mutex.acquire()
KeyboardInterrupt
I use the same motion sensor. When plug in GPIO port of Raspberry Pi 3 B+, it works fine. When I use Jetson Nano and jetson-gpio library, it performs differently, it seems to be very unstable and produces high and low very frequently.
What could be problem between the jetson-gpio and the one used in Raspberry pi given that I use the (almost) same code and same sensor. Is there any bug that would affect this in the jetson-gpio?
now,the gpio lib only have gpio
i want to do pwm,i2c,spi,but i can`t see it
how long it can realize?
it best to like the Arduino.
i am Jetson Nano
I am trying to run the following code:
import Jetson.GPIO as GPIO
BUTTON_GPIO = 'AUD_MCLK' # / pin number 7 (connected to 3.3v)
BUTTON_LED = 'LCD_TE' # / pin number 15
def button(argument):
print(f"{type(argument)}: {argument}")
print("Button")
def main():
GPIO.setmode(GPIO.TEGRA_SOC)
GPIO.setup(BUTTON_GPIO, GPIO.IN)
GPIO.setup(BUTTON_LED, GPIO.OUT)
GPIO.add_event_detect(BUTTON_GPIO, GPIO.RISING, callback=button)
if __name__ == "__main__":
main()
Jetson.GPIO Version:
grass@grass-desktop:~/grass_hopper$ pip3 show Jetson.GPIO
Name: Jetson.GPIO
Version: 2.0.17
Summary: A module to control Jetson GPIO channels
Home-page: https://github.com/NVIDIA/jetson-gpio
Author: NVIDIA
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.6/dist-packages
Requires:
L4T Version:
grass@grass-desktop:~/grass_hopper$ cat /etc/nv_tegra_release
# R32 (release), REVISION: 5.1, GCID: 26202423, BOARD: t210ref, EABI: aarch64, DATE: Fri Feb 19 16:45:52 UTC 2021
Jetson board:
Nvidia Jetson Nano Developer Kit
To Reproduce
Steps to reproduce the behavior:
Expected behavior
"Button" should be printed when pressing button
Additional context
This issue does not happen when running python3
, then entering the code in file.
I do everything as the readme file say, but the terminal returns the following err
No such file or directory: '/sys/devices/3160000.i2c/i2c-0/0-0074/gpio
I reboot jetson but it seems that doesn't work, btw, I have run the sample successfully on the same jetson just yesterday.
Hi! Thanks for this library. I'm just getting started with Jetson Nano and was wondering how I can use this (or another) library to interface with servos and I2C sensors.
Any pointers would be appreciated. Thanks!
Please don't submit questions
Please use this form to report specific bugs in Jetson.GPIO. All general questions or support requests should be directed at NVIDIA's forums; see:
https://developer.nvidia.com/embedded/community/support-resources
Please delete this section from your bug report.
Describe the bug
A clear and concise description of what the bug is, including
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Traceback (most recent call last):
File "./simple_input.py", line 22, in
import RPi.GPIO as GPIO
File "/opt/nvidia/jetson-gpio/lib/python/RPi/GPIO/init.py", line 1, in
from Jetson.GPIO import *
File "/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO/init.py", line 1, in
from .gpio import *
File "/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO/gpio.py", line 96, in
_board_info, _gpio_chip_base = gpio_pin_data.get_gpio_data(get_model())
File "/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO/gpio.py", line 94, in get_model
% model_str)
Exception: Could not guess Jetson model from the model string (NVIDIA Jetson Nano Developer Kit).
Additional context
I find this bug when using the 4.2.1 new release, the previous version OS works fine.
Hi!
I consulted your GPIO pin data for the NX to find out the linux pin number for board pin 31 after moving from a nano to an NX, and found that it might be wrong?
in the line:
(134, "/sys/devices/2200000.gpio", 31, 6, 'GPIO11', 'SOC_GPIO42', None, None),
134 should be the linux GPIO pin number according to the file, but actually for GPIO11 the pin number is 388 (which I tested and is indeed correct) am I looking at it wrong?
for the nano the line is correct, as 200 is indeed the correct pin for GPIO11
Hi,
I followed the process to install the library but I'm also using virtualenv to separate my workspaces.
So I did pip install in my virtualenv and when I want to import Jetson.GPIO it tells me I don't have the permissions:
import Jetson.GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nvidia/.virtualenvs/cv/lib/python3.5/site-packages/Jetson/GPIO/__init__.py", line 1, in <module>
from .gpio import *
File "/home/nvidia/.virtualenvs/cv/lib/python3.5/site-packages/Jetson/GPIO/gpio.py", line 33, in <module>
raise RuntimeError("The current user does not have permissions set to "
RuntimeError: The current user does not have permissions set to access the library functionalites. Please configure permissions or use the root user to run this
Even after I added gpio as a group and included nvidia as a new member and copy and reload the rules..
The problem then is if I want to use python as root , I then have the old environment for python where Jetson.GPIO is not installed of course...
Is there a way to solve this ?
I suppose I have to clone the repository elsewhere than /opt/nvidia but I don't understand where ? Or is there a file in which I should change a python path to point to my virtual environment ?
Thank in advance
Neither .input nor .PWM work on the Jetson Nano with GPIO.BOARD configuration. Identical code & connected circuitry works as expected on the rasberry pi.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.