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)



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.

  • \$\begingroup\$ Does your definition of F_CPU match reality? \$\endgroup\$ Jul 20 '15 at 13:53
  • \$\begingroup\$ @IgnacioVazquez-Abrams I hope so, I`m 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) \$\endgroup\$
    – Tim
    Jul 20 '15 at 14:04
  • 1
    \$\begingroup\$ ... There is no 12MHz option for the internal oscillator on the ATmega8. \$\endgroup\$ Jul 20 '15 at 14:07
  • \$\begingroup\$ @IgnacioVazquez-Abrams So what frequency can i use ? \$\endgroup\$
    – Tim
    Jul 20 '15 at 14:11
  • 1
    \$\begingroup\$ Okay, i now understood that the F_CPU Paramter won`t change the speed of the internal oscillator. I will try to set the Fusebits and answer my question if that worked. \$\endgroup\$
    – Tim
    Jul 20 '15 at 14:23

Okay, i figured it out!

Just changing the F_CPU Parameter won`t really change the frequency of the internal oscillator. To really change the frequency of the oscillator you have to set the according fusebits. A great tool to find the right fusebits is this Fuse Calculator.

8MHz is the highest frequency the internal oscillator can produce and a suitable value to use the light_ws2812 libray and drive the WS2812B modules.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.