cpldcpu / light_ws2812 Goto Github PK
View Code? Open in Web Editor NEWLight weight library to control WS2811/WS2812 based LEDS and LED Strings for 8-Bit AVR microcontrollers.
License: GNU General Public License v3.0
Light weight library to control WS2811/WS2812 based LEDS and LED Strings for 8-Bit AVR microcontrollers.
License: GNU General Public License v3.0
Hi,
I'm using your project with an 8Mhz ATTiny85 programmed with Arduino.
My project needs to support 100Leds and when compiling your sample fade_RGB everything works fine.
But if I include <SoftwareSerial.h> to the project and instanciate a SoftwareSerial object, then I can't manage to light more than ~70LEDs. If I begin() a communication, this number drops to ~50LEDs.
As I am not an expert on programming ATTiny nor on memory management I don't know how to handle this problem... Maybe you encountered a similar problem?
Hi, just wanted to let you know the library is working exactly as expected in a 8 MHz 328p, so you might want to update the Readme.
Hi,
great work on the lib !
i've been trying to use it on my LPC11U37FBD48-401 (Cortex M0 from NXP). I had to modify some syntax for the LPC_GPIO->SET[#port] in order to compile.
I'm no expert but i believe the clock speed is 50Mhz (i tried with 50,48,36,32,24).
When i update my led Array [GRBGRBGRBGRBGRB....] it's all flickering and showing only red, sometimes a small amount of green and never blue. The behaviors are pretty much the same with small differences when i change the clock speed.
Do you know what could be wrong and if i should continue trying to make this lib working with my CPU or if i should search for another one ?
Thanks
Ben
using attiny85, Arduino IDE, the max led count is 24, doesn't work if set above 24
Thanks the huge work. Works well with STM32F0 devices, but not with STM32F3xx, the assembly code is stuck into an infinite loop.
Tried to debug the code with OpenOCD, seems like the chip is blocked at the ilop
end instruction.
Have you an idea about where the problem may come from? Is there such a huge difference between M0 and M3 assembly code instruction and how it works?
Regards
Any chance this library will run on a SAMD11 MCU? (Trying to plan a project).
Is there way to just set all values to 0 and latch the WS2812? Faster than the simple way of filling the memory array with 0, of course.
As far as I can see from the documentation, we should be able to issue a minimal clear command (start writing 0 bit, wait 6 us for the chip to latch).
error:
\WS2812.cpp:38:35: error: 'OFFSET_R' was not declared in this scope
px_value.r = pixels[OFFSET_R(tmp)];
The new product WS2813 seems to be based on WS2811 and WS2812, both supported by this software.
Is there (or will there be) any support for this 4-wire hardware?
I've ordered some strips, but I won't get them until some weeks, so I can't really make any test by now, but I'm already looking for solution (like an Attiny85 + this lib) to interface those strips with a Raspberry Pi.
I tried the RGB_blinky example with my ATMega8 and the first LED is showing green - constantly.
Tried it with multiple LEDs but same result.
I only had to change two small parts:
diff --git a/light_ws2812_AVR/Examples/RGB_blinky.c b/light_ws2812_AVR/Examples/RGB_blinky.c
index 1429d59..44ab9d5 100644
--- a/light_ws2812_AVR/Examples/RGB_blinky.c
+++ b/light_ws2812_AVR/Examples/RGB_blinky.c
@@ -21,8 +21,8 @@ int main(void)
CCP=0xD8; // configuration change protection, write signature
CLKPSR=0; // set cpu clock prescaler =1 (8Mhz) (attiny 4/5/9/10)
#else
- CLKPR=_BV(CLKPCE);
- CLKPR=0; // set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A)
+ //CLKPR=_BV(CLKPCE);
+ //CLKPR=0; // set clock prescaler to 1 (attiny 25/45/85/24/44/84/13/13A)
#endif
diff --git a/light_ws2812_AVR/Makefile b/light_ws2812_AVR/Makefile
index ff0f6e6..e04009d 100644
--- a/light_ws2812_AVR/Makefile
+++ b/light_ws2812_AVR/Makefile
@@ -4,7 +4,7 @@
# Change these parameters for your device
F_CPU = 16000000
-DEVICE = attiny85
+DEVICE = atmega8
# Tools:
CC = avr-gcc
Hi, i tested with an atmega328p @20 MHz (external crystal) and the output timing are bad:
I confirmed that my AVR work at 20 MHz because the _delay_us work well and the serial baud rate work well too.
fuse: L: 0xFF | H: 0xD1 | E: 0x07 ( CKDIV8 is disabled)
#define F_CPU 20000000UL
USB analyser :
0 CODE:
time high: 1.5 µs
time low: 3.25 µs
1 CODE:
time high: 3.25 µs
time low: 1.98 µs
i modified the following line to work perfectly (all example work well) but the timing results are not perfect (the values "1000000" was modified by "100000")
light_ws2812.c
#define w_zerocycles (((F_CPU/1000)*w_zeropulse )/100000)
#define w_onecycles (((F_CPU/1000)*w_onepulse +500000)/100000)
#define w_totalcycles (((F_CPU/1000)*w_totalperiod +500000)/100000)
...
#define w_lowtime ((w1_nops+w_fixedlow)*100000)/(F_CPU/1000)
USB analyser after the modification:
0 CODE:
time high: 0.17 µs
time low: 0.7 µs
1 CODE:
time high: 0.62 µs
time low: 0.54 µs
But why ?
Hi,
Very appreciated for your repo and asm solution.
I'm using STM32F0 and develop in Keil 5, when compiling the .c file, it pops up error.
Refer to this Link, I'm in the same situation, but I'm not familiar to assmbly code so can't transform it.
Could you tell your compiler environment, or any other info about learning this asm code?
Thanks
According to the readme, to set configuration options one should modify e.g. ws2812_config.h and include it before light_ws2812.h. However this does not actually work, the custom options are ignored and the default ones in light_ws2812.h are used. (See also #67.)
As far as I understand it this is because the two files are part of different compilation units and DEFINEs are not shared between them. Before the commit 6f56c5c ws2812_config.h was included in light_ws2812.h, so everything worked.
Is there some way to get the current setup to work or is this a bug?
hi dear
when i compile in keil ide ...show this error
error: #18: expected a ")"
for assembly section
So I can see that by using ws2812_setleds_pin
it's possible to have multiple strips on the one port be usable however from what I can understand of the code it appears as though these would be written
independently for each strip.
EG: 3 strips, on pins 8, 9, 10 on Arduino (PORTB pins 0, 1, 2)
I would then need to call ws2812_setleds_pin
three times, once for each strip with appropriate array.
The question I have (and with a bit of guidance I can probably submit this as a change if it's possible) is whether it's possible to output different sequences to a single port all in one go and maintain the timings?
Presumably this would involve maintaining a buffer of what the current bit is for each of the pins on the port being fed from each of the strip arrays and then writing that mask to the whole port in one go... or something?
Is that possible? Or is that what's happening now and I've missed that in the code?
Cheers
Andrew
Hi @cpldcpu
just tested your code on an STM32F0, works like a charm at 8MHz.
Thank you for the code, I always wanted to write it myself but I am rubbish at assembler programming.
Here is what I added to the header file:
#include` "stm32f0xx.h" // Change this to the include for your MCU
#include "stm32f0xx_gpio.h"
#define ws2812_port_set ((uint32_t*)&GPIOA->BSRR) // Address of the data port register to set the pin
#define ws2812_port_clr ((uint32_t*)&GPIOA->BRR) // Address of the data port register to clear the pin
#define ws2812_mask_set GPIO_Pin_3 // Bitmask to set the data out pin
#define ws2812_mask_clr GPIO_Pin_3 // Bitmask to clear the data out pin
Hi, I have Adapixel neofruit ws2812 and AVR Atmega168. Tried to use Your library, but my stick is just light on red color. Tried every configuration but nothing. Can someone help me? leds is working because I can light 1-8 led, but when I loop lighting 2,4,8 leds then it's starting very good but after loop they are no turning off and still light 8 leds on red color.
Hi there,
Not really an issue but I wanted to share my experience at 4MHz with ATMega328.
I've got 5 boards with ATMega328P with 16Mhz crystal (not resonator). In my code I'm using clock divider to setup sketch running at 4Mhz. Of course compiled with F_CPU=4000000.
I've done simple sketch doing a rainbow on only one WS2812B located on the board (so very close). So, no strip, just one WS2812 LED.
I took a LAB power to 3.3V and powered the board directly
As driving WS2812B at 4MHz is very timing critical I decided to test driving them at 8Mhz and the problem went off on 3 problematic boards. So my conclusion is that the problem can come from 2 points :
I noticed in your blog different timing for WS2812 and WS2812B but I did not found where I can declare the WS1812 LED type to adjust the timing.
By the way, have you experienced this type of problem ? looks very strange to me.
Thank you for your help
Hi!
Just a quick question about the license: is it GPLv2 only, or GPLv2 or later? By default, the GPL's text usually say " either version 2 of the License, or (at your option) any later version", and this is the recommended text to paste into comments, etc. However, the sources only say "License: GPLv2", which could be interpreted both ways.
Reason I'm asking, is because I'd like to use the library in a project that is otherwise GPL3+. If the license is GPL2+, I can, otherwise I'll have to find an alternative, which would be a huge setback.
Thanks in advance!
In light_ws2812_AVR/Examples/Rainbow.c, COLORLENGTH and FADE are defined like this:
#define COLORLENGTH MAXPIX/2
#define FADE 256/COLORLENGTH
but these formulas should be set in brackets, because without doing so, FADE will be transformed to
256/MAXPIX/2
by the preprocessor, instead of
256/(MAXPIX/2)
as probably intended. One effect of the missing brackets is that this example code does not work if MAXPIX is set to 129 or greater, as in that case FADE would currently become zero.
Using this attiny10 board on arduino: https://github.com/kimio-kosaka/bitDuino10-arduinoTPI
The compiled code is too large. Even the "Blinky" sketch in your examples works out to 1884 bytes. Any idea why this is?
Sadly not a single example is building for me. Arduino is saying: 1544 Bytes (150%) used of 1024 and gives me an error (rainbow example). Blinky example is 126%. How can I fix it? Thanks!
Hi,
I really need to have a WS2812 lib for XMEGA, so I tried compiling for XMEGA, several issues:
First the defines for DDR and PORT will not work for Xmegas
You need to specify something like:
#define ws2812_PORTREG PORTB_OUT
#define ws2812_DDRREG PORTB_DIR
But after that it won't even compile:
impossible constraint in 'asm' ...\light_ws2812.c 119
asm operand 2 probably doesn't match constraints ...\light_ws2812.c 119
I think it has something todo with:
Please help!
I'm looking for a solution that will work on the Teensy 3.1. The Teensy uses an MX20DX256 which is ARM based and compiles in the Arduino IDE. It looks like the Arduino support is primary intended for Atmel chips. The ARM support that is being tested right now doesn't compile under the Arduino. The following error is given:
light_ws2812.cpp: In member function 'void WS2812::ws2812_sendarray_mask(uint8_t_, uint16_t, uint8_t, uint8_t_, uint8_t*)':
light_ws2812.cpp:152: error: impossible constraint in 'asm'
As far as I can tell, the port definitions that are set using digitalPinToBitMAsk, etc. are not defined in the Teensy because of different hardware in the ARM chip. I'm basing this on comments here: http://forum.pjrc.com/threads/26225-problem-bit-banging-using-digitalPinToBitMask-et-al
This likely also means the Arduino Due won't work, yet.
Hello,
I've tried a number of neopixel / ws2812 librarys (using MegaCore) in Arduino but can get none of them to work. I've connected the neopixel to pin 5 (which is PE5 as per MegaCore pin allocation)
I've tried this library also and while it compile happily, when I load it to the board nothing happens. I've confirmed the neopixels are ok using a 328p and an adafruit library.
Short of a CRO, is there anything else I should be checking to see if this is operational? It seems the
Kind regards,
alex
Hello guys,
this problem occured due to my little knowledge about compiler and linker stuff and how everything works together I guess, but I'm getting the following error whenever I'm trying to build the Blinky example in platformio:
ccWcx3C7.ltrans0.o:(.text.startup+0x66): undefined reference to
ws2812_setleds(cRGB*, unsigned int)'`
As IDE I'm using platformio and I have absolutely no idea why I get this error. The header files of light_ws2812.h are found obviously, because there'd be a file not found error. I cannot find the reason for that undefined reference error, maybe you can guide me into the right direction.
As I said, I'm not an compiler / linker expert and can't really give you much information about my setup because i don't know how. But the config files of platformio tell me something about atmelavr and as a board I'm using ATTiny13.
Hopefully you can provide me with some information on how to investigate further. Unfortunately this really is all I'm getting right now. Maybe you do know some gcc parameters or something? I'd try to figure out how to set them in platformio
Thanks in advance
Timo
While compiling there are warning and error:
../light_ws2812.c:119:5: warning: asm operand 2 probably doesn't match constraints
../light_ws2812.c:119:5: error: impossible constraint in 'asm'
Atmega128, AVR Studio 4.19, AVR Toolchain 3.3.0.364
The problem is in selected port, for some reason PORTF doesn't work. Any other port is correct. Can anyone explain this?
Could you add support for multiple separate strips?
If I set F_CPU to 8000000UL (8MHz), w1 is calculated as 0 (2-2), w2 as 3 (7-4) and w3 is below zero (10-8-0-3)!
This leads to a veeeeery long low period.
And, even if I set F_CPU to 500000UL (500kHz), I do not get a warning. Code is compiled without error.
Hello everyone.
I just tried to use this library in Atmel studio 7. I set the F_CPU in the properties to 16MHZ(in numbers of course) which is the frequency my atmega 2560 is running at. Now i've imported the two header files and the c file and tried to compile knowing that nothing will light up but this didn't work for me. There are multiple Warnings with the following content: asm operand 2 probably doesn't match constraints and a fitting error message: Impossible constraint in 'asm'. All errors point at this line(the first one):
asm volatile( " ldi %0,8 \n\t" "loop%=: \n\t" " out %2,%3 \n\t" // '1' [01] '0' [01] - re
Am i doing something wrong? Or is it just me being dumb and not knowing how to handle assembler files?
Hi,
I am completely new to C / Arduino and I've been looking for a solution to get my APA102 strip running with either Adalight or AmbiLED. Got a reply from Adafruit saying that they are not working on adding APA102 support themselves. Do you know how to get this to work?
So I gave this a shot:
attiny13at9.name=ATtiny13 @ 9.6MHz (internal 9.6 MHz clock)
attiny13at9.bootloader.low_fuses=0x7a //fuses still need to be set to this value
attiny13at9.bootloader.high_fuses=0xff
attiny13at9.upload.using=arduino:arduinoisp
attiny13at9.upload.maximum_size=1024
attiny13at9.build.mcu=attiny13
attiny13at9.build.f_cpu=1200000
attiny13at9.build.core=core13
But I guess the timings have not been updated for arduino ide yet.
Without knowing the exact workings of the code in the 'ws2812_sendarray_mask'
I would guess this needs attiny bit of love (see what I did there? ;-) )
comparing the light_ws2818 file to the others, there are some differences.
would it be enough to simply change the
?
Or are additional tweaks required to make this work?
I am only interrested in the ws2818b ;-) but I could work in some additional defines to make it a config option for end users if need be.
Is there any easy way to do this?
When I change ws2812_port and ws2812_pin in ws2812_config.h it has no effect on my program. The neopixel still only works on port B pin 2. I'm trying to figure out how to drive two separate strings of pixels from two different pins.
I'm using the ATMega328P, but do not want to use Arduino or the Arduino bootloader.
My includes:
#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "ws2812_config.h"
#include "light_ws2812.h"
#define F_CPU 8000000
am I missing something here?
Hello,
Currently, when using the AVR library with my atmega328p, my green values are inverted. For example, when using the provided blinky example, instead of going red -> green -> blue it goes green -> red -> blue.
I don't think it's a problem with the LEDs themselves because when using the FastLED library the colors come out as intended.
With some helper functions I can manually invert the red and green values again to get the expected colors, but I'd rather not have to do that.
Thoughts?
Hello
This is just a message to tell you that you can add Arduino Nano to your Tested Combinations Arduino tab.
Tested with Arduino Nano 3.0 @16mhz (both genuine and clone)
Working perfectly.
Great job !
Thank you
Using an ATTiny85 and getting the following errors
Building Library
Light_WS2812/light_ws2812.h:69: warning: 'ws2812_setleds_pin' declared inline after being called
Light_WS2812/light_ws2812.h:69: warning: previous declaration of 'ws2812_setleds_pin' was here
Light_WS2812/light_ws2812.h:80: warning: 'ws2812_sendarray_mask' declared inline after being called
Light_WS2812/light_ws2812.h:80: warning: previous declaration of 'ws2812_sendarray_mask' was here
Building Rainbow
Light_WS2812/light_ws2812.h:69: warning: 'ws2812_setleds_pin' declared inline after being called
Light_WS2812/light_ws2812.h:69: warning: previous declaration of 'ws2812_setleds_pin' was here
Light_WS2812/light_ws2812.h:80: warning: 'ws2812_sendarray_mask' declared inline after being called
Light_WS2812/light_ws2812.h:80: warning: previous declaration of 'ws2812_sendarray_mask' was here
text data bss dec hex filename
642 0 114 756 2f4 Objects/Rainbow.o
0 [main] sh.exe" 13048 sync_with_child: child 14796(0x1DC) died before initialization with status code 0xC0000142
131 [main] sh.exe" 13048 sync_with_child: *** child state waiting for longjmp
"D:/Program Files/utils/bin/sh.exe": fork: Resource temporarily unavailable
make: *** [Rainbow] Error 128
Any suggestions?
I have not looked further into your code ... but could this be ported over to operate on the ESP8266 micro controller?
When compiling with a core for SAMD11 by MattairTech (https://github.com/mattairtech/ArduinoCore-samd) I get:
In file included from C:\Users\Perigalacticon\Documents\Arduino\sketches\Function Tests\test_neopixels_841\test_neopixels_841.ino:6:0:
C:\Program Files (x86)\Arduino\libraries\light_ws2812/WS2812.h:28:24: fatal error: util/delay.h: No such file or directory
#include <util/delay.h>
^
This might be an installation issue, but light_ws2812_cortex.h has #include "WS2812.h", which contains commands specific to AVR.
I just wanted to try out the library in combination with an Arduino Uno and some WS 2812 LEDs, but it won't compile correctly.
Here's the error log: http://pastebin.com/0m6tqhb4
The last says: "Error while compiling for the board Arduino/Genuine Uno"
When I upload the Blinky example to my Arduino Uno only the first led does what it should do but the others are blinking in ohter colors.
Sometimes they are also just black.
Here is the code:
`
#include <WS2812.h>
WS2812 LED(64); // 1 LED
cRGB value;
void setup() {
LED.setOutput(7); // Digital Pin 7
}
void loop() {
value.b = 255; value.g = 0; value.r = 0; // RGB Value -> Blue
LED.set_crgb_at(0, value); // Set value at LED found at index 0
LED.sync(); // Sends the value to the LED
delay(500); // Wait 500 ms
value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Blue
LED.set_crgb_at(0, value); // Set value at LED found at index 0
LED.sync(); // Sends the value to the LED
delay(500); // Wait 500 ms
}
`
Thank you so much for your code!
I took the Cortex code from your project and C++ified it. (inspired by your Adruino code)
Connected a 4m strip with 240 LEDs (Luxorparts WS2812B NeoStrip compatible) @4.5V, no level converter.
I control the LEDs through a TCP connection using the DhcpChatServer (found in the Andruino examples).
I don't know if the Ethernet Shield is significant or not, but when I clocked the LEDs with all 0s, 3-4 random LEDs would turn on with random color and intensity. Same when clocking out RGB(1,1,1)
Reading your readme, made me focus on the NVM read cache and NVM wait-states @[email protected].
Turning the cache off had no effect. Never figured out how to run the CPU @24MHz with 0 wait-states.
On a whim, I added __disable_irq(); & __enable_irq(); in ws2812_sendarray() and viola!
Rock steady @48MHz 1-wait-state & cache enabled.
Up to you to decide if this should be incorporated into the code or just make an entry in the ReadMe.
The current comment about max clock and wait-state restriction seem not to apply when disabling interrupts during the bit/banging.
Cheers
Edit: just hit me that interrupts did not need to be disabled during the whole clocking cycle.
josh.com states:
The only tight timing parameter for NeoPixel signaling is the maximum width of a 0-bit pulse
So I tested out the code below and it worked fine. Did not find out how to just do it for a 0, but interrupts are now allowed inside the clocking loop:
asm volatile(
" lsl %[dat],#24 \n\t"
" movs %[ctr],#8 \n\t"
"ilop%=: \n\t"
---> "cpsid i \n\t"
" lsl %[dat], #1 \n\t"
" str %[maskhi], [%[set]] \n\t"
#if (w1&1)
ws2812_DEL1
#endif
#if (w1&2)
ws2812_DEL2
#endif
#if (w1&4)
ws2812_DEL4
#endif
#if (w1&8)
ws2812_DEL8
#endif
#if (w1&16)
ws2812_DEL16
#endif
" bcs one%= \n\t"
" str %[masklo], [%[clr]] \n\t"
"one%=: \n\t"
---> "cpsie i \n\t"
#if (w2&1)
ws2812_DEL1
.
.
(I'm thinking about using the USI/DO to do the bitbang)
How difficult would it be to add a support for Esp8266?
Regards.
How can I use this library with stm8s00?
Im trying to use your library with my ARM STM32F4xx and STM32F1xx Boards but i cant get it to run.
My assembler skills are not so good so i could fix the issue by myself.
I implent it like your samples but it doesnt get out of the sendarray routine. It stucks in this routine and continiously sends data out of the data port.
Im using this defines for the ports (the gpio was initialized correctly)
I set my F_CPU=9600000 but the LED colour display wrong colour. Does this code support this MCU?
I use your library with AtTiny85 (8Mhz internal oscillator).
Simple loop
for (int i = 0; i < 100; i++) {
led[0].r=GREEN[i][0];
led[0].g=GREEN[i][1];
led[0].b=GREEN[i][2];
led[0].w=0;
ws2812_setleds_rgbw(led,1);
_delay_ms(50);
}
GREEN - is a predefined array with RGB values. Only green is non-zero here.
So, I've got very strange artifacts here, sometimes led blinks red, and white. It has to start from black and slowly go green. But it starts at green instead. It's 100% reproducible and probably goes wrong at the same GREEN rows.
At the same time, it works perfectly on the Arduino Uno board.
I think that something is wrong with timings. But I have no idea how to investigate 8(
Could you make it or tell me how? xD ^^
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.