You can even use NeoPixels on the Jetson Nano using the CircuitPython NeoPixel_SPI library. Using this library makes it really easy. The only requirement is you need to enable SPI first. If you haven't already done that, be sure to take a look at the Initial Setup page. For more information about the the NeoPixel SPI library itself, check out our CircuitPython NeoPixel Library Using SPI guide.

Parts Used

You want some NeoPixels of course. You can use strips, matrices, or even rings.

We crammed ALL THE NEOPIXELS into this strip! An unbelievable 144 individually-controllable LED pixels on a flexible PCB. It's completely out of control and ready for you to...
For advanced NeoPixel fans, we now have a bendable, Flexible 16x16 NeoPixel LED Matrix! Control all 256 ultra-bright LEDs using a single microcontroller pin, set each...
Round and round and round they go! 16 ultra bright smart LED NeoPixels are arranged in a circle with 1.75" (44.5mm) outer diameter. The rings are 'chainable' - connect the...

If you're using more than a few NeoPixels (and why wouldn't you want to?), then you'll want an external power supply. For more about power requirements see Powering NeoPixels.

This is a beefy switching supply, for when you need a lot of power! It can supply 5V DC up to 10 Amps, running from 110V or 220V power (the plug it comes with is for US/Canada/Japan...
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 4 Amps (4000mA). 110 or 240 input, so it works in any country. The plugs are "US...

And here's a couple more products to make it easier to hook it all up.

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 ten rainbow...
If you need to connect a DC power wall wart to a board that doesn't have a DC jack - this adapter will come in very handy! There is a 2.1mm DC jack on one end, and a screw terminal...

Wiring

There's no Jetson Nano Fritzing object, so we'll show using a Raspberry Pi which has the same pinout
  • Connect +5V on the power supply to the NeoPixel VIN
  • Connect Ground on the power supply to the NeoPixel GND
  • Connect RPI GND to NeoPixel GND
  • Connect RPI MOSI to NeoPixel DIN

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!

Install the required libraries

The CircuitPython NeoPixel_SPI library is very easy to install. Just type:

pip3 install adafruit-circuitpython-neopixel-spi

If you're using a NeoPixel matrix, you may also want to try out the CircuitPython Pixel Framebuf library as well, which works well with the NeoPixel SPI library.

pip3 install adafruit-circuitpython-pixel-framebuf

For more information on using the Pixel Framebuf library, check out our Easy NeoPixel Graphics with the CircuitPython Pixel Framebuf Library guide.

Run that code!

The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.

Check out the examples for your library by visiting the repository for the library and looking in the example folder. In this case, it would be https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI/tree/master/examples

As of this writing there's only one example that runs NeoPixels on SPI:

import time
import board
import neopixel_spi as neopixel

NUM_PIXELS = 12
PIXEL_ORDER = neopixel.GRB
COLORS = (0xFF0000, 0x00FF00, 0x0000FF)
DELAY = 0.1

spi = board.SPI()

pixels = neopixel.NeoPixel_SPI(
    spi, NUM_PIXELS, pixel_order=PIXEL_ORDER, auto_write=False
)

while True:
    for color in COLORS:
        for i in range(NUM_PIXELS):
            pixels[i] = color
            pixels.show()
            time.sleep(DELAY)
            pixels.fill(0)
If you are using more than 128 NeoPixels, you will need to make some changes to your Jetson Nano first.

Save this code to your Jetson Nano by copying and pasting it into a text file, downloading it directly from the Jetson Nano, etc.

You'll want to edit the script and number of NeoPixels that you are actually using and possibly the type if the colors don't look correct.

Then in your command line run:

python3 neopixel_spi_simpletest.py

Each pixel should individually light up Red, then Green, then Blue and loop back to Red and so on.

Using Many NeoPixels

If you need to use a lot of them, like more than 170 RGB NeoPixels (about 128 for RGBW type), it will require you to make some changes on the Jetson Nano first. This is because the SPI buffer is set to 4096 by default and each NeoPixel takes 24 bytes. If we use any more than that, it overflows and behaves oddly.

To increase this, we need to make changes in a couple of different places. Although this was tested on the Jetson Nano, it will likely work on other NVIDIA Jetson boards.

Increase the Jetson Nano's Spidev Buffer Size

The first place we increase it is in the Jetson Nano's spidev.bufsize parameter. This is done in the boot/extlinux/extlinux.conf file. We can check the current size with:

cat /sys/module/spidev/parameters/bufsiz

Let's change that. Start by opening the config file in an editor:

sudo nano /boot/extlinux/extlinux.conf

At the top of the file, you should see a line that looks like DEFAULT [labelname]. If you enabled spi1 using the directions in the Initial Setup, it likely is using JetsonIO which we'll go with for the rest of this section.

Download: file
DEFAULT JetsonIO

Scroll down in the file to a section that starts with LABEL and has a name that matches.

Download: file
LABEL JetsonIO

Just below that, there is a line that starts with APPEND. Go to the end of that line and at the end add

spidev.bufsiz=65536

It should look something like the following:

Download: file
APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0 spidev.bufsiz=65536

Go ahead and save the file, then exit and reboot:

sudo reboot

Once it restarts, type the following command to verify that it is now 65536:

cat /sys/module/spidev/parameters/bufsiz

Change Adafruit PureIO's buffer size

First of all, be sure you're running the latest version of Blinka. This will ensure that you have the latest PureIO as well, which was recently updated for this purpose:

pip3 install --upgrade adafruit-blinka

To change Adafruit PureIO's buffer size, we can simply set the SPI_BUFSIZE environment variable and it will use that. If you just want to use it once, you can type at the command line:

export SPI_BUFSIZE=65536

If you want to have it set the variable every time the Jetson Nano boots, you can add it to your .bashrc file, which is located in your home directory. So fi your username is pi, you would find it in /home/pi/.bashrc. Open it up in an editor:

nano ~/.bashrc

And just add the export line to the bottom of your file and save. Once it is added, you can either reboot or type the following command to immediately reload it:

source ~/.bashrc

That's it, you're ready to rock with lots of NeoPixels now.

This guide was first published on Sep 10, 2019. It was last updated on Sep 10, 2019.

This page (NeoPixels with SPI) was last updated on Nov 23, 2020.