Use Buzzer with Nvidia Jetson Orin Nano GPIO

Use Buzzer with Nvidia Jetson Orin Nano GPIO

Introduction 

The NVIDIA Jetson Orin Nano Developer Kit carrier boards include a 40-pin expansion header (UART, SPI, I2S, I2C, GPIO). Much like an Arduino or Raspberry Pi, the GPIO pins can be used to buzz a buzzer. 

Hardware

 

Connect the positive leg of your passive buzzer to the 7th pin on the Nvidia Jetson Orin Nano.

 

Connect the negative leg to a GND (ground) pin on the Nvidia Jetson Orin Nano such as the 6th pin.

 

 

Software

Turn on your NVIDIA Jetson Orin Nano, open a new terminal window and first check that Jetson.GPIO is installed

 

sudo pip install Jetson.GPIO

 

It should say Requirement already satisfied: Jetson.GPIO in …

 

 

Create a new Python file named buzz_buzzer.py 

 

touch buzz_buzzer.py

 

Now let’s edit the buzz_buzzer.py file 

 

gedit buzz_buzzer.py

 

For the start, we are going to import the necessary libraries needed 

 

import Jetson.GPIO as GPIO
import time

 

Then we declare which PIN the LED is connected to

 

buzzer_pin = 15  

 

We then set to GPIO to use the physical pin number and for the pin to output

 

GPIO.setmode(GPIO.BOARD) 
GPIO.setup(buzzer_pin, GPIO.OUT, initial=GPIO.LOW) 

 

We are going to define a function called beep(). A passive buzzer requires a rapid pulse signal. We can accomplish this by switching between sending HIGH and LOW signals with a very, very small delay in between

 

def beep():
    for i in range(10):
        GPIO.output(buzzer_pin, GPIO.HIGH)
        time.sleep(0.0005)
        GPIO.output(buzzer_pin, GPIO.LOW)
        time.sleep(0.0005)

 

Then start a try-except block. Inside the try block, we will use a while statement. Inside the while statement, the code will repeatedly execute. So here we repeatedly call our beep function and wait for another 500 milliseconds. 

 

try:
    while True:
        beep()
        time.sleep(0.5)

 

Lastly, finish the try-except block with the except block specifying KeyboardInterrupt. This block will make our program safely close when we want to close the program. 

 

except KeyboardInterrupt:
    print("Exiting gracefully")
    GPIO.cleanup()

 

The completed code should look like this:
 

import Jetson.GPIO as GPIO
import time

buzzer_pin = 15

GPIO.setmode(GPIO.BOARD)
GPIO.setup(buzzer_pin, GPIO.OUT,initial=GPIO.LOW)

def beep():
    for i in range(10):
        GPIO.output(buzzer_pin, GPIO.HIGH)
        time.sleep(0.0005)
        GPIO.output(buzzer_pin, GPIO.LOW)
        time.sleep(0.0005)

try:
    while True:
        beep()
        time.sleep(0.5)

except KeyboardInterrupt:
    print("Exiting gracefully")
    GPIO.cleanup()

 

Click on the Save button to save the code and then close gedit (the text editor program)

 

 

We can now launch the buzz_buzzer.py program 

 

python3 buzz_buzzer.py

 

When you are finished, you can press Ctrl + C to safely stop the program

Hardware Components

Nvidia Jetson Orin Nano Training Kit - AI Computer Vision New -10%
x 1 unit(s)