NeoPixel Python LED Control?

66 views Asked by At

I'm using two different modules for the NeoPixel led devices. One is the neopixel module and the other is the adafruit PixelFrame Buffer (https://docs.circuitpython.org/projects/pixel_framebuf/en/latest/index.html)

I'm working on a 8x32 matrix.

I'm trying to make one led setting overlap the other - ie , if the frame buffer module fills the whole matrix blue, then I use the NeoPixel strip setup to overlap per say a pixel or two as red for example.

This is easily done with one module, set all the conditions then strip.show and they will overlap each. Or for example using the frame buffer module you could:


pixel_framebuf.fill(0x000088)
pixel_framebuf.pixel(5, 1, 0xFFFF00)
pixel_framebuf.line(0, 0, pixel_width - 1, pixel_height - 1, 0x00FF00)
pixel_framebuf.display()


Annoyingly, I need to work with both the pixel_framebuf and strip - it seems that when it jumps between each initialisation it wipes the previous setting.

Is there a way around this so that both display modules can work on top of each other?

Example Code:


import neopixel
import time
from rpi_ws281x import *
import argparse
import board
import random
from adafruit_pixel_framebuf import PixelFramebuffer, VERTICAL



# LED MATRIX 1 STRIP configuration:
LED_COUNT      = 256      # Number of LED pixels.
LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA        = 10      # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 1    # Set to 0 for darkest and 255 for brightest
LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53

# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()

firstPixel = 0


# LED MATRIX 1 FRAME configuration:
pixel_pin = board.D18
pixel_width = 32
pixel_height = 8

pixels = neopixel.NeoPixel(
    pixel_pin,
    pixel_width * pixel_height,
    brightness=0.01,
    auto_write=False,
)

pixel_framebuf = PixelFramebuffer(
    pixels, pixel_width, pixel_height, orientation=VERTICAL, rotation=2
)



# Main

if __name__ == '__main__':
  

    
    #DEFAULT STATE 1 
    
    print ('State 1')
    
    
    pixel_framebuf.fill(0x0000FF)
    strip.setPixelColor(10, Color(0, 128, 255));
    
    pixel_framebuf.rect(1, 2, 8, pixel_height - 3, 0xFF00FF)
    pixel_framebuf.display()
    

    strip.show() 

     
    time.sleep(4)   
    
0

There are 0 answers