Software PWM on Orin Nano any GPIO pin

Hi there,

I was discussing with AI the possibilities of generating a software PWM signal (as opposed to hardware PWM) on pin 19, 21 and 23 for instance.

My point is to drive LEDs with PWM, so I was wondering if there was an easy way to do this, please.

Thank you!

Tom

Hello @tom.hall1 ,

Here is a guide for the Jetson GPIO Library: How to test GPIO with Jetson GPIO Library

You can take this example as a starting point for your implementation.

Feel free to contact us for more details.

Felipe Solano
Embedded SW Engineer at RidgeRun
Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com
Website: www.ridgerun.com

Hello @felipe.solano

Thank you for this, but I was hoping for a way to put software PWM on any gpio of the Jetson Nano or Orin.

Do you know how I could do that please?

Thank you !

Hello @tom.hall1 ,

Here is a general scaffold for a implementation on the pins you are mentioning. It is mostly the same example of the shared Wiki and I added a couple of loops:

import Jetson.GPIO as GPIO
import time

# Test pins on Orin Nano
output_pins = [19, 21, 23]

# Software PWM settings
frequency = 10      # Hz
duty_cycle = 50     # percent
duration = 10       # seconds


def main():
    GPIO.setmode(GPIO.BOARD)

    for output_pin in output_pins:
        GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.LOW)

    period = 1.0 / frequency
    high_time = period * (duty_cycle / 100.0)
    low_time = period - high_time

    start_time = time.time()

    try:
        while time.time() - start_time < duration:
            print("--> GPIOs set to High")
            for output_pin in output_pins:
                GPIO.output(output_pin, GPIO.HIGH)
            time.sleep(high_time)

            print("--> GPIOs set to Low")
            for output_pin in output_pins:
                GPIO.output(output_pin, GPIO.LOW)
            time.sleep(low_time)

    except KeyboardInterrupt:
        print("--> Stopped by user")

    for output_pin in output_pins:
        GPIO.output(output_pin, GPIO.LOW)

    GPIO.cleanup()


if __name__ == '__main__':
    main()

Feel free to contact us for more details.

Felipe Solano
Embedded SW Engineer at RidgeRun
Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com
Website: www.ridgerun.com