1. Got a question or need help troubleshooting? Post to the troubleshooting forum or Search the forums!

RGB LED Wiring Diagram and Code

Discussion in 'Mods and Upgrades' started by Marquis Johnson, Sep 21, 2015.

  1. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
    Wiring Diagram II.jpg
    Need to finish up some other stuff, but here's a schematic I made about the lights in this video:
     
    TomerO, Scifideity, MChrisP1 and 4 others like this.
  2. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
    Attached is a completely stock V3 Firmware with this added in on

    Marlin_Main.cpp:
    Code:
    #ifdef TEMP_STAT_LEDS
    static uint32_t stat_update = 0;
    //Virtual Variables
    int Rval = 0;
    int Gval = 0;
    int Bval = 0;
    int LEDmax = 150;
    int temp;
    int target;
    //Static Colors
    void white(){Rval = LEDmax;Gval = LEDmax;Bval = LEDmax;}
    void red(){Rval = LEDmax;Gval = 0;Bval = 0;}
    void green(){Rval = 0;Gval = LEDmax;Bval = 0;}
    void blue(){Rval = 0;Gval = 0;Bval = LEDmax;}
    //Handle Led Stauts
    void handle_status_leds(){
    //Fade Leds On when starting up
    
      if(millis() > stat_update) {
    //Update Status
        stat_update += 50; // Update every 0.05s
        for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
           temp = degHotend(cur_extruder);
           target = degTargetHotend(cur_extruder);
        }
        if(Rval+Gval+Bval == 0){
    //length of delay
          int t = 2;
          for(int r = 0; r<LEDmax; r++){Rval = r;analogWrite(STAT_LED_RED, Rval);delay(t);}
          for(int r = LEDmax; r>0; r--){Rval = r;analogWrite(STAT_LED_RED, Rval);delay(t);}
          for(int g = 0; g<LEDmax; g++){Gval = g;analogWrite(STAT_LED_GREEN, Gval);delay(t);}
          for(int g = LEDmax; g>0; g--){Gval = g;analogWrite(STAT_LED_GREEN, Gval);delay(t);}
          for(int b = 0; b<LEDmax; b++){Bval = b;analogWrite(STAT_LED_BLUE, Bval);delay(t);}
          for(int b = LEDmax; b>0; b--){Bval = b;analogWrite(STAT_LED_BLUE, Bval);delay(t);}
          for(int w = 0; w<LEDmax; w++){Rval = w; Gval = w; Bval = w;analogWrite(STAT_LED_RED, Rval);analogWrite(STAT_LED_GREEN, Gval);analogWrite(STAT_LED_BLUE, Bval);delay(t);}
        }
    //White at Idle
        if(target == 0){white();}
    //Green when Finished
        if(target == 5){green();}
        if((target != 0)&&(target != 5)){
    //White at temp     
          if((target >= temp-TEMP_HYSTERESIS)&&(target <= temp+TEMP_HYSTERESIS)){white();}
    //Blue to Red Depending on Temp
          else{
            if(temp < 40){blue();}
            if(temp > EXTRUDE_MINTEMP){red();}
            if((temp > 40)&&(temp < EXTRUDE_MINTEMP)){ 
              Rval = map(temp,40,EXTRUDE_MINTEMP,0,LEDmax);
              Gval = 0;
              if(Rval == 0){Bval = LEDmax;}
              if(Rval > 0){Bval = LEDmax-Rval;}
              if(Rval == LEDmax){Bval == 0;}
            }
          }
        }
    //Write to LEDs
      analogWrite(STAT_LED_RED, Rval);
      analogWrite(STAT_LED_GREEN, Gval);
      analogWrite(STAT_LED_BLUE, Bval);
      }
    }
    #endif
    and this in pins.h
    Code:
    #ifdef TEMP_STAT_LEDS
        #if MOTHERBOARD == 67
          #define STAT_LED_RED       6
          #define STAT_LED_BLUE     11
        #endif
        #if MOTHERBOARD == 33
        //Transistor RGB configuration
          #define STAT_LED_RED 6
          #define STAT_LED_BLUE 5
          #define STAT_LED_GREEN 4
        #endif
      #endif
     

    Attached Files:

    • RGB.zip
      File size:
      248.7 KB
      Views:
      76
  3. jim3Dbot

    jim3Dbot Active Member

    Joined:
    Jun 1, 2015
    Messages:
    246
    Likes Received:
    124
    Post well done!
     
  4. Joe Pellegrino

    Joe Pellegrino New Member

    Joined:
    Jul 30, 2015
    Messages:
    2
    Likes Received:
    1
    I have followed your schematic and flashed the RGB code to the control board. If I hook up 12v+ and ground I only get bright white. If I hook up 12v+ without the ground I get red on start up and than it goes to a dim white light. Any suggestions would be appreciated.
     
  5. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
    Hmm, that's weird. It should be completely off when starting up, then flash Red, Green, then Blue then hold white. I've never seen that behavior from that code.
     
  6. DevinaBove

    DevinaBove New Member

    Joined:
    Oct 13, 2015
    Messages:
    1
    Likes Received:
    0
    I have gone through your post and the schematic. I am also working on the same kind of project.
    When i flashed your RGB code into my control board i found that if I hook up 12v+ and ground I only get bright white.
    If I hook up 12v+ without the ground I get red on start up and than it goes to a dim white light.
     
  7. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
  8. Joe Pellegrino

    Joe Pellegrino New Member

    Joined:
    Jul 30, 2015
    Messages:
    2
    Likes Received:
    1
    My first attempt was a fail however after your instructible post I wanted to know what went wrong with my first attempt. What I noticed was that I reversed the base and emitter on the NPN transistor, after making the change everything is working the way you intended them to. Thanks for the nice work.
     
    Mike Kelly likes this.
  9. Gordon Freeman

    Joined:
    Jun 4, 2015
    Messages:
    38
    Likes Received:
    0
    hey how much current should the transistors be able to handle
    like 12v 5a or something along those lines...
     
    #9 Gordon Freeman, Mar 28, 2016
    Last edited: Mar 28, 2016
  10. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
    12v at 1a should be plenty, the lights don't take that much current to run. But a 5a tranistor will work as well. I used 2N2222
     
  11. Scifideity

    Scifideity Member

    Joined:
    Mar 24, 2016
    Messages:
    74
    Likes Received:
    18
    In your video you show that you removed the factory LED strips. Did you replace them with small RGB strips or remove them completely to go with just the longer one up top?
     
  12. WheresWaldo

    WheresWaldo Volunteer ( ͠° ͟ʖ ͡°)
    Staff Member

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    @Scifideity the LED strips supplied do not attach to RAMPS pins, but rather direct o the power supply input. That is proabably why he disconnected them.
     
  13. Scifideity

    Scifideity Member

    Joined:
    Mar 24, 2016
    Messages:
    74
    Likes Received:
    18
    Gotcha. Thanks.
     
  14. TomerO

    TomerO Member

    Joined:
    May 2, 2016
    Messages:
    97
    Likes Received:
    48
    I love the idea so I decided to try it.
    I have a Robo3D R1+ with the RC6 marlin firmware.

    The wiring worked well (I didn't go directly with the instructions, I just wired...).
    I had to do an extra step and unscrew my board and solder some male headers since it doesn't have them by default on mine.

    I did encounter some Software problems though.
    The pins.h file is structured differently so it doesn't match whats written anymore for RC6, but its just defines so put them wherever.
    The code provided for Marlin_main.cpp didn't work for me at all, I only got a steady white (startup).
    I checked with a simple algo to go through all colors and it worked, so problem must be with some changed global param that is being used or something like that.

    @Marquis Johnson did you try your code with the RC6 version of marlin?

    I'm going to look into this tomorrow probably and use the exiting code as a reference, I intended to change it anyway.

    Bottom line, thanks @Marquis Johnson for a great idea!
     
    Scifideity likes this.
  15. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    204
    I had that same issue when I had the pins in strictly digital outputs instead of PWM pins. Are the pins you used and defined PWN pins?
    And I'm still using RC3 firmware, where can I get my hands on RC6?
     
  16. TomerO

    TomerO Member

    Joined:
    May 2, 2016
    Messages:
    97
    Likes Received:
    48
    I was able to display the full range of colors using these pins (4,5,6, same as you, different board though) so I doubt its the problem,
    I will look at the code today/when I have time and will update if I understand whats up.

    You can get the RC6 from their repo https://github.com/MarlinFirmware/Marlin,
    Just follow WheresWaldo's great post that is still updating http://community.robo3d.com/index.p...lease-candidate-6-for-r1-r1-plus.5806/page-18 (page 18 has the RC6 files)
     
  17. TomerO

    TomerO Member

    Joined:
    May 2, 2016
    Messages:
    97
    Likes Received:
    48
    Found the problem with the LEDs not flashing.
    The code makes them flash on the board's startup, but since I have a USB cable connect to the board its always up so switching on the power didn't make it flash.
    I looked at the code and couldn't find a way to detect the power-on, will keep looking later
     
  18. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,967
    Likes Received:
    7,344
    The A/C power? Yea, unless you add a relay or an I/O port for it I am not sure that is feasible.
    The Arduino thinks power is power (regardless of which it is using)
     
  19. TomerO

    TomerO Member

    Joined:
    May 2, 2016
    Messages:
    97
    Likes Received:
    48
    Yup, I looked into it and expect for the power supply pin which works only if you added something extra like a relay there isn't any indication.
    I will look around and see maybe I can hack something :)
     
  20. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,967
    Likes Received:
    7,344

Share This Page