In this lesson we show you how to control a simple LED circuit using the GPIO pins on the Jetson Nano. We use pull up resistors to connect a push button to the Jetson Nano GPIO pins. We create a toggle switch where the light turns off when the button is pressed, and then turns it back on when pressed again.
Tag Archives: GPIO
AI on the Jetson Nano LESSON 56: Using the GPIO Pins on the Jetson Nano
In this lesson we show how to interact with the GPIO pins on the NVIDIA Jetson Nano. The GPIO pins on the Jetson Nano have very limited current capability, so you must learn to use a PN2222 BJT transistor in order to control things like LED or other components. In this lesson we show how the Jetson Nano can be used to control a standard LED.
Beaglebone LESSON 8: Read Button State from Python
In this tutorial we will see how to read digital values from the GPIO pins. We will be doing digital reads, which means we will be limited to “HIGH” or “LOW” readings. This is a 3.3 volt system, so we need to make sure that the “HIGH” applied signal is 3.3 volts.
Our pinout from LESSON 1 shows which pins are suitable for digital reads.

It is the green GPIO pins which we can use for digital reads. In this lesson we will demonstrate the digital read technique using a simple two button circuit. In order to complete this lesson, you should go ahead and build this circuit.

Notice we are using Pin 1 on Header P9 as the ground and Pins 11 and 13 on header P9 s the input pins. Also note the pulldown resistors are 1000 Ohm. It is important to use at least this much resistance. If you do not have 1,000 Ohm resistors, using something larger NOT something smaller.
Once you have the circuit set up we are ready to begin programming.
First up, you need to import the GPIO library. If you have the latest version of Debian Wheezy, you should have the library on your system. If you do not have it you will need to update and upgrade your operating system. To load the library, you will use the python command:
1 | import Adafruit_BBIO.GPIO as GPIO |
We now need to configure out pins P9_11 and P9_13 as inputs. We do this with the command:
1 2 | GPIO.setup("P9_11", GPIO.IN) GPIO.setup("P9_13", GPIO.IN) |
Now to read the state of the buttons, we would use the commands:
1 2 | state1=GPIO.input("P9_11") state2=GPIO.input("P9_13") |
state1 will be True if the top button is pushed, and False if it is not being pushed. Similarly, state2 will be True when the button is being pushed, and False when it is not being pushed.
We can bring these concepts together to make the following program. Play around with the program and see what all you can make it do.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import Adafruit_BBIO.GPIO as GPIO from time import sleep topButton="P9_11" bottomButton="P9_13" GPIO.setup(topButton, GPIO.IN) GPIO.setup(bottomButton, GPIO.IN) while(1): if GPIO.input(topButton): print "Top Button Pushed" if GPIO.input(bottomButton): print "Bottom Button Pushed" if GPIO.input(bottomButton) and GPIO.input(topButton): break sleep(.2) GPIO.cleanup() |
Beaglebone Black LESSON 5: Blinking LEDs from GPIO Pins
This lesson shows a simple example of how to blink two LEDs from the GPIO pins on the Beaglebone Black. To get going, you will need to hook up the following circuit. (If you have not ordered your Beaglebone Black, you can get one HERE.)

Note that the Top LED is connected to Pin “P9_12” and the bottom LED is connected to Pin “P9_11”. We are using 330 ohm current limiting resistors.
The video lesson takes you through several examples of how to blink the LED. Watch the video, and do the examples. Then play around on your own and see what you can make the LEDs do.
Beaglebone Black LESSON 4: Digital Write to the GPIO Pins from Python
In this lesson we show you how to do digital writes to the GPIO pins from python. If you do not already have a Beaglebone Black Rev C, you can order one HERE.
In order to do this lesson, we need to go back and review the pinout diagram from LESSON 1.

In Python, we reference pins by first specifying which header we want (P8 or P9) and then which physical Pin. For Example, to specify pin 12 on the left header, we would refer to it as “P9_12”. For digital output, we should use one of the pins above that is shaded green.
To talk to the GPIO pins in Python, we must first import a library. The latest versions of the Beaglebone Black Rev C. are shipping with the library already installed. If you have an earlier version, you need to update to the latest operating system. You can visit the beagleboard.org web site to download the latest operating system. If you get an error when you try and load the library, you know that either you have typed the command in wrong, or you need to update your operating system. In python to import the library you need to include the line:
1 | import Adafruit_BBIO.GPIO as GPIO |
Once you have imported the library, you then need to setup your pin as an output pin:
1 | GPIO.setup("P9_12", GPIO.OUT) |
Now if you want to set that pin high you can use the command:
1 | GPIO.output("P8_10", GPIO.HIGH) |
To set the pin low you can use the command:
1 | GPIO.output("P8_10", GPIO.LOW) |
After you are done working with the pin, you should “cleanup” to free the pin up:
1 | GPIO.cleanup() |
These are all the commands you need in order to set the pin “HIGH” or “LOW”. Remember that in the High state, the Beaglebone Black outputs 3.3 Volts.
We can bring things together to make a simple program that will turn the pin on and off in three second intervals. Try and play around yourself with this code. Then try different GPIO pins.
1 2 3 4 5 6 7 8 9 10 | import Adafruit_BBIO.GPIO as GPIO #import GPIO Library outPin="P9_12" #set outPin to "P9_12" GPIO.setup(outPin,GPIO.OUT) #make outPin an Output from time import sleep #so we can use delays for i in range(0,5): #loop 5 times GPIO.output(outPin, GPIO.HIGH) # Set outPin HIGH sleep(3) #Pause GPIO.output(outPin, GPIO.LOW) # Set outPin LOW sleep(3) #Wait GPIO.cleanup() #Release your pins |