I tried running two Jetson Nano hardware PWMs from the Jetson.GPIO Python library.

Introduction

The PWM sample script that comes with the Jetson.GPIO Python library has finally worked, so make a note of it. First is the video. <img width = "50%" alt = "Screenshot 2020-01-13 14.41.50.png " src = "https://qiita-image" -store.s3.ap-northeast-1.amazonaws.com/0/72479/f86ca2dc-6388-10e9-8586-a338a3766792.png ">

The other five sample scripts were written in the book "Jetson Nano Super Primer". 1251.jpg

Sample script

simple_pwm.py The library's README.md only says "See simple_pwm.py for details on how to use PWM channels", which was difficult to understand compared to other sample scripts.

"The Jetson.GPIO library only supports PWM on the pin to which the hardware PWM controller is connected. Unlike the RPi.GPIO library, the Jetson.GPIO library does not implement software emulated PWM. Jetson Nano Supports two hardware PWM channels. The system pinmux must be configured to connect a hardware PWM controller to the associated pin. If pinmux is not configured, the PWM signal will reach the pin. No. The Jetson.GPIO library does not dynamically change the pinmux configuration to achieve this. Read the L4T documentation for more information on how to configure pinmux. "

The hurdles such as pinmux and L4T (= Linux for Tegra) documents were high, but I finally caught up with my understanding and was able to move it safely. First of all, I was able to run the sample script as long as I had the correct pinmux settings. The Jetson-IO tool added in JetPack 4.3 (r32.3.1) made it easier to set up Pinmux.

(reference) I set up a Pinmux table using the Jetson-IO tool added in JetPack 4.3 (r32.3.1). I tried using two hardware PWMs from Jetson Nano.

Modified script to move servo motor

First, understand the contents of the included sample script.

--For Jetson Nano, use pin 33 for PWM output. --Set the PWM cycle (cycle) to 20 ms (50 Hz). --Set the duty ratio (pulse width divided by period) to 25%.

simple_pwm.py


import RPi.GPIO as GPIO
import time

output_pins = {
    'JETSON_XAVIER': 18,
    'JETSON_NANO': 33,
}
output_pin = output_pins.get(GPIO.model, None)
if output_pin is None:
    raise Exception('PWM not supported on this board')


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)
    p = GPIO.PWM(output_pin, 50)
    p.start(25)

    print("PWM running. Press CTRL+C to exit.")
    try:
        while True:
            time.sleep(1)
    finally:
        p.stop()
        GPIO.cleanup()

if __name__ == '__main__':
    main()

The script needs to be modified because it uses two servo motors (Geekservo 9g 360 ° servo motors).

--Pin setting Change to 2 (32 pins, 33 pins) --PWM cycle 20 ms (50 Hz) → No change --Control pulse 0.5 ms ~ 2.4 ms → Change the duty ratio to 2.5% (rotate in the -90 ° direction) ~ 7.25% (0 ° = rest) ~ 12% (rotate in the + 90 ° direction)

(Modified script)

simple_pwm_servo.py


#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

output_pin1 = 32
output_pin2 = 33

def main():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(output_pin1, GPIO.OUT, initial=GPIO.HIGH)
    p1 = GPIO.PWM(output_pin1, 50)
    GPIO.setup(output_pin2, GPIO.OUT, initial=GPIO.HIGH)
    p2 = GPIO.PWM(output_pin2, 50)

    print("PWM running. Press CTRL+C to exit.")
    try:
        while True:
            p1.start(2.5)
            print("p1 start at 2.5%")
            time.sleep(1)
            p2.start(2.5)
            print("p2 start at 2.5%")
            time.sleep(1)
            p1.start(7.25)
            print("p1 start at 7.25%")
            time.sleep(1)
            p2.start(7.25)
            print("p2 start at 7.25%")
            time.sleep(1)
            p1.start(12)
            print("p1 start at 12%")
            time.sleep(1)
            p2.start(12)
            print("p2 start at 12%")
            time.sleep(1)
            p1.start(7.25)
            print("p1 start at 7.25%")
            time.sleep(1)
            p2.start(7.25)
            print("p2 start at 7.25%")
            time.sleep(1)
    finally:
        p1.stop()
        p2.stop()
        GPIO.cleanup()

if __name__ == '__main__':
    main()

(Execution result)

$ python3 simple_pwm_servo.py
PWM running. Press CTRL+C to exit.
p1 start at 2.5%
p2 start at 2.5%
p1 start at 7.25%
p2 start at 7.25%
p1 start at 12%
p2 start at 12%
p1 start at 7.25%
p2 start at 7.25%
...

Recommended Posts

I tried running two Jetson Nano hardware PWMs from the Jetson.GPIO Python library.
I tried using the Python library from Ruby with PyCall
I tried running python etc. from a bat file
I wanted to use the Python library from MATLAB
I tried the changefinder library!
I tried face recognition from the video (OpenCV: python version)
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried Grumpy (Go running Python).
I tried running prolog with python 3.8.2.
I tried running the Python Package Repository (Warehouse) that supports PyPI
I tried using UnityCloudBuild API from Python
Python: I tried the traveling salesman problem
I tried the Python Tornado Testing Framework
I tried using the Python library "pykakasi" that can convert kanji to romaji.
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
[Python] I tried to get the type name as a string from the type function
[Python] I tried the same calculation as LSTM predict with from scratch [Keras]
[Python] I tried substituting the function name for the function name
I tried hitting the Qiita API from go
vprof --I tried using the profiler for Python
I tried "differentiating" the image with Python + OpenCV
I tried the least squares method in Python
I tried python programming for the first time.
I tried debugging from Python via System Console
I tried "binarizing" the image with Python + OpenCV
I tried running faiss with python, Go, Rust
I tried using the Datetime module by Python
I tried running python -m summpy.server -h 127.0.0.1 -p 8080
I tried running Deep Floor Plan with Python 3.6.10.
I tried running alembic, a Python migration tool
I tried using the functional programming library toolz
I tried to extract various information of remote PC from Python by WMI Library
I tried to graph the packages installed in Python
I tried Python on Mac for the first time.
Touching the latest physics-based renderer Mitsuba2 (2) Running from Python
I tried to detect the iris from the camera image
I tried running the app on the IoT platform "Rimotte"
I tried to solve the soma cube with python
[Python] I tried to graph the top 10 eyeshadow rankings
[Python] I tried running a local server using flask
I tried to solve the problem with Python Vol.1
I tried LeetCode every day 1. Two Sum (Python, Go)
I tried hitting the API with echonest's python client
I tried running the sample code of the Ansible module
I tried to summarize the string operations of Python
I tried running the offline speech recognition system Julius with python in the Docker virtual environment
I tried running pymc
I tried Python> autopep8
I tried Python> decorator
I tried running TensorFlow
I tried the site "Deploy Azure virtual machine from Go"
I tried to find the entropy of the image with python
I tried "gamma correction" of the image with Python + OpenCV
I tried to simulate how the infection spreads with Python
I tried the accuracy of three Stirling's approximations in python
I tried to create API list.csv in Python from swagger.yaml
I tried running PIFuHD on Windows for the time being
I tried running Movidius NCS with python of Raspberry Pi3
[Python] I installed the game from pip and played it
I tried programming the chi-square test in Python and Java.
[Python] I tried to visualize the follow relationship of Twitter