Introduction and problems with plasma2040

Hi All,My name is Nick ,and I’m from Australia. I am a bit of a tinkerer, and sometimes it’s harder than expected.

I recently purchased a plasma2040 and I’ve discovered that the coding is a fair bit different to micropython on a Pi Pico. I have seen the web pages and the code for random blinkies,rainbow and rotary and I have them all working .

My aim is to blend code that is working on a Pico to run smoothly on a plasma or extend plasma code to be more versatile and useful for my purposes. For instance I want to convert the random blinkies code to have many more colours and for them to only change when I push switch B for instance or possibly when I turn the rotary encoder…….random blinkies code

# This super simple example sets up two alternating colours, great for festive lights!

import plasma
from plasma import plasma2040
import time

# Set how many LEDs you have
NUM_LEDS = 1

# Pick two hues from the colour wheel (from 0-360°, try https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/ )
HUE_1 = 0
HUE_2 = 127
HUE_3 = 250
# Set up brightness (between 0 and 1)
BRIGHTNESS = 0.5

# Set up speed (wait time between colour changes, in seconds)
SPEED = 1

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

# Start updating the LED strip
led_strip.start()

while True:
    for i in range(NUM_LEDS):
        # the if statements below use a modulo operation to identify the even and odd numbered LEDs
        if (i % 2) == 0:
            led_strip.set_hsv(i, HUE_1 / 360, 1.0, BRIGHTNESS)
        else:
            led_strip.set_hsv(i, HUE_2 / 360, 1.0, BRIGHTNESS)
#         else:
#             led_strip.set_hsv(i, HUE_3 / 360, 1.0, BRIGHTNESS)    
    time.sleep(SPEED)

    for i in range(NUM_LEDS):
        if (i % 2) == 0:
            led_strip.set_hsv(i, HUE_2 / 360, 1.0, BRIGHTNESS)
        else:
            led_strip.set_hsv(i, HUE_1 / 360, 1.0, BRIGHTNESS)
#         else:
#             led_strip.set_hsv(i, HUE_2 / 360, 1.0, BRIGHTNESS)    
    time.sleep(SPEED)

The code that I will show below works well on a Pico and I have attempted to convert it for plasma use but it ain’t that easy. It is called Rotating code. I made various changes (which are not here) and it just ends up in a mess

from machine import Pin
import neopixel
import time

# NeoPixel configuration
PIXEL_PIN = 28  # Replace with your actual data pin
NUM_PIXELS = 7 # Replace with your number of pixels
np = neopixel.NeoPixel(Pin(PIXEL_PIN), NUM_PIXELS)

# Button configuration
BUTTON_PIN = 12 # Replace with your actual button pin
button = Pin(BUTTON_PIN, Pin.IN, Pin.PULL_UP)

current_mode = 0
num_modes = 7 # Adjust based on your number of animation functions

last_button_state = True # True for unpressed (pull-up)
last_debounce_time = 0
DEBOUNCE_DELAY = 50 # milliseconds

def animation_mode_0():
    # Example: Solid Red
    for i in range(NUM_PIXELS):
        np[i] = (255, 0, 0)
    np.write()

def animation_mode_1():
    # Example: Solid Blue
    for i in range(NUM_PIXELS):
        np[i] = (0, 0, 255)
    np.write()

def animation_mode_2():
    # Example: Rainbow cycle (simplified, needs more logic for smooth animation)
    for i in range(NUM_PIXELS):
        np[i] = (0, 255, 0) # Green for simplicity
    np.write()
    
def animation_mode_3():
    # Example: Rainbow cycle (simplified, needs more logic for smooth animation)
    for i in range(NUM_PIXELS):
        np[i] = (0, 255, 250) # Green for simplicity
    np.write()
    
def animation_mode_4():
    # Example: Rainbow cycle (simplified, needs more logic for smooth animation)
    for i in range(NUM_PIXELS):
        np[i] = (250, 55, 0) # Orange for simplicity
    np.write()
    
def animation_mode_5():
    np.fill((250, 20, 0)) # ORANGE
    np.write() 
    time.sleep(0.2)
    np.fill((0, 0, 0)) # OFF
    np.write() 
    time.sleep(0.4)
    np.fill((0, 200, 0)) # GREEN
    np.write() 
    time.sleep(0.2)
    np.fill((0, 0, 0)) # OFF
    np.write() 
    time.sleep(0.4)
    np.fill((0, 0, 200)) # BLUE
    np.write() 
    time.sleep(0.2)
    np.fill((0, 0, 0)) # OFF
    np.write() 
    time.sleep(0.4)
    # Blinking
    # (Implement blinking logic here)
    pass
    np.write()
    time.sleep(0.2)
    
    # Example: Rainbow cycle (simplified, needs more logic for smooth animation)
    #for i in range(NUM_PIXELS):
        #np[i] = (250, 55, 0) # Orange for simplicity
    #np.write() 
def animation_mode_6():
    # Example: Solid Red
    for i in range(NUM_PIXELS):
        np[i] = (155, 150, 150)
    np.write()   

animations = [animation_mode_0, animation_mode_1, animation_mode_2, animation_mode_3, animation_mode_4,animation_mode_5,animation_mode_6  ]

while True:
    # Button polling and debouncing
    current_button_state = button.value()
    if current_button_state == False and last_button_state == True: # Button pressed
        if (time.ticks_ms() - last_debounce_time) > DEBOUNCE_DELAY:
            current_mode = (current_mode + 1) % num_modes
            last_debounce_time = time.ticks_ms()
    last_button_state = current_button_state

    # Execute current animation mode
    animations[current_mode]()

    # Short delay to prevent busy-waiting too intensely, adjust as needed
    time.sleep_ms(10)

At the moment I am using 1 4watt neopixel led on the plasma as it will be for home made light painting equipment

any assistance greatly appreciated

Cheers

Nick

You don’t need the plasma-stuff to run the plasma2040. It is just a Pico with less pins and some hardware that supports level-shifting for the neopixels.

Just use your code that is working on the Pico and replace the PIXEL_PIN and NUM_PIXELS. For the plasma, use PIXEL_PIN=15.

1 Like

Hi bablokb,

Thanks for getting back to me.I looked up yesterday what pin neopixels are connected to.

It said GPIO15 which is Pin 18 as I read the schematic, which means that switch B is on Pin16 and swA on Pin15 but neither pin is responding to a push and the colour sequence is grb for some strange reason on the plasma

The first pixel in the sequence lights up but its green instead of red

cheers

Nick

Don’t use physical pin numbers, use GPIO numbers.

1 Like

Thankyou ,I will keep playing around