# WS2812B with ATMega8 and light_ws2812 Libray

I have connected four WS2812B modules I got from eBay to my AtMega8 and tried to use the light_ws2812 libray to controll them.

I connected the wire used for communication to the PC5 Pin on my ATMega and wrote the following programm to controll the four LEDs.

#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "light_ws2812.h"

struct cRGB led[4];

int main(void)
{
led[0].r=255;led[0].g=00;led[0].b=0;
led[1].r=255;led[1].g=00;led[1].b=0;
led[2].r=255;led[2].g=00;led[2].b=0;
led[3].r=255;led[3].g=00;led[3].b=0;
ws2812_setleds(led,4);

while(1)
{

}
}


I followed the given Example of the Libray to write the Code. While trying to figure out the error myself and rewriting my code a little bit, I somehow managed to get the first LED to light up fully green. When I erased the complete flash memory of the ATMega the LED still stayed on.

Because of that I'm pretty sure that my problem is on the software side, but I don't know how to fix it.

• Does your definition of F_CPU match reality? Jul 20 '15 at 13:53
• @IgnacioVazquez-Abrams I hope so, Im using the internal oscillator and wrote at the beginning of my programm "#define F_CPU 12000000". Using Atmel Studio i also added under Project>Properties>Toolchain>AVR/GNU C Compiler>Symbols the Symbol "F_CPU=12000000" like it was pointed out in the Readme for the libray. (i.imgur.com/fnGX4Vs.png)
– Tim
Jul 20 '15 at 14:04
• ... There is no 12MHz option for the internal oscillator on the ATmega8. Jul 20 '15 at 14:07
• @IgnacioVazquez-Abrams So what frequency can i use ?
– Tim
Jul 20 '15 at 14:11
• Okay, i now understood that the F_CPU Paramter wont change the speed of the internal oscillator. I will try to set the Fusebits and answer my question if that worked.
– Tim
Jul 20 '15 at 14:23