Skip to content

Initialization

Blaž Rolih edited this page Jun 26, 2023 · 2 revisions

Uploading library to Pi Pico

In order to use this library, first save the neopixel.py file on your Pi Pico.

This can be done in Thonny by opening neopixel.py then click File and Save as.

image

After this a pop-up window will open. Here you select Raspberry Pi Pico.

image

In next window, make sure you name the file as neopixel.py then click OK.

image

At this point the library should be successfully uploaded to your Pi Pico device.

Mind that if you save the library inside folder named /lib, it won't work due to clash with official micropython Neopixel implementation. That is why I recommend uploading in exactly the same way as above, or using other directory than lib.

Using the library

To start using the library, you first need to import it with following line of code:

from neopixel import Neopixel

This imports the class from library that is used to control the led-strip. But to use it, you need to instantiate the object of class with following line of code:

pixels = Neopixel(10, 0, 0, "RGBW")

This makes a class for 10 leds on state machine 0 and pin 0 with RGBW mode.

The class constructor accepts 5 arguments, out of which 3 are mandatory. Following are arguments and their meaning in same order as the class accepts them:

  • num_leds: number of leds on your led-strip
  • state_machine: id of PIO state machine used
  • pin: pin on which data line to led-strip is connected
  • mode: [default: "RGB"] mode and order of bits representing the color value. This can be any order of RGB or RGBW (neopixels are usually GRB)
  • delay: [default: 0.0001] delay used for latching of leds when sending data

Check documentation for description of library functions.