Controling addressable LEDs

Joel Grant

New Member

premelec

Senior Member
Welcome to this forum... if you use the advanced search feature you will find some comments - in my personal experience the 2812s were not useable with PICAXE but the APA102s are driveable ok - it has to do with close timing versus sloppy timing that the APA102s tolerate. Number of units driven gets into power problems I think - I had no trouble up to 60 unit string I tried... speed of changes is slower with PICAXEs fairly low clocking of bit banged SPI with M2 units - perhaps X2 units would work better with dedicated SPI function...
 

hippy

Technical Support
Staff member
My understanding of the situation is -

APA102 - Easily controlled directly from a PICAXE.

WS2801 - Directly controllable by a fast enough PICAXE with appropriate code.

WS2811 / WS2812 / WS2812B / APA104 - Not controllable by PICAXE.

So the item the OP asks about, based on WS2812B, is not suitable for use with a PICAXE.
 

Joel Grant

New Member
My understanding of the situation is -

APA102 - Easily controlled directly from a PICAXE.

WS2801 - Directly controllable by a fast enough PICAXE with appropriate code.

WS2811 / WS2812 / WS2812B / APA104 - Not controllable by PICAXE.

So the item the OP asks about, based on WS2812B, is not suitable for use with a PICAXE.
Thanks Guys for explaining that, saved me from a buying something useless.
This brings up 3 more questions though:
So is there any disadvantage with the APA102 compared to the others?
Is there any other limitations ie functions or number of LEDs?
And is there other options in regard to the APA102 that I should know in its selection ie. types

thanks
Joel
 

inglewoodpete

Senior Member
This brings up 3 more questions though:
So is there any disadvantage with the APA102 compared to the others?
Is there any other limitations ie functions or number of LEDs?
And is there other options in regard to the APA102 that I should know in its selection ie. types
I have successfully used a 28X2 running at 64MHz with hSPIOut to drive a string of APA102s.

If you want to drive a large number of APA102s with fast and complicated transitions of colour, then perhaps the PICAXE is not the microcontroller of choice.
 

Joel Grant

New Member
I have successfully used a 28X2 running at 64MHz with hSPIOut to drive a string of APA102s.

If you want to drive a large number of APA102s with fast and complicated transitions of colour, then perhaps the PICAXE is not the microcontroller of choice.
Ok so lets say I want to run 1 or up to 2 meters of a set of 144 LED p/m APA102's for a colour changing LED chaser would a picaxe work for that? What would the limit be?
Joel
 

hippy

Technical Support
Staff member
A suitable PICAXE should easily control a 144 or 288 LED APA102 string. Technically it could control an infinite length but the limitations are responsiveness ( how quickly any LED can be updated ) and how much memory is available to store RGB LED levels if those must be remembered.

In practical terms the limit would probably be a PICAXE-28X2 which has a 1024 byte scratchpad which would allow 24-bit colour control of 341 RGB LED's and supports hardware SPI.

If the LED's were simply being used as a chaser, say just one or a few LED's being moved back and forth along a rope, the limits are greater because the data is only a few bytes, how many LED's to skip to the one which is lit and what its colour would be.
 

RonnS

Member
hi,

there are some examples from user Technical Link
based on it i make this STAR - have fun...:cool:

if sombody intrestin in this i will post the code an some more details

Ron
 

BESQUEUT

Senior Member
In practical terms the limit would probably be a PICAXE-28X2 which has a 1024 byte scratchpad which would allow 24-bit colour control of 341 RGB LED's and supports hardware SPI.
You can also use few of them on différents APA102 segments. But in that case, you also have to synchronize them.
 

Bill.b

Senior Member
This is part of my Christmas light display using 1m 60 APA102 LED strip and a picaxe 28X2.

Code:
#picaxe 28x2
#no_table
#no_data
setfreq em32
; drop LED Strip light control
;  .--------------------------> Prox Switch
;  |       28X2                 5V -.-   Light strip
;  |  .-----__-----.                |
;  |  | RST    B.7 |                `--> RED +V
;  '--= A0         =  .--> SCK --------> BLU CK
;     | C.2    C.5 |--|--> SDO --------> GRN DI
;  .--| C.3    C.4 |  |             .--> YEL 0V
;  |  |            |  |         0V _|_
;  |  `------------'  |
;  `------------------'

; Set how many LED modules in the strip
Symbol HOW_MANY_LEDS = 60
`
Symbol HOW_MANY_LEDS_MINUS_1 = HOW_MANY_LEDS - 1
Symbol HOW_MANY_LEDS_TIMES_3 = HOW_MANY_LEDS * 3

; Set the maximum brightness of the LED while testing
; Use small values to keep current consumption low
Symbol MAX_BRIGHTNESS = 31 ; 0 to 255 (full)

; Initialise the HSPI interface
#macro init()
  hspisetup spimode00, spifast
#endmacro

; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
  hspiout( n1, n2, n3, n4 )
#endmacro

; Send the start of data header
#macro head()
  sendPacket( $00, $00, $00, $00 )
#endmacro

; Send a LED controlling command
#macro send( red, green, blue)
  sendPacket( $FF, blue, green, red )
#endmacro

; Send the end of data tail
#macro tail()
  sendPacket( $FF, $FF, $FF, $FF )
#endmacro

PowerOnReset:

  ; Initialise the HSPI interface
  init

  ; Turn all LED modules off
  head
  for w0 = 1 To HOW_MANY_LEDS
    send( $00, $00, $00 ) ; 1 to last = Off
  next
  tail

BounceLed:
  ; Set one LED at a time
  ; 'w0' indicates which LED to set
  do
  do
    for w0 = HOW_MANY_LEDS_MINUS_1 to 2 step -1
      Gosub SetLeds
	'Gosub SetLeds2
	if pina.0 = 0 then
	b15 = 1
	endif
	next
    loop until b15 = 1
  '  for w0 = HOW_MANY_LEDS_MINUS_1 to 2 step -1
   '   Gosub SetLeds
   ' next
 b15 = 0
gosub TurnAllLedsOn
pause 3000
for b30 = 1 to 2
   for w0 = 1 to HOW_MANY_LEDS
    Gosub SetLeds2
   next
next b30
gosub VaryLeds
loop
SetLeds:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
     ' for b20 = 0 to 4
		b10 = 0
		b11 = 50
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 50
		b11 = 0
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 0
		b11 = 0
		b12 = 50
	send( b10, b11, b12 ) ; varying colour
	'next b20
    else
      send( $1, $00, $1 ) ; off
    end if
pause 4
  next

  tail
  ; Update the colour
  b10 = b10 + 1 // MAX_BRIGHTNESS; Red
  b11 = b11 + 3 // MAX_BRIGHTNESS; Green
  b12 = b12 + 5 // MAX_BRIGHTNESS; Blue

  return
  
  TurnAllLedsOn:
  ; Turn all LED modules on
 ' do
    head
    for w0 = 1 to HOW_MANY_LEDS 
      send(  MAX_BRIGHTNESS, $00,        $00        ) ; red
      send( $00,         MAX_BRIGHTNESS, $00        ) ; green
      send( $00,        $00,        MAX_BRIGHTNESS ) ; blue
      send(  MAX_BRIGHTNESS,  MAX_BRIGHTNESS, $00        ) ; red + green
      send( MAX_BRIGHTNESS, $00,         MAX_BRIGHTNESS ) ; red + blue
      send( $00,         MAX_BRIGHTNESS,  MAX_BRIGHTNESS ) ; green + blue
      send(  MAX_BRIGHTNESS,  MAX_BRIGHTNESS,  MAX_BRIGHTNESS ) ; white
    next
    tail
    pause 3500
 ' loop
return
SetLeds2:
  ; Set a specific LED and keep the others off
  head
  for w1 = 1 to HOW_MANY_LEDS
    ; Light only the lED we want lit
    if w1 = w0 then
     ' for b20 = 0 to 4
		b10 = 50
		b11 = 50
		b12 = 0
	send( b10, b11, b12 ) ; varying colour
		b10 = 50
		b11 = 0
		b12 = 30
	send( b10, b11, b12 ) ; varying colour
		b10 = 0
		b11 = 50
		b12 = 50
	send( b10, b11, b12 ) ; varying colour
	'next b20
    else
      send( $00, $01, $00 ) ; off
    end if

  next

  tail
  ; Update the colour
  b10 = b10 + 1 // MAX_BRIGHTNESS; Red
  b11 = b11 + 3 // MAX_BRIGHTNESS; Green
  b12 = b12 + 5 // MAX_BRIGHTNESS; Blue

  return
  
VaryLeds:
 for b30 = 1 to 250
    ; Randomly update some LED values
    	for w0 = 1 to 5
      	random w1
      	ptr = w1 / 5 // HOW_MANY_LEDS_TIMES_3		'Set array size and set data - Number of LEDs * 3
      	@ptr = @ptr + 10 & 10					'Set Brightness of LED
    	next
    	; Output the LED data
    	ptr = 0								'Set pointer to first location of data
    	head									'Send start data to LEDs - ($00, $00, $00, $00)
    	for w0 = 1 to HOW_MANY_LEDS
    	  	send( @ptrinc, @ptrinc, @ptrinc )			'Send 3 bytes of data to each leds (Blue, Green, Red) 
    	next   
	tail									'Send End data to LEDs - ($FF, $FF, $FF, $FF)		
  next b30
return
apa102test.jpg


Bill
 

dMajo

New Member
This is not PICAXE, but it is also very easy to program. Have a look ... [redacted]

@dMajo : While we do not generally mind posts which indicate other products are available which can do what a PICAXE can do, and sometime cannot do, when appropriate; if we let the forum become an advertising or promotion platform for one particular product, we really have to let it become the same for all, and this forum is primarily for PICAXE and related product.
 
Last edited by a moderator:

RonnS

Member
@RonnS I would be interested in seeing your star code... if you care to post it... nice display!
see attachment premelec, but i would make a new thread to talk about it to make it better

just in time i work on to dimming a colour from lovest level to highest level and return
 

Attachments

Last edited:
Top