Jetson Nano GPIO Description

 

1. Jetson.GPIO library

Jetson.GPIO library is pre-installed Nano, without the need to install additional GPIO Python library, if the library is installed GPIO other party may need to uninstall applicable Jetson.GPIO normal, pre-installation path:

/opt/nvidia/jetson-gpio

Need to run the following steps before running Jetson.GPIO, establish GPIO operating environment
Step one - Set permission to run Setup permissions

sudo groupadd -f -r gpio
sudo usermod -a -G gpio jetbot  #$USER
sudo cp /opt/nvidia/jetson-gpio/etc/99-gpio.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger

sudo reboot now

Step two - Python code reference
After addition the following Python code, it can call the import the RPi.GPIO (motorhat library or the like)

import sys
sys.path.append('/opt/nvidia/jetson-gpio/lib/python/')
sys.path.append('/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO')
import Jetson.GPIO

Step three: Python GPIO Case
GPIO Mode

GPIO.setmode(GPIO.BOARD)
# or
GPIO.setmode(GPIO.BCM)
# or
GPIO.setmode(GPIO.CVM)
# or
GPIO.setmode(GPIO.TEGRA_SOC)

Case Code verified as follows (measured J41 PIN13, every 2s set high set low i.e. 0/1/0/1)

#!/usr/bin/env python
#BCM 是Broadcom SOC GPIO序列号,此处需修改为BOARD
#即Nano载板的40Pin GPIO序列号,参考上图<Nano_J41_40Pin.png>

#import jetson gpio
import sys
sys.path.append('/opt/nvidia/jetson-gpio/lib/python/')
sys.path.append('/opt/nvidia/jetson-gpio/lib/python/Jetson/GPIO')

import Jetson.GPIO as GPIO
import time

# Pin Definitions
output_pin = 13  #J41_BOARD_PIN13---gpio14/GPIO.B06/SPI2_SCK

def main():
    # Pin Setup:
    # Board pin-numbering scheme
    GPIO.setmode(GPIO.BOARD)
    # set pin as an output pin with optional initial state of HIGH
    GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.HIGH)

    print("Starting demo now! Press CTRL+C to exit")
    curr_value = GPIO.HIGH
    try:
        while True:
            time.sleep(2)
            # Toggle the output every second
            print("Outputting {} to pin {}".format(curr_value, output_pin))
            GPIO.output(output_pin, curr_value)
            curr_value ^= GPIO.HIGH
    finally:
        GPIO.cleanup()

if __name__ == '__main__':
    main()

2. HC-SR04 Ultrasonic Applications

#!/usr/bin/env python
#BCM 是Broadcom SOC GPIO序列号,此处需修改为BOARD
#即Nano载板的40Pin GPIO序列号,参考上图<Nano_J41_40Pin.png>

import Jetson.GPIO as GPIO
import time

# Pin Definitions
trig_output_pin = 13  #发射PIN,J41_BOARD_PIN13---gpio14/GPIO.B06/SPI2_SCK
echo_input_pin = 18  #接收PIN,J41_BOARD_PIN18---gpio15/GPIO.B07/SPI2_CS0

def main():
    # Pin Setup:
    # Board pin-numbering scheme
    GPIO.setmode(GPIO.BOARD)
    # set pin as an output pin with optional initial state of LOW
    GPIO.setup(trig_output_pin, GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(echo_input_pin, GPIO.IN)
    #value = GPIO.input(echo_input_pin)
    #print("Value read from pin {} : {}".format(echo_input_pin,value_str))

    print("Starting Measure now! Press CTRL+C to exit")
    try:
        while True:
            # Toggle the output every second
            GPIO.output(trig_output_pin, GPIO.HIGH)
            time.sleep(0.00001)
            GPIO.output(trig_output_pin, GPIO.LOW)
         
            pulse_start = time.time()
            while GPIO.input(echo_input_pin)==0:
                    pulse_start = time.time()

                    pulse_end = time.time()
                    while GPIO.input(echo_input_pin)==1:
                            pulse_end = time.time()

                            pulse_duration = pulse_end - pulse_start
                            distance = pulse_duration * 17150
                            distance = round(distance, 2)

                            print ("Distance" , distance)
            
    finally:
        GPIO.cleanup()


if __name__ == '__main__':
    main()

3. Jetson Nano GPIO some explanations:

Support PWM Library does not Jetson.GPIO **
(does not support PWM, such as the need requires external PWM signal PWM of a transfer board the I2C)
HOWEVER, at The CAN Board following the I2C Controlled the Generate up to ~ 1.6 kHz PWM Signals Should have have Python and the Libraries the Available.
https://www.adafruit.com/product/815

You could potentially connect this to whatever H-Bridge meets the power requirements of your application. The motor driver we used for JetBot actually combines this chip and multiple H-bridge on the same board.
https://www.adafruit.com/product/2927

PS:
NVIDIA Forum:
Nano GPIO Python support
https://pypi.org/project/Jetson.GPIO/

Jetson Nano GPIO description Part code directory and
the GPIO the DTS:
Hardware / NVIDIA / Platform / T210 / porg / DTS-Kernel / porg-Platforms / tegra210-porg-GPIO-p3448-0002-a02.dtsi

P37-gpio12-GPIO.B04
P22-gpio13-GPIO.B05
P13-gpio14-GPIO.B06
P18-gpio15-GPIO.B07
VDD-USB-HUB-EN gpio151-GPIO.S07

IMX219 DTS:
hardware\nvidia\platform\t210\porg\kernel-dts\porg-platforms\tegra210-porg-camera-rbpcv2-imx219.dtsi

发布了4 篇原创文章 · 获赞 8 · 访问量 9119

Guess you like

Origin blog.csdn.net/u012254599/article/details/103352125