Need to drive 4 rgb leds, but have only 1 pin available...


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Need to drive 4 rgb leds, but have only 1 pin available...

    Hello.

    The situation is as follows:

    PIC16F877A, running @ 8mhz intosc.

    Have 1 free pin available (can alocate any, including one with PWM output).

    Need to drive 4 rgb leds. All 4 should change colors together, so it can be considered as a single led. There is no animation, color effects or whatever - this is backlight and it will be tuned to specific value once configured and that's all.

    I'd like to do it with as few extra components as possible, due to lack of available space.

    I have the following ideas:

    1. Add another MCU in 8 pin case, say, 12F683, connect it to main chip via serial and use it to drive leds via bitbam or whatever.
    2. Use WS2812 LEDs, and to solve timing issues, wire them in parallels, instead of serial?
    3. As a last resort - use only two colors of leds, say red and blue, and use inverted HPWM to drive them.

    Of course, I'd like to do #2 - requires less extra hardware than others, but is this doable on 16F887?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    PIC16F877A has internal osc?

    On 20MHz, with WS2812 LED try this: http://www.picbasic.co.uk/forum/showthread.php?t=23399

    Should be work.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    Sorry I should write 887A.

    Yes I have read that, but I don't have 20Mhz capability, so this is why I'm asking.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    OK, I try to decreasing the clock frequency, and the minimum clock is 16MHz and the WS2812 works fine.
    In my case at 8MHz the WS2812 not work.

    Pulse generator code for 16MHz looks like this:
    Code:
    ;------------ Pulse generator ---------------
    NeoBit:
        IF DataBit = 1 THEN
            ;generate 800ns pulse 
            NeoPin = 1
            ASM
                nop
            ENDASM
            NeoPin = 0
        ELSE
            ;generate 400ns pulse 
            NeoPin = 1
            ASM
            ENDASM
            NeoPin = 0
        ENDIF
    RETURN

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,793


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    With the APA101 clock frequency is not an issue. We did some experiments in this thread:

    http://www.picbasic.co.uk/forum/show...ghlight=apa101

    Ioannis

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    Yes, but APA needs two legs. Data and clock,. Or I'm wrong?
    Last edited by louislouis; - 30th January 2020 at 14:16.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,793


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    Yes, you are right. Forgot that, sorry!

    Ioannis

  8. #8
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    If you are trying to get a specific color from your RGB, and you aren't needing to change that color, use different value resistors from VREF to your individual LED legs and use the PIC to provide ground. For brightness control, you could use that one PWM pin on your PIC and vary duty cycle. You wouldn't be able to change the colors, due to the fixed resistors.

  9. #9
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    Quote Originally Posted by louislouis View Post
    Yes, but APA needs two legs. Data and clock,. Or I'm wrong?
    Not necessary, you can create clock and data using only one pin.
    eg
    https://www.romanblack.com/shift1.htm

  10. #10
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    This is customizable backlight, so user will be setting the color. Idea with shift register is nice, but if I have to add an extra IC, I can add say 12F683 and use it directly to drive RGB leds. Footprint will be much smaller

  11. #11
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    You missed the point...
    Use same RC circuit to drive APA LED. Apa have Data and Clock pin and you have one pin free.

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: Need to drive 4 rgb leds, but have only 1 pin available...

    Out of the box. A small PIC device running the 4 LEDs and reading a 2 bit serial pattern with a longish pause to sync.
    George

Similar Threads

  1. Re: RGB Fading Using 3 LEDs and PWM
    By Fernandoangel in forum Off Topic
    Replies: 0
    Last Post: - 8th April 2012, 06:59
  2. Oh Dear. My head is spinning. HPWM RGB LEDs What to choose?
    By jimseng in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th March 2012, 18:03
  3. TV remote controlled RGB LEDs
    By idtat in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd February 2009, 18:15
  4. RGB Fading Using 3 LEDs and PWM
    By Tissy in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 20th February 2007, 16:53
  5. RGB Fading Using 3 LEDs and PWM
    By _abello in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th April 2006, 16:50

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts