Digital I/O

The first step with any new hardware is the 'hello world' of electronics - blinking an LED. This is very easy with CircuitPython and Jetson Nano. We'll extend the example to also show how to wire up a button/switch.

Jetson Nano boards don't have any way to set the pullup/pulldown resistors, so you'll need to use external resistors instead of built-in pullups, whenever it makes sense!
Note that this graphic matches the 2x20 Raspberry Pi pinout but it's upside-down

Parts Used

Any old LED will work just fine as long as it's not an IR LED (you can't see those) and a 220 to 2.2K resistor

Diffused Blue 10mm LED (25 pack)

PRODUCT ID: 847
Need some big indicators? We are big fans of these huge diffused blue LEDs. They are really bright so they can be seen in daytime, and from any angle. They go easily into a breadboard...
$9.95
IN STOCK

Through-Hole Resistors - 220 ohm 5% 1/4W - Pack of 25

PRODUCT ID: 2780
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
IN STOCK

Some tactile buttons or switches along with some pull-up resistors:

Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack

PRODUCT ID: 1119
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but
$2.50
IN STOCK

Through-Hole Resistors - 1.0K ohm 5% 1/4W - Pack of 25

PRODUCT ID: 4294
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
IN STOCK

We recommend using a breadboard and some male-male wires.

Premium Male/Male Jumper Wires - 40 x 6" (150mm)

PRODUCT ID: 758
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of...
$3.95
IN STOCK

Half-size breadboard

PRODUCT ID: 64
This is a cute half size breadboard, good for small projects. It's 2.2" x 3.4" (5.5 cm x 8.5 cm) with a standard double-strip in the middle and two power rails on both...
$5.00
IN STOCK

Wiring

  • Connect the Jetson Nano Ground pin to the blue ground rail on the breadboard.
  • Connect one side of the tactile switch to Jetson Nano D4 (#7)
  • Connect a ~1K-10K pull up resistor from D4 to 3.3V
  • Connect the other side of the tactile switch to the ground rail
  • Connect the longer/positive pin of the LED to Jetson Nano D18 (#12)
  • Connect the shorter/negative pin of the LED to a 220 ohm-2.2K resistor, the other side of the resistor goes to ground rail

There's no Jetson Nano Fritzing object, so we sub'd a Raspberry Pi in

Double-check you have the right wires connected to the right location, it can be tough to keep track of GPIO pins as there are forty of them!

No additional libraries are needed so we can go straight on to the example code

However, we recommend running a pip3 update!

sudo pip3 install --upgrade adafruit_blinka

Blinky Time!

The finish line is right up ahead, let's start with an example that blinks the LED on and off once a second (half a second on, half a second off):

Download: file
    import time
import board
import digitalio

print("hello blinky!")

led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
  

Verify the LED is blinking. If not, check that the resistor is installed correctly, and you have Ground and +3.3v wires to the Jetson Nano. Also, check that the wires are going to the correct GPIO pins. If you are powering the board with an AC adapter, try powering it through the USB port.

Type Control-C to quit

Button It Up

Now that you have the LED working, let's add code so the LED turns on whenever the button is pressed:

Download: file
import time
import board
import digitalio

print("press the button!")

led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.D4)
button.direction = digitalio.Direction.INPUT
# use an external pullup since we don't have internal PU's
#button.pull = digitalio.Pull.UP

while True:
    led.value = not button.value # light when button is pressed!

Press the button - see that the LED lights up!

Type Control-C to quit

This guide was first published on Sep 10, 2019. It was last updated on 2019-09-10 23:16:10 -0400. This page (Digital I/O) was last updated on Sep 16, 2019.