onboard_neopixel
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| onboard_neopixel [2026/07/19 13:06] – walkeradmin | onboard_neopixel [2026/07/21 08:51] (current) – walkeradmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== OnBoard NeoPixel ====== | ====== OnBoard NeoPixel ====== | ||
| - | <color #db5f0b>Jun 2026</ | + | <color #db5f0b>Jul 2026</ |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 6: | Line 6: | ||
| ---- | ---- | ||
| ===== Introduction ===== | ===== Introduction ===== | ||
| + | \\ | ||
| + | * Not for Raspberry Pi Pico. | ||
| \\ | \\ | ||
| The RP2040-Zero mini has an onboard NeoPixel. So we cannot use the Raspberry Pi Pico code to use this LED. Instead we need to use some Micro Python specific to the Waveshare (or compatible) device. | The RP2040-Zero mini has an onboard NeoPixel. So we cannot use the Raspberry Pi Pico code to use this LED. Instead we need to use some Micro Python specific to the Waveshare (or compatible) device. | ||
| Line 33: | Line 35: | ||
| while True: | while True: | ||
| - | np[0] = (8, 0, 8) | + | np[0] = (255, 0, 0) |
| np.write() | np.write() | ||
| time.sleep(0.5) | time.sleep(0.5) | ||
| Line 42: | Line 44: | ||
| </ | </ | ||
| + | First we import three libraries - Pin, neopixel and time. | ||
| + | \\ | ||
| + | \\ | ||
| + | We set the LED Pin to be 16 (this is the GPIO Pin that the NeoPixel uses). | ||
| + | \\ | ||
| + | \\ | ||
| + | Next we create a NeoPixel (WS2812/ | ||
| + | * Which pin the NeoPixel data line is connected to (16). | ||
| + | * How many LEDs are in the strip (in this case, just 1). | ||
| + | \\ | ||
| + | We start a loop | ||
| + | * Set NeoPixel value - np[0] = (255, 0, 0) (this is red) | ||
| + | * Write the value - np.write() | ||
| + | * Wait half a second - time.sleep(0.5) | ||
| + | We then write zeros to the NeoPixel (turn it off) and wait half a second and repeat. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| + | ==== NeoPixel Values ==== | ||
| + | The NeoPixel works on RGB values (0,0,0) so Red, Green, Blue. If you put a value in Red, you get red. The value can be from 0-255, 0 being off, 255 being max brightness. The options for the colours are listed below. | ||
| + | \\ | ||
| + | #other colours | ||
| + | #(255, 0, 0), # Red | ||
| + | #(0, 255, 0), # Green | ||
| + | #(0, 0, 255), # Blue | ||
| + | #(255, 255, 0), # Yellow | ||
| + | #(255, 0, 255), # Magenta | ||
| + | #(0, 255, 255), # Cyan | ||
| + | #(255, 255, 255),# White | ||
| + | #(0, 0, 0) # Off | ||
| + | So 255, 0, 0 will give a bright Red. 8, 0, 0 will give a dull Red. You don't have to use values of 255 all the time, you can use lower values to lower the LED brightness. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| ==== NeoPixel Blink Code with Comments ==== | ==== NeoPixel Blink Code with Comments ==== | ||
| + | Below we can see the same code, but with lots and lots of comments to really help you understand how this Micro Python code works with the onboard Neo Pixel. | ||
| + | \\ | ||
| < | < | ||
| # Import the Pin class from the machine module. | # Import the Pin class from the machine module. | ||
| Line 72: | Line 109: | ||
| # | # | ||
| # Pin(LED_PIN) tells MicroPython which GPIO pin is connected | # Pin(LED_PIN) tells MicroPython which GPIO pin is connected | ||
| - | # to the LED. | + | # to the LED. The GPIO pin number is set by previous variable LED_PIN=16 |
| # | # | ||
| # The second parameter (1) tells it there is only ONE RGB LED | # The second parameter (1) tells it there is only ONE RGB LED | ||
| Line 97: | Line 134: | ||
| # Green = 0 | # Green = 0 | ||
| # Blue = 0 | # Blue = 0 | ||
| - | np[0] = (8, 0, 8) | + | np[0] = (8, 0, 8) # I changed the colour from bright Red to a soft Purple. |
| # Send the colour data to the LED. | # Send the colour data to the LED. | ||
onboard_neopixel.1784466399.txt.gz · Last modified: by walkeradmin
