Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:38 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Playing with the WS2816 in the Waveshare RP2040-Zero

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 02:43am 30 Apr 2023
Copy link to clipboard 
Print this post

So how does one play with just one WS2816 not a string of them?

Quazee137
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 05:52am 30 Apr 2023
Copy link to clipboard 
Print this post

I assume you mean the WS2812, WS2812B or the SK6812.
AFAIK, the WS2816 is not supported unless it is backwards compatible.

I have the 2812B LED on my stock of WS Zero modules.

To get it to light up, I used page 41 of the PicoMite manual, and the example code there to get things working.  On the SW Zero module, the 2812 is on GP16, so:


DIM b%(4)=(RGB(red), Rgb(green), RGB(blue), RGB(Yellow), rgb(cyan))
SETPIN GP16, DOUT
BITBANG WS2812 O, GP16, 5, b%()


...is the equivalent if you have FIVE 2812 LED's daisy chained.

Modify the code:


DIM b%(4)=(RGB(red), RGB(green), RGB(blue), RGB(Yellow), RGB(cyan))
SETPIN GP16, DOUT
FOR X=0 to 5 'Cycle through the five colours
 BITBANG WS2812 O, GP16, 1, b%(X) 'Show a colour
 PAUSE 3000 'Appreciation time...
NEXT X 'Next colour
BITBANG WS2812 O, GP16, 1, RGB(Black)


The last command just turns the LED off, otherwise it will glow forever in the last colour it was commanded to emit.
Edited 2023-04-30 16:16 by Grogster
Smoke makes things work. When the smoke gets out, it stops!
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 07:17am 30 Apr 2023
Copy link to clipboard 
Print this post

WS2816? I don't think you can from MMBasic. I suspect the timing will be different, although you can get round the extra B pin.

https://datasheet.lcsc.com/szlcsc/2012110135_Worldsemi-WS2816B-2121_C965560.pdf

https://datasheet.lcsc.com/szlcsc/2012110135_Worldsemi-WS2816C-2121_C965561.pdf

.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 07:59am 30 Apr 2023
Copy link to clipboard 
Print this post

Thanks Grogster that works.

 I did on mod to your code

 Dim b%(5)=(RGB(red), RGB(green), RGB(blue), RGB(Yellow), RGB(cyan),RGB(Black))

 I didn't know there was a bitbang for it.

 I had looked at python code but it used a lib as did arduino.

 After looking at low level driver code it's so complex to light just 3 leds.  

 Quazee137
 
barewires
Newbie

Joined: 13/04/2015
Location: United Kingdom
Posts: 30
Posted: 09:30am 30 Apr 2023
Copy link to clipboard 
Print this post

# from chatgpt 24022023 Waveshare RP2040-Zero works 1st time RS
# too bright, added black and a pause to stop with LED off

import machine
import neopixel
import time

# Define the number of WS2812 LEDs in the chain and the pin to which they're connected
num_leds = 1
pin = machine.Pin(16)

# Initialize the neopixel object
np = neopixel.NeoPixel(pin, num_leds)

# Define the RGB colors
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
black = (0, 0, 0)

# Loop through the colors and blink the LED once each second
while True:
   np[0] = red
   np.write()
   time.sleep(.105)
   np[0] = green
   np.write()
   time.sleep(.105)
   np[0] = blue
   np.write()
   time.sleep(.105)
   np[0] = black
   np.write()
   time.sleep(5)
 
barewires
Newbie

Joined: 13/04/2015
Location: United Kingdom
Posts: 30
Posted: 09:34am 30 Apr 2023
Copy link to clipboard 
Print this post

# MicroPython v1.19.1 on 2022-06-18; Raspberry Pi Pico with RP2040
# zero_RGB_random_colours.py from chatgpt 24022023 RS
import machine
import neopixel
import urandom
import utime

# set up neopixel LED
NUM_LEDS = 1
np = neopixel.NeoPixel(machine.Pin(16), NUM_LEDS, bpp=3)

#This configures a NeoPixel strip on GPI16 with 8 pixels. You can adjust the “16” (pin number)
#and the “1” (number of pixel) to suit your set up.
#To set the colour of pixels use:
#np[0] = (255, 0, 0) # set to red, full brightness
#np[1] = (0, 128, 0) # set to green, half brightness
#np[2] = (0, 0, 64)  # set to blue, quarter brightness

print("Blank LED Stop now!")
colour = (0,0,0)
np[0] = colour  # set LED colour
np.write()     # update LED
utime.sleep(2)

numbits = 8
print("numbits =", numbits)

# main loop
while True:
   # generate random RGB colour
   #numbits = urandom.getrandbits(4)

   colour1 = urandom.getrandbits(numbits)
   colour2 = urandom.getrandbits(numbits)
   colour3 = urandom.getrandbits(numbits)
   print(colour1, colour2, colour3)
   colour = (colour1, colour2, colour3)
   np[0] = colour  # set LED colour
   np.write()     # update LED

   # wait
   utime.sleep(.125)
Edited 2023-04-30 19:44 by barewires
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 09:55am 30 Apr 2023
Copy link to clipboard 
Print this post

I was originally looking at how to do it without import/libs something
more bare metal bit this shift that ect...

Quazee137
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 10:02am 30 Apr 2023
Copy link to clipboard 
Print this post

As you can't "import" stuff into MMBasic that sounds like a better approach. :)

I had to look up WS2816 - I didn't know such a thing existed. The weather station looked interesting too, but I figured you didn't want a string of those. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 11:59pm 30 Apr 2023
Copy link to clipboard 
Print this post

I'm surprised to some extent, that the 2812 bitbang in MMBASIC could drive the 2816, as that is not officially supported.  I guess perhaps Mick was just lucky.  The 2816 could also be backwards compatible with the 2812 commands, so.....

Glad you got it working, Mick!  
It's very easy to drive them via the MMBASIC bitbang command.
Smoke makes things work. When the smoke gets out, it stops!
 
IanRogers

Senior Member

Joined: 09/12/2022
Location: United Kingdom
Posts: 151
Posted: 09:31am 03 May 2023
Copy link to clipboard 
Print this post

I have been looking at this as well

the PIO code to write to these is on a youtube tutorial.

I also found the Quad encoder.. Using code here on this forum, from Volholt, that you could use as a template.. Then it's kinda a hardware driver!
Edited 2023-05-03 19:36 by IanRogers
I'd give my left arm to be ambidextrous
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024