Creating Arduino Library for WS2812B LED Strip

preview_player
Показать описание
Link to circuit diagram:

Link to my GitHub repository to access WS2812B library:

Link to my tutorial on programming WS2812B using assembly:

Content:
0:00 Introduction
0:35 Sending Bytes to WS2812B
2:20 Programming WS2812B using C++ and assembly
7:38 Demonstrations
8:18 Creating Library: Header & Source Files
10:31 Library Example Sketch: Displaying Patterns on LED Strip
11:26 Demonstration
11:39 Future Project: Update Library to Include More Functions
Рекомендации по теме
Комментарии
Автор

Nice to see that how bricks are made and brick comes to brick to finish some day the house or city - thank you

dlcy
Автор

Parabéns pelo vídeo explicativo meu amigo

bk_electronics
Автор

Thank you for this Lib. I am going to try to adapt to Attiny85. Question : I understand the assembly however if I understand the code, the "C" code sends bytes to the assembly code and as such could this not expose the timing to how the compiler handles the code in between bytes? If there is a excessive delay between bytes would this cause an error as the Ws2812 is looking for a continuous 24 bit wave train with specific timing requirements. I expect code modified for 8 MHZ would be more susceptible. Once I convert to Attiny85 I will check timing with an oscilloscope. Also what is the code size compared to other library's like neopixel and lite_ws2812? I expect it to be much more compact. Love your tutorials !

janetsypen
Автор

When calling ASM functions from C, would you consider prefixing the function calls with "asm" for example asmColor(0, 0, 255); when calling for an LED to be 100%blu. Also, do you use "keywords.txt" in your project to turn "color" function name orange?

I extended your initial 3 pixels to "n" and found timing became an issue in "high pulse" of "Logic0" and "Logic1"... see where I edited your .S file, showing timing at 0.0625us/cycle. The "high pulse" timing makes a large difference in color:

Logic0: // (0.40us + 0.85us = 1.25us)

;0.40us high pulse (6T)

OUT PORTD, R30 ;set DIN pin HIGH
NOP // 2 timing cycles
NOP // 3 timing cycles
NOP // 4 timing cycles
NOP // 5 timing cycles
NOP // 6 timing cycles * 0.0625 = 0.375

;0.85us low pulse (14T)

OUT PORTD, R31 ;set DIN pin LOW
NOP // 2 timing cycles
NOP // 3 timing cycles
NOP // 4 timing cycles
NOP // 5 timing cycles
NOP // 6 timing cycles
NOP // 7 timing cycles
NOP // 8 timing cycles
NOP // 9 timing cycles
NOP // 10 timing cycles
NOP // 11 timing cycles
NOP // 12 timing cycles
; NOP // 13 timing cycles // for ease of including timing cycles 13 and 14
RET // 13 timing cycles * 0.625 = 0.8125 (+ 0.375 = 1.125)
;----
; RET // 14 timing cycles * 0.0625 = 0.875 (+ 0.375 = 1.25)

Logic1: // (0.80us + 0.45us = 1.25us)

;0.80us high pulse (13T)

OUT PORTD, R30 // 1 timing cycle
NOP // 2 timing cycles
NOP // 3 timing cycles
NOP // 4 timing cycles
NOP // 5 timing cycles
NOP // 6 timing cycles
NOP // 7 timing cycles
NOP // 8 timing cycles
NOP // 9 timing cycles
NOP // 10 timing cycles
NOP // 11 timing cycles
NOP // 12 timing cycles * 0.0625 = 0.75... expected drop in pixel intensity
; NOP // 13 timing cycles * 0.0625 = 0.8125 ... sharp drop in pixel intensity

;0.45us low pulse (7T)

OUT PORTD, R31 // 1 timing cycle
NOP // 2 timing cycles
NOP // 3 timing cycles
NOP // 4 timing cycles
NOP // 5 timing cycles
NOP // 6 timing cycles
;----
RET // 7 timing cycles * 0.0625 = 0.4375 (+ 0.75 = 1.1875)

bob-nykn
Автор

Is is possible to to write this specific assembly code in C?
If it's possible, how can I do that without knowing assembly?

MatanSpada