Jetson.GPIO


NameJetson.GPIO JSON
Version 2.1.6 PyPI version JSON
download
home_pagehttps://github.com/NVIDIA/jetson-gpio
SummaryA module to control Jetson GPIO channels
upload_time2024-01-10 18:35:51
maintainer
docs_urlNone
authorNVIDIA
requires_python
licenseMIT
keywords jetson gpio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Jetson.GPIO - Linux for Tegra

Jetson TX1, TX2, AGX Xavier, and Nano development boards contain a 40 pin GPIO
header, similar to the 40 pin header in the Raspberry Pi. These GPIOs can be
controlled for digital input and output using the Python library provided in the
Jetson GPIO Library package. The library has the same API as the RPi.GPIO
library for Raspberry Pi in order to provide an easy way to move applications
running on the Raspberry Pi to the Jetson board.

This document walks through what is contained in The Jetson GPIO library
package, how to configure the system and run the provided sample applications,
and the library API.

# Package Components

In addition to this document, the Jetson GPIO library package contains the
following:

1. The `lib/python/` subdirectory contains the Python modules that implement all
library functionality. The gpio.py module is the main component that will be
imported into an application and provides the needed APIs. The `gpio_event.py`
and `gpio_pin_data.py` modules are used by the `gpio.py` module and must not be
imported directly in to an application.

2. The `samples/` subdirectory contains sample applications to help in getting
familiar with the library API and getting started on an application. The
`simple_input.py` and `simple_output.py` applications show how to perform read
and write to a GPIO pin respectively, while the `button_led.py`,
`button_event.py` and `button_interrupt.py` show how a button press may be used
to blink an LED using busy-waiting, blocking wait and interrupt callbacks
respectively.

# Installation

These are the way to install Jetson.GPIO python modules on your system. For the samples applications, please clone this repository to your system. 

## Using pip

The easiest way to install this library is using `pip`:
```shell
sudo pip install Jetson.GPIO
```

## Manual download 

You may clone this git repository, or download a copy of it as an archive file
and decompress it. You may place the library files anywhere you like on your
system. You may use the library directly from this directory by manually
setting `PYTHONPATH`, or install it using `setup.py`:
```shell
sudo python3 setup.py install
```

# Setting User Permissions

In order to use the Jetson GPIO Library, the correct user permissions/groups must
be set first.

Create a new gpio user group. Then add your user to the newly created group.
```shell
sudo groupadd -f -r gpio
sudo usermod -a -G gpio your_user_name
```

Install custom udev rules by copying the 99-gpio.rules file into the rules.d
directory.

If you have downloaded the source to Jetson.GPIO:
```shell
sudo cp lib/python/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/
```

If you installed Jetson.GPIO from a package, e.g. using pip into a virtual
environment:
```shell
sudo cp venv/lib/pythonNN/site-packages/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/
```

For the new rule to take place, you either need to reboot or reload the udev
rules by running:
```shell
sudo udevadm control --reload-rules && sudo udevadm trigger
```

# Running the sample scripts

With the permissions set as needed, the sample applications provided in the
`samples/` directory can be used. The following describes the operation of each
application:

1. `simple_input.py`: This application uses the BCM pin numbering mode and reads
the value at pin 12 of the 40 pin header and prints the value to the
screen.

2. `simple_out.py`: This application uses the BCM pin numbering mode from
Raspberry Pi and outputs alternating high and low values at BCM pin 18 (or
board pin 12 on the header) every 2 seconds.

3. `button_led.py`: This application uses the BOARD pin numbering. It requires a
button connected to pin 18 and GND, a pull-up resistor connecting pin 18
to 3V3 and an LED and current limiting resistor connected to pin 12. The
application reads the button state and keeps the LED on for 1 second every
time the button is pressed.

4. `button_event.py`: This application uses the BOARD pin numbering. It requires a
button connected to pin 18 and GND, a pull-up resistor connecting the button
to 3V3 and an LED and current limiting resistor connected to pin 12. The
application performs the same function as the button_led.py but performs a
blocking wait for the button press event instead of continuously checking the
value of the pin in order to reduce CPU usage.

5. `button_interrupt.py`: This application uses the BOARD pin numbering. It
requires a button connected to pin 18 and GND, a pull-up resistor connecting
the button to 3V3, an LED and current limiting resistor connected to pin 12
and a second LED and current limiting resistor connected to pin 13. The
application slowly blinks the first LED continuously and rapidly blinks the
second LED five times only when the button is pressed.

To run these sample applications if Jetson.GPIO is added to the PYTHONPATH:
```shell
python3 <name_of_application_to_run>
```

Alternatively, if Jetson.GPIO is not added to the PYTHONPATH, the `run_sample.sh`
script can be used to run these sample applications. This can be done with the
following command when in the samples/ directory:
```shell
./run_sample.sh <name_of_application_to_run>
```

The usage of the script can also be viewed by using:
```shell
./run_sample.sh -h
./run_sample.sh --help
```

# Complete library API

The Jetson GPIO library provides all public APIs provided by the RPi.GPIO
library. The following discusses the use of each API:

#### 1. Importing the libary

To import the Jetson.GPIO module use:
```python
import Jetson.GPIO as GPIO
```

This way, you can refer to the module as GPIO throughout the rest of the
application. The module can also be imported using the name RPi.GPIO instead of
Jetson.GPIO for existing code using the RPi library.

#### 2. Pin numbering

The Jetson GPIO library provides four ways of numbering the I/O pins. The first
two correspond to the modes provided by the RPi.GPIO library, i.e BOARD and BCM
which refer to the pin number of the 40 pin GPIO header and the Broadcom SoC
GPIO numbers respectively. The remaining two modes, CVM and TEGRA_SOC use
strings instead of numbers which correspond to signal names on the CVM/CVB
connector and the Tegra SoC respectively.

To specify which mode you are using (mandatory), use the following function
call:
```python
GPIO.setmode(GPIO.BOARD)
# or
GPIO.setmode(GPIO.BCM)
# or
GPIO.setmode(GPIO.CVM)
# or
GPIO.setmode(GPIO.TEGRA_SOC)
```

To check which mode has be set, you can call:
```python
mode = GPIO.getmode()
```

The mode must be one of GPIO.BOARD, GPIO.BCM, GPIO.CVM, GPIO.TEGRA_SOC or
None.

#### 3. Warnings

It is possible that the GPIO you are trying to use is already being used
external to the current application. In such a condition, the Jetson GPIO
library will warn you if the GPIO being used is configured to anything but the
default direction (input). It will also warn you if you try cleaning up before
setting up the mode and channels. To disable warnings, call:
```python
GPIO.setwarnings(False)
```

Additionally, Jetson.GPIO uses **warnings** module to issue warning. Therefore,
you can control the warning message using [Python Standard Library - warnings](https://docs.python.org/3/library/warnings.html#the-warnings-filter) 

#### 4. Set up a channel

The GPIO channel must be set up before use as input or output. To configure
the channel as input, call:
```python
# (where channel is based on the pin numbering mode discussed above)
GPIO.setup(channel, GPIO.IN)
```

To set up a channel as output, call:
```python
GPIO.setup(channel, GPIO.OUT)
```

It is also possible to specify an initial value for the output channel:
```python
GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)
```

When setting up a channel as output, it is also possible to set up more than one
channel at once:
```python
# add as many as channels as needed. You can also use tuples: (18,12,13)
channels = [18, 12, 13]
GPIO.setup(channels, GPIO.OUT)
```

#### 5. Input

To read the value of a channel, use:

```python
GPIO.input(channel)
```

This will return either GPIO.LOW or GPIO.HIGH.

#### 6. Output

To set the value of a pin configured as output, use:

```python
GPIO.output(channel, state)
```

where state can be GPIO.LOW or GPIO.HIGH.

You can also output to a list or tuple of channels:

```python
channels = [18, 12, 13] # or use tuples
GPIO.output(channels, GPIO.HIGH) # or GPIO.LOW
# set first channel to LOW and rest to HIGH
GPIO.output(channels, (GPIO.LOW, GPIO.HIGH, GPIO.HIGH))
```

#### 7. Clean up

At the end of the program, it is good to clean up the channels so that all pins
are set in their default state. To clean up all channels used, call:

```python
GPIO.cleanup()
```

If you don't want to clean all channels, it is also possible to clean up
individual channels or a list or tuple of channels:

```python
GPIO.cleanup(chan1) # cleanup only chan1
GPIO.cleanup([chan1, chan2]) # cleanup only chan1 and chan2
GPIO.cleanup((chan1, chan2))  # does the same operation as previous statement
```

#### 8. Jetson Board Information and library version

To get information about the Jetson module, use/read:

```python
GPIO.JETSON_INFO
```

This provides a Python dictionary with the following keys: P1_REVISION, RAM,
REVISION, TYPE, MANUFACTURER and PROCESSOR. All values in the dictionary are
strings with the exception of P1_REVISION which is an integer.

To get information about the library version, use/read:

```python
GPIO.VERSION
```

This provides a string with the X.Y.Z version format.

#### 9. Interrupts

Aside from busy-polling, the library provides three additional ways of
monitoring an input event:

##### The wait_for_edge() function

This function blocks the calling thread until the provided edge(s) is
detected. The function can be called as follows:

```python
GPIO.wait_for_edge(channel, GPIO.RISING)
```

The second parameter specifies the edge to be detected and can be
GPIO.RISING, GPIO.FALLING or GPIO.BOTH. If you only want to limit the wait
to a specified amount of time, a timeout can be optionally set:

```python
# timeout is in seconds
GPIO.wait_for_edge(channel, GPIO.RISING, timeout=500)
```

The function returns the channel for which the edge was detected or None if a
timeout occurred.

##### The event_detected() function

This function can be used to periodically check if an event occurred since the
last call. The function can be set up and called as follows:

```python
# set rising edge detection on the channel
GPIO.add_event_detect(channel, GPIO.RISING)
run_other_code()
if GPIO.event_detected(channel):
    do_something()
```

As before, you can detect events for GPIO.RISING, GPIO.FALLING or GPIO.BOTH.

##### A callback function run when an edge is detected

This feature can be used to run a second thread for callback functions. Hence,
the callback function can be run concurrent to your main program in response
to an edge. This feature can be used as follows:

```python
# define callback function
def callback_fn(channel):
    print("Callback called from channel %s" % channel)

# add rising edge detection
GPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn)
```

More than one callback can also be added if required as follows:

```python
def callback_one(channel):
    print("First Callback")

def callback_two(channel):
    print("Second Callback")

GPIO.add_event_detect(channel, GPIO.RISING)
GPIO.add_event_callback(channel, callback_one)
GPIO.add_event_callback(channel, callback_two)
```

The two callbacks in this case are run sequentially, not concurrently since
there is only thread running all callback functions.

In order to prevent multiple calls to the callback functions by collapsing
multiple events in to a single one, a debounce time can be optionally set:

```python
# bouncetime set in milliseconds
GPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn,
bouncetime=200)
```
The thread running in the background will be idle waiting for an event until
timeout, which can be optionally set as the following. The default polling
timeout is 0.2 sec. When the poll time times out, the thread will wake up and
check the thread status. If the thread is in the running state, it will go back
to the idle state waiting for another event, otherwise, the thread will exit
(event detection removal). This process will go on until the thread is in the
exit state.

```python
# polltime set in seconds
GPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn,
polltime=1)
```

If the edge detection is not longer required it can be removed as follows:

```python
GPIO.remove_event_detect(channel)
```

A timeout option can be set to wait for an event detection
to be removed, or else it is 0.5 seconds by default. It is
recommended that the timeout for removal should be at
least twice as much as the poll time.

```python
GPIO.remove_event_detect(channel, timeout=0.5)
```

#### 10. Check function of GPIO channels

This feature allows you to check the function of the provided GPIO channel:

```python
GPIO.gpio_function(channel)
```

The function returns either GPIO.IN or GPIO.OUT.

#### 11. PWM

See `samples/simple_pwm.py` for details on how to use PWM channels.

The Jetson.GPIO library supports PWM only on pins with attached hardware PWM
controllers. Unlike the RPi.GPIO library, the Jetson.GPIO library does not
implement Software emulated PWM. Jetson Nano supports 2 PWM channels, and
Jetson AGX Xavier supports 3 PWM channels. Jetson TX1 and TX2 do not support
any PWM channels.

The system pinmux must be configured to connect the hardware PWM controlller(s)
to the relevant pins. If the pinmux is not configured, PWM signals will not
reach the pins! The Jetson.GPIO library does not dynamically modify the pinmux
configuration to achieve this. Read the L4T documentation for details on how to
configure the pinmux.


# Using the Jetson GPIO library from a docker container
The following describes how to use the Jetson GPIO library from a docker container. 

## Building a docker image
`samples/docker/Dockerfile` is a sample Dockerfile for the Jetson GPIO library. The following command will build a docker image named `testimg` from it. 

```shell
sudo docker image build -f samples/docker/Dockerfile -t testimg .
```

## Running the container
### Basic options 
You should map `/dev` into the container to access to the GPIO pins.
So you need to add these options to `docker container run` command.

```shell
--device /dev/gpiochip0 \
```

and if you want to use GPU from the container you also need to add these options:
```shell
--runtime=nvidia --gpus all
```


### Running the container in privilleged mode
The library determines the jetson model by checking `/proc/device-tree/compatible` and `/proc/device-tree/chosen` by default.
These paths only can be mapped into the container in privilleged mode.

The following example will run `/bin/bash` from the container in privilleged mode. 
```shell
sudo docker container run -it --rm \
--runtime=nvidia --gpus all \
--privileged \
-v /proc/device-tree/compatible:/proc/device-tree/compatible \
-v /proc/device-tree/chosen:/proc/device-tree/chosen \
--device /dev/gpiochip0 \
testimg /bin/bash
```

### Running the container in non-privilleged mode
If you don't want to run the container in privilleged mode, you can directly provide your jetson model name to the library through the environment variable `JETSON_MODEL_NAME`:  
 
```shell
# ex> -e JETSON_MODEL_NAME=JETSON_NANO
-e JETSON_MODEL_NAME=[PUT_YOUR_JETSON_MODEL_NAME_HERE]
``` 

You can get the proper value for this variable by running `samples/jetson_model.py` on the host or in previlleged mode.
```shell
# run on the host or in previlleged mode
sudo python3 samples/jetson_model.py
```


The following example will run `/bin/bash` from the container in non-privilleged mode. 

```shell
sudo docker container run -it --rm \
--runtime=nvidia --gpus all \
--device /dev/gpiochip0 \
-e JETSON_MODEL_NAME=[PUT_YOUR_JETSON_MODEL_NAME_HERE] \
testimg /bin/bash
```


# Obtaining L4T Documentation

The L4T documentation may be available in the following locations:

* [Jetson Download Center](https://developer.nvidia.com/embedded/downloads);
search for the "L4T Documentation" package.
* [docs.nvidia.com](https://docs.nvidia.com/jetson/l4t/).

Within the documentation, relevant topics may be found by searching for e.g.:
* Hardware Setup.
* Configuring the 40-Pin Expansion Header.
* Jetson-IO.
* Platform Adaptation and Bring-Up.
* Pinmux Changes.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NVIDIA/jetson-gpio",
    "name": "Jetson.GPIO",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Jetson GPIO",
    "author": "NVIDIA",
    "author_email": "linux-tegra-bugs@nvidia.com",
    "download_url": "https://files.pythonhosted.org/packages/ab/8f/fb59c8dd6ad3d983c7dbe2e4c1e2af7343031760960cefe0bfeb2ab0e946/Jetson.GPIO-2.1.6.tar.gz",
    "platform": null,
    "description": "# Jetson.GPIO - Linux for Tegra\n\nJetson TX1, TX2, AGX Xavier, and Nano development boards contain a 40 pin GPIO\nheader, similar to the 40 pin header in the Raspberry Pi. These GPIOs can be\ncontrolled for digital input and output using the Python library provided in the\nJetson GPIO Library package. The library has the same API as the RPi.GPIO\nlibrary for Raspberry Pi in order to provide an easy way to move applications\nrunning on the Raspberry Pi to the Jetson board.\n\nThis document walks through what is contained in The Jetson GPIO library\npackage, how to configure the system and run the provided sample applications,\nand the library API.\n\n# Package Components\n\nIn addition to this document, the Jetson GPIO library package contains the\nfollowing:\n\n1. The `lib/python/` subdirectory contains the Python modules that implement all\nlibrary functionality. The gpio.py module is the main component that will be\nimported into an application and provides the needed APIs. The `gpio_event.py`\nand `gpio_pin_data.py` modules are used by the `gpio.py` module and must not be\nimported directly in to an application.\n\n2. The `samples/` subdirectory contains sample applications to help in getting\nfamiliar with the library API and getting started on an application. The\n`simple_input.py` and `simple_output.py` applications show how to perform read\nand write to a GPIO pin respectively, while the `button_led.py`,\n`button_event.py` and `button_interrupt.py` show how a button press may be used\nto blink an LED using busy-waiting, blocking wait and interrupt callbacks\nrespectively.\n\n# Installation\n\nThese are the way to install Jetson.GPIO python modules on your system. For the samples applications, please clone this repository to your system. \n\n## Using pip\n\nThe easiest way to install this library is using `pip`:\n```shell\nsudo pip install Jetson.GPIO\n```\n\n## Manual download \n\nYou may clone this git repository, or download a copy of it as an archive file\nand decompress it. You may place the library files anywhere you like on your\nsystem. You may use the library directly from this directory by manually\nsetting `PYTHONPATH`, or install it using `setup.py`:\n```shell\nsudo python3 setup.py install\n```\n\n# Setting User Permissions\n\nIn order to use the Jetson GPIO Library, the correct user permissions/groups must\nbe set first.\n\nCreate a new gpio user group. Then add your user to the newly created group.\n```shell\nsudo groupadd -f -r gpio\nsudo usermod -a -G gpio your_user_name\n```\n\nInstall custom udev rules by copying the 99-gpio.rules file into the rules.d\ndirectory.\n\nIf you have downloaded the source to Jetson.GPIO:\n```shell\nsudo cp lib/python/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/\n```\n\nIf you installed Jetson.GPIO from a package, e.g. using pip into a virtual\nenvironment:\n```shell\nsudo cp venv/lib/pythonNN/site-packages/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/\n```\n\nFor the new rule to take place, you either need to reboot or reload the udev\nrules by running:\n```shell\nsudo udevadm control --reload-rules && sudo udevadm trigger\n```\n\n# Running the sample scripts\n\nWith the permissions set as needed, the sample applications provided in the\n`samples/` directory can be used. The following describes the operation of each\napplication:\n\n1. `simple_input.py`: This application uses the BCM pin numbering mode and reads\nthe value at pin 12 of the 40 pin header and prints the value to the\nscreen.\n\n2. `simple_out.py`: This application uses the BCM pin numbering mode from\nRaspberry Pi and outputs alternating high and low values at BCM pin 18 (or\nboard pin 12 on the header) every 2 seconds.\n\n3. `button_led.py`: This application uses the BOARD pin numbering. It requires a\nbutton connected to pin 18 and GND, a pull-up resistor connecting pin 18\nto 3V3 and an LED and current limiting resistor connected to pin 12. The\napplication reads the button state and keeps the LED on for 1 second every\ntime the button is pressed.\n\n4. `button_event.py`: This application uses the BOARD pin numbering. It requires a\nbutton connected to pin 18 and GND, a pull-up resistor connecting the button\nto 3V3 and an LED and current limiting resistor connected to pin 12. The\napplication performs the same function as the button_led.py but performs a\nblocking wait for the button press event instead of continuously checking the\nvalue of the pin in order to reduce CPU usage.\n\n5. `button_interrupt.py`: This application uses the BOARD pin numbering. It\nrequires a button connected to pin 18 and GND, a pull-up resistor connecting\nthe button to 3V3, an LED and current limiting resistor connected to pin 12\nand a second LED and current limiting resistor connected to pin 13. The\napplication slowly blinks the first LED continuously and rapidly blinks the\nsecond LED five times only when the button is pressed.\n\nTo run these sample applications if Jetson.GPIO is added to the PYTHONPATH:\n```shell\npython3 <name_of_application_to_run>\n```\n\nAlternatively, if Jetson.GPIO is not added to the PYTHONPATH, the `run_sample.sh`\nscript can be used to run these sample applications. This can be done with the\nfollowing command when in the samples/ directory:\n```shell\n./run_sample.sh <name_of_application_to_run>\n```\n\nThe usage of the script can also be viewed by using:\n```shell\n./run_sample.sh -h\n./run_sample.sh --help\n```\n\n# Complete library API\n\nThe Jetson GPIO library provides all public APIs provided by the RPi.GPIO\nlibrary. The following discusses the use of each API:\n\n#### 1. Importing the libary\n\nTo import the Jetson.GPIO module use:\n```python\nimport Jetson.GPIO as GPIO\n```\n\nThis way, you can refer to the module as GPIO throughout the rest of the\napplication. The module can also be imported using the name RPi.GPIO instead of\nJetson.GPIO for existing code using the RPi library.\n\n#### 2. Pin numbering\n\nThe Jetson GPIO library provides four ways of numbering the I/O pins. The first\ntwo correspond to the modes provided by the RPi.GPIO library, i.e BOARD and BCM\nwhich refer to the pin number of the 40 pin GPIO header and the Broadcom SoC\nGPIO numbers respectively. The remaining two modes, CVM and TEGRA_SOC use\nstrings instead of numbers which correspond to signal names on the CVM/CVB\nconnector and the Tegra SoC respectively.\n\nTo specify which mode you are using (mandatory), use the following function\ncall:\n```python\nGPIO.setmode(GPIO.BOARD)\n# or\nGPIO.setmode(GPIO.BCM)\n# or\nGPIO.setmode(GPIO.CVM)\n# or\nGPIO.setmode(GPIO.TEGRA_SOC)\n```\n\nTo check which mode has be set, you can call:\n```python\nmode = GPIO.getmode()\n```\n\nThe mode must be one of GPIO.BOARD, GPIO.BCM, GPIO.CVM, GPIO.TEGRA_SOC or\nNone.\n\n#### 3. Warnings\n\nIt is possible that the GPIO you are trying to use is already being used\nexternal to the current application. In such a condition, the Jetson GPIO\nlibrary will warn you if the GPIO being used is configured to anything but the\ndefault direction (input). It will also warn you if you try cleaning up before\nsetting up the mode and channels. To disable warnings, call:\n```python\nGPIO.setwarnings(False)\n```\n\nAdditionally, Jetson.GPIO uses **warnings** module to issue warning. Therefore,\nyou can control the warning message using [Python Standard Library - warnings](https://docs.python.org/3/library/warnings.html#the-warnings-filter) \n\n#### 4. Set up a channel\n\nThe GPIO channel must be set up before use as input or output. To configure\nthe channel as input, call:\n```python\n# (where channel is based on the pin numbering mode discussed above)\nGPIO.setup(channel, GPIO.IN)\n```\n\nTo set up a channel as output, call:\n```python\nGPIO.setup(channel, GPIO.OUT)\n```\n\nIt is also possible to specify an initial value for the output channel:\n```python\nGPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)\n```\n\nWhen setting up a channel as output, it is also possible to set up more than one\nchannel at once:\n```python\n# add as many as channels as needed. You can also use tuples: (18,12,13)\nchannels = [18, 12, 13]\nGPIO.setup(channels, GPIO.OUT)\n```\n\n#### 5. Input\n\nTo read the value of a channel, use:\n\n```python\nGPIO.input(channel)\n```\n\nThis will return either GPIO.LOW or GPIO.HIGH.\n\n#### 6. Output\n\nTo set the value of a pin configured as output, use:\n\n```python\nGPIO.output(channel, state)\n```\n\nwhere state can be GPIO.LOW or GPIO.HIGH.\n\nYou can also output to a list or tuple of channels:\n\n```python\nchannels = [18, 12, 13] # or use tuples\nGPIO.output(channels, GPIO.HIGH) # or GPIO.LOW\n# set first channel to LOW and rest to HIGH\nGPIO.output(channels, (GPIO.LOW, GPIO.HIGH, GPIO.HIGH))\n```\n\n#### 7. Clean up\n\nAt the end of the program, it is good to clean up the channels so that all pins\nare set in their default state. To clean up all channels used, call:\n\n```python\nGPIO.cleanup()\n```\n\nIf you don't want to clean all channels, it is also possible to clean up\nindividual channels or a list or tuple of channels:\n\n```python\nGPIO.cleanup(chan1) # cleanup only chan1\nGPIO.cleanup([chan1, chan2]) # cleanup only chan1 and chan2\nGPIO.cleanup((chan1, chan2))  # does the same operation as previous statement\n```\n\n#### 8. Jetson Board Information and library version\n\nTo get information about the Jetson module, use/read:\n\n```python\nGPIO.JETSON_INFO\n```\n\nThis provides a Python dictionary with the following keys: P1_REVISION, RAM,\nREVISION, TYPE, MANUFACTURER and PROCESSOR. All values in the dictionary are\nstrings with the exception of P1_REVISION which is an integer.\n\nTo get information about the library version, use/read:\n\n```python\nGPIO.VERSION\n```\n\nThis provides a string with the X.Y.Z version format.\n\n#### 9. Interrupts\n\nAside from busy-polling, the library provides three additional ways of\nmonitoring an input event:\n\n##### The wait_for_edge() function\n\nThis function blocks the calling thread until the provided edge(s) is\ndetected. The function can be called as follows:\n\n```python\nGPIO.wait_for_edge(channel, GPIO.RISING)\n```\n\nThe second parameter specifies the edge to be detected and can be\nGPIO.RISING, GPIO.FALLING or GPIO.BOTH. If you only want to limit the wait\nto a specified amount of time, a timeout can be optionally set:\n\n```python\n# timeout is in seconds\nGPIO.wait_for_edge(channel, GPIO.RISING, timeout=500)\n```\n\nThe function returns the channel for which the edge was detected or None if a\ntimeout occurred.\n\n##### The event_detected() function\n\nThis function can be used to periodically check if an event occurred since the\nlast call. The function can be set up and called as follows:\n\n```python\n# set rising edge detection on the channel\nGPIO.add_event_detect(channel, GPIO.RISING)\nrun_other_code()\nif GPIO.event_detected(channel):\n    do_something()\n```\n\nAs before, you can detect events for GPIO.RISING, GPIO.FALLING or GPIO.BOTH.\n\n##### A callback function run when an edge is detected\n\nThis feature can be used to run a second thread for callback functions. Hence,\nthe callback function can be run concurrent to your main program in response\nto an edge. This feature can be used as follows:\n\n```python\n# define callback function\ndef callback_fn(channel):\n    print(\"Callback called from channel %s\" % channel)\n\n# add rising edge detection\nGPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn)\n```\n\nMore than one callback can also be added if required as follows:\n\n```python\ndef callback_one(channel):\n    print(\"First Callback\")\n\ndef callback_two(channel):\n    print(\"Second Callback\")\n\nGPIO.add_event_detect(channel, GPIO.RISING)\nGPIO.add_event_callback(channel, callback_one)\nGPIO.add_event_callback(channel, callback_two)\n```\n\nThe two callbacks in this case are run sequentially, not concurrently since\nthere is only thread running all callback functions.\n\nIn order to prevent multiple calls to the callback functions by collapsing\nmultiple events in to a single one, a debounce time can be optionally set:\n\n```python\n# bouncetime set in milliseconds\nGPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn,\nbouncetime=200)\n```\nThe thread running in the background will be idle waiting for an event until\ntimeout, which can be optionally set as the following. The default polling\ntimeout is 0.2 sec. When the poll time times out, the thread will wake up and\ncheck the thread status. If the thread is in the running state, it will go back\nto the idle state waiting for another event, otherwise, the thread will exit\n(event detection removal). This process will go on until the thread is in the\nexit state.\n\n```python\n# polltime set in seconds\nGPIO.add_event_detect(channel, GPIO.RISING, callback=callback_fn,\npolltime=1)\n```\n\nIf the edge detection is not longer required it can be removed as follows:\n\n```python\nGPIO.remove_event_detect(channel)\n```\n\nA timeout option can be set to wait for an event detection\nto be removed, or else it is 0.5 seconds by default. It is\nrecommended that the timeout for removal should be at\nleast twice as much as the poll time.\n\n```python\nGPIO.remove_event_detect(channel, timeout=0.5)\n```\n\n#### 10. Check function of GPIO channels\n\nThis feature allows you to check the function of the provided GPIO channel:\n\n```python\nGPIO.gpio_function(channel)\n```\n\nThe function returns either GPIO.IN or GPIO.OUT.\n\n#### 11. PWM\n\nSee `samples/simple_pwm.py` for details on how to use PWM channels.\n\nThe Jetson.GPIO library supports PWM only on pins with attached hardware PWM\ncontrollers. Unlike the RPi.GPIO library, the Jetson.GPIO library does not\nimplement Software emulated PWM. Jetson Nano supports 2 PWM channels, and\nJetson AGX Xavier supports 3 PWM channels. Jetson TX1 and TX2 do not support\nany PWM channels.\n\nThe system pinmux must be configured to connect the hardware PWM controlller(s)\nto the relevant pins. If the pinmux is not configured, PWM signals will not\nreach the pins! The Jetson.GPIO library does not dynamically modify the pinmux\nconfiguration to achieve this. Read the L4T documentation for details on how to\nconfigure the pinmux.\n\n\n# Using the Jetson GPIO library from a docker container\nThe following describes how to use the Jetson GPIO library from a docker container. \n\n## Building a docker image\n`samples/docker/Dockerfile` is a sample Dockerfile for the Jetson GPIO library. The following command will build a docker image named `testimg` from it. \n\n```shell\nsudo docker image build -f samples/docker/Dockerfile -t testimg .\n```\n\n## Running the container\n### Basic options \nYou should map `/dev` into the container to access to the GPIO pins.\nSo you need to add these options to `docker container run` command.\n\n```shell\n--device /dev/gpiochip0 \\\n```\n\nand if you want to use GPU from the container you also need to add these options:\n```shell\n--runtime=nvidia --gpus all\n```\n\n\n### Running the container in privilleged mode\nThe library determines the jetson model by checking `/proc/device-tree/compatible` and `/proc/device-tree/chosen` by default.\nThese paths only can be mapped into the container in privilleged mode.\n\nThe following example will run `/bin/bash` from the container in privilleged mode. \n```shell\nsudo docker container run -it --rm \\\n--runtime=nvidia --gpus all \\\n--privileged \\\n-v /proc/device-tree/compatible:/proc/device-tree/compatible \\\n-v /proc/device-tree/chosen:/proc/device-tree/chosen \\\n--device /dev/gpiochip0 \\\ntestimg /bin/bash\n```\n\n### Running the container in non-privilleged mode\nIf you don't want to run the container in privilleged mode, you can directly provide your jetson model name to the library through the environment variable `JETSON_MODEL_NAME`:  \n \n```shell\n# ex> -e JETSON_MODEL_NAME=JETSON_NANO\n-e JETSON_MODEL_NAME=[PUT_YOUR_JETSON_MODEL_NAME_HERE]\n``` \n\nYou can get the proper value for this variable by running `samples/jetson_model.py` on the host or in previlleged mode.\n```shell\n# run on the host or in previlleged mode\nsudo python3 samples/jetson_model.py\n```\n\n\nThe following example will run `/bin/bash` from the container in non-privilleged mode. \n\n```shell\nsudo docker container run -it --rm \\\n--runtime=nvidia --gpus all \\\n--device /dev/gpiochip0 \\\n-e JETSON_MODEL_NAME=[PUT_YOUR_JETSON_MODEL_NAME_HERE] \\\ntestimg /bin/bash\n```\n\n\n# Obtaining L4T Documentation\n\nThe L4T documentation may be available in the following locations:\n\n* [Jetson Download Center](https://developer.nvidia.com/embedded/downloads);\nsearch for the \"L4T Documentation\" package.\n* [docs.nvidia.com](https://docs.nvidia.com/jetson/l4t/).\n\nWithin the documentation, relevant topics may be found by searching for e.g.:\n* Hardware Setup.\n* Configuring the 40-Pin Expansion Header.\n* Jetson-IO.\n* Platform Adaptation and Bring-Up.\n* Pinmux Changes.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A module to control Jetson GPIO channels",
    "version": "2.1.6",
    "project_urls": {
        "Homepage": "https://github.com/NVIDIA/jetson-gpio"
    },
    "split_keywords": [
        "jetson",
        "gpio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab8ffb59c8dd6ad3d983c7dbe2e4c1e2af7343031760960cefe0bfeb2ab0e946",
                "md5": "1a2f2553de5bf97111e61cdb27194202",
                "sha256": "af8ff56b554e1f36662d19fff3d23e7c5ac261ac51ce7b1894447e64746760a2"
            },
            "downloads": -1,
            "filename": "Jetson.GPIO-2.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "1a2f2553de5bf97111e61cdb27194202",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 33178,
            "upload_time": "2024-01-10T18:35:51",
            "upload_time_iso_8601": "2024-01-10T18:35:51.135818Z",
            "url": "https://files.pythonhosted.org/packages/ab/8f/fb59c8dd6ad3d983c7dbe2e4c1e2af7343031760960cefe0bfeb2ab0e946/Jetson.GPIO-2.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-10 18:35:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NVIDIA",
    "github_project": "jetson-gpio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jetson.gpio"
}
        
Elapsed time: 0.18786s