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.

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.

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

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:

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

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.

DEFAULT JetsonIO

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

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:

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 2023-12-05 06:22:42 -0500.

This page (NeoPixels with SPI) was last updated on Dec 04, 2023.

Text editor powered by tinymce.