1
\$\begingroup\$

I am using an ATmega328p to control this RGB LED module. The ATmega is on an Arduino Uno, but I am programming it in C, without using the Arduino libraries.

To power the RGB module I am also using a 12V power supply. To power the Arudino Uno I am using the USB power. I connected it the following way:

  • RGB LED Module 12V -> 12V power supply 12V
  • RGB LED Module GND -> 12V power supply GND
  • RGB LED Module SDI -> ATmega PORTB0
  • RGB LED Module SCK -> ATmega PORTB1
  • RGB LED Module GND -> ATmega GND

Now if I send some data R=0xFF, G=0xFF, B=0xFF (Set SDI to 5V and make every second 24 SCK pulses) according to the datasheet nothing happens. The lights stay off. But randomly I found out, that if I disconnect the 12V power supply and connected it again randomly, sometimes the Lights turning on in a random color. So I don't have any clue whats going on.

What can cause this behavior, what can I do to find the error?

enter image description here

    #include <avr/io.h>


// 16ms delay.
static void delShort()
{
    TCCR0B = 0;
    TCCR0A = 0;
    TIMSK0 = 0;
    TCNT0 = 0;
    GTCCR = 0;

    TIFR0 = TIFR0 | (1 << TOV0);
    TCCR0B = (1 << CS02) | (1 << CS00);

    while(!(TIFR0 & (1 << TOV0)))
    {

    }

    TCCR0B = 0;
}

// 1000ms delay.
static void delLong()
{
    for(unsigned char lI = 0; lI < 61; ++lI)
    {
        delShort();
    }
}

static void ledSetup()
{
    PORTB &= ~(1 << PORTB0);
    DDRB |= (1 << DDB0);

    PORTB &= ~(1 << PORTB1);
    DDRB |= (1 << DDB1);
}

static void ledWrite(uint32_t pData)
{
    uint32_t lValue = pData;

    for(uint8_t lIndex = 0; lIndex < 24; ++lIndex)
    {
        if(lValue & 0x1)
        {
            PORTB |= (1 << PORTB0);
        }
        else
        {
            PORTB &= ~(1 << PORTB0);
        }

        delShort();

        PORTB |= (1 << PORTB1);

        delShort();

        PORTB &= ~(1 << PORTB1);

        delShort();

        lValue = lValue >> 1;
    }
}


void main(void)
{
    ledSetup();

    delLong();

    while (1) 
    {
        delLong();
        ledWrite(0xFFFFFFFF);
    }
}
\$\endgroup\$
  • \$\begingroup\$ Schematic and the code are needed. \$\endgroup\$ – Eugene Sh. Jun 28 '17 at 17:01
  • \$\begingroup\$ @Eugene Sh. I added the code and schematic. \$\endgroup\$ – Michael Jun 28 '17 at 17:51
  • \$\begingroup\$ @Michael Oh, wow! It's been some years since I was drawing ASCII schematics!! Cool. (I actually wrote a program to accept LTSpice schematics and then generate quite readable ASCII from that.) Just so you know, there is a schematic editor available here for you and you can construct arbitrary "black boxes" with arbitrary pin names, if you want to. It's not so bad. \$\endgroup\$ – jonk Jun 28 '17 at 18:42
  • \$\begingroup\$ As you are developing for an ATmega in C without using the Arduino libraries or approach, I've edited your question to emphasize that, and de-emphasize the nearly irrelevant fact that your board happens to say "Arduino" on it. \$\endgroup\$ – Chris Stratton Jun 28 '17 at 20:11
  • \$\begingroup\$ You should verify that your timing functions work for sure as a first step. \$\endgroup\$ – HaLailah HaZeh Jul 11 '17 at 3:20
0
\$\begingroup\$

Have you tried an example first? Just to eliminate the possibility of a wiring problem.

I suggest trying this library: Adafruit-WS2801-Library

WS2801 Library

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to stackexchange. FYI: Answers that are purely links are frowned upon, as links often go dead or the content changes. \$\endgroup\$ – Bort Jun 28 '17 at 20:30
  • \$\begingroup\$ I tried the example using the library but it's not working. So I think it's a hardware problem. \$\endgroup\$ – Michael Jun 28 '17 at 21:50
  • \$\begingroup\$ You're right Bort, I added the library name in case the link goes down. \$\endgroup\$ – François Killeen Jun 29 '17 at 17:28
  • 3
    \$\begingroup\$ This might be more a comment-class suggestion than an answer. But regardless, the fact that it doesn't work suggests that the hardware issues preventing the presumed-good library from working should be addressed before worrying about why the custom code does not work. \$\endgroup\$ – Chris Stratton Jun 29 '17 at 18:58

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.