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

G-Code Controlled Case Lighting

Discussion in 'Mods and Upgrades' started by WheresWaldo, Nov 24, 2017.

  1. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    This is an extension of the work that @Kilrah has already done with his Light... mod. If you haven't looked over that thread, I suggest you do and give @Kilrah a ♥ Like for creating it and the Thingiverse submission of the angled LED strip mounts. It does require additional parts and modification to Marlin in order to get it to work. I will try to outline all the steps and parts needed.

    The posts will be broken up as follows:
    • Hardware will outline the parts required, how it is wired up and where it connects on the Robo Mainboard.
    • Firmware will outline what files need to be changed and how they must change in order to enable G-Code control of the LED strip(s).
    • Usage will give example of how to use the LED strip(s).
     
    #1 WheresWaldo, Nov 24, 2017
    Last edited: Nov 25, 2017
  2. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Hardware

    Parts
    • 24V single color LED strip
      HTB1xy5BRFXXXXc4XXXXq6xXFXXXt[1].jpg
    • PWM controlled power MOSFET
      HTB1dc3TSXXXXXcqaXXXq6xXFXXXK[1].jpg
    • Wire
      HTB18fsLLFXXXXaRXpXXq6xXFXXXJ[1].jpg
    • Dupont connectors and crimps
      HTB1WJv5LXXXXXc7XpXXq6xXFXXX2[1].jpg
    • MSTB 2.5-50.8 power connector
      61ZLOE83LEL._SL1100_[1].jpg
    The use of a 24V LED strip will mean you can directly connect it to the power supplied to the Robo mainboard without adding dropping resistors or a step down converter (also know as a Buck Converter). Using a pulse width modulated (PWM) MOSFET power board lets you drive the board at different duty cycles. Varying the on off duty cycle will allow for setting different brightness levels on the LED strip using different G-Code parameters (discussed in post #4). Obviously you need wire to attach the components tighter. The Dupont connector will allow for easy plug insertion and removal from the Robo Mainboard, you can also use an R/C JR style servo connector.

    If you want to use a 12V or 5V LED strip you will need to add a buck converter as outlined in the Light... thread.
    LM2596S-ADJ-DC-DC-Switching-Step-Down-Module-Power-Supply-Converter-12V-24V-New[1].jpg


    Installation

    Wiring up is pretty straight forward and will consist of two attachments to the Robo Mainboard (4 wires total). The two wires that control the actual light level will go from these two pins on the Robo Mainboard.
    2017-11-26 10.29.57.png
    Ground will connect to the ground connector on the MOSFET board and the PWM Pin will connect to the Signal or PWM pin of the same MOSFET board. This is what allows the MOSFET to vary the power to the LED strips and thus vary the overall brightness. This is where using the Dupont connector will make things easier. Just crimp the ends and shove them into the outside two holes in the Dupont housing. That way you will have a properly spaced set of wires that will simply plug into the Robo Mainboard.

    Verify that you have the PWM wiring plugged into the proper set of pins as we are going to set the pin number used in firmware.

    The next attachment is for the supply voltage of the LED strips. Two wires go from the plug located at the upper right most corner of the Robo Mainboard and then to the Input Power of the MOSFET board.
    20171124_172804.jpg
    Those pins supply 24V on the R2 and 19V on the C2. A suggestion here would be to strip the insulation about 5 mm off the end of each wire. Twist the wires so they do not fray, insert each end into the MSTB connector and tighten before inserting the connector into the Robo Mainboard. Removing the fuses may make this task easier, don't forget to replace the fuses in their proper location.
     
    #2 WheresWaldo, Nov 24, 2017
    Last edited: Jan 5, 2018
  3. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Firmware

    Configuration_adv.h
    Code:
    /**
    * M355 Case Light on-off / brightness
    */
    #define CASE_LIGHT_ENABLE
    #if ENABLED(CASE_LIGHT_ENABLE)
      //#define CASE_LIGHT_PIN 4                  // Override the default pin if needed
      #define INVERT_CASE_LIGHT false             // Set true if Case Light is ON when pin is LOW
      #define CASE_LIGHT_DEFAULT_ON true          // Set default power-up state on
      #define CASE_LIGHT_DEFAULT_BRIGHTNESS 105   // Set default power-up brightness (0-255, requires PWM pin)
      //#define MENU_ITEM_CASE_LIGHT              // Add a Case Light option to the LCD main menu
    #endif
    pins_ROBOMB.h
    Code:
    //
    // Misc. Functions
    //
    #define SDSS              53
    #define LED_PIN           13
    #define CASE_LIGHT_PIN    44  // MUST BE HARDWARE PWM (2, 3, 4, 5, 6, 7, 8, 9, 10, 44, 45)
    I have opened an issue to ask for a Feature Request that will include these two edits to Robo's firmware from the start so the edits are not necessary. https://github.com/Robo3D/Marlin/issues/22
     
    #3 WheresWaldo, Nov 24, 2017
    Last edited: Nov 29, 2017
  4. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Usage

    G-Code

    To use this in your g-code scripts add the following line to your scripts, see notes about parameter limits.

    M355 S1 P105

    S
    is the switch and can be 0 (light off) or 1 (light on)
    P is brightness and is a number between 0 - 255 (0 = no brightness, 255 = full brightness)

    There is no assumption that the LED strip will behave in a linear fashion, so don't assume that 128 is one half brightness. Firmware defaults to lights on and P = 105.

    Web Control

    If you want to control this from the Robo Web interface you can do so by adding a section to /home/pi/.octoprint/config.yaml. The following section needs to be added:
    Code:
    controls:
      - name: Case Lighting
        layout: horizontal
        children:
        - name: Light On
          command: M355 S1 P%(brightness)s
          input:
          - name: Brightness (0 - 255)
            parameter: brightness
            default: 105
            slider:
              min: 0
              max: 255
        - name: Light Off
          command: M355 S1 P0
    
    When editing config.yaml please remember that spacing is critical and you cannot replace spaces for tabs or OctoPrint will not load. Cutting and pasting the above code does work.

    This will give you the following addition to the Control section of the web interface:
    FireShot Capture 2 - robo [OctoPrint] - http___192.168.1.36_.png
    Robo Theme enabled

    FireShot Capture 1 - robo [OctoPrint] - http___192.168.1.36_.png
    Default OctoPrint theme
     
    #4 WheresWaldo, Nov 24, 2017
    Last edited: Dec 8, 2017
  5. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Here is what it looks like completed

    Lights Off
    upload_2017-12-8_20-42-8.png

    Lights on at full brightness (255)
    upload_2017-12-8_20-44-55.png

    You can control the lights directly from sliced G-Code if you add the M355 commands in the slicing scripts or post process your sliced G-Code after the fact.

    If you know a thing or two about G-Code you will notice that We are not actually turning off the case lights with the custom code above. We are actually turning the brightness down to zero. There is a bug in Marlin 1.1.6 and prior versions that does not allow a hardware PWM pin to turn off using M355. That bug has been fixed in the bugfix branch but that branch has been released yet. The next Marlin release will allow you to turn the case lights off with M355 S0.
     
    #5 WheresWaldo, Dec 8, 2017
    Last edited: Dec 8, 2017
    mark tomlinson likes this.
  6. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    #6 WheresWaldo, Dec 25, 2017
    Last edited: Dec 25, 2017
    ytilotia likes this.
  7. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Still unhappy with how much light bleeds into the scene at full brightness I modeled a new version of the LED mounting strip. This on has a slightly longer front valance and mounts the LED strip with more angle pointed downward (67.5°). Model was added to the Thingiverse posting listed above. The 3D model can be downloaded from this link:

    http://a360.co/2D43NFP - Downloadable 3D model, can be exported in various formats​
     
    supercazzola likes this.
  8. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111
    Waldo,
    Which temperature of white do you find the most pleasant for this application ? I'm trying to buy the components to make this mod.
     
  9. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    I use bright white, but I believe most people prefer warm white.
     
  10. AlienBeans

    AlienBeans Active Member

    Joined:
    May 19, 2016
    Messages:
    110
    Likes Received:
    27
    This is terrific. I've never done any mods before, but this is one that I would love to do. Would it be too much trouble to post the links to where those items can be purchased? Also the steps to add the firmware and the g-code for web control would be helpful for a newbie.
     
  11. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Since I wasn't in a rush to do this mod, I sourced everything from China, Banggood or Aliexpress usually. You can also get stuff much faster from Amazon (especially if you have Prime) but at added costs.


    The green main power connectors are not available from Banggood so it is either Amazon or Aliexpress for those.
     
    ytilotia likes this.
  12. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111

    This should be the first one:

    http://s.aliexpress.com/eyAnUney
     
  13. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Yep, that one will work also. I order from both Banggood and Aliexpress and found that Banggood is generally faster with shipping to the US. Plus they have a US warehouse for some stuff.
     
  14. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111

    I downloaded your github source code and see a few changes. For example, the default brightness and the LED_PIN. Which is the one to use? what is quoted in your post, or what you have in your github?

    LED_PIN 13 or 5?
    Default Brightness 16 or 105 ?
     
  15. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    LED_PIN doesn't matter we are using CASE_LIGHT_PIN, I use a default brightness of 16 because I want the printer fairly dim until I am actually printing something and for my particular LED strips 16 is dim enough. In other works find your own pleasant level and use that number.
     
  16. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111
    OK. I’m still trying to get it to compile right off your code. I’ve never used the arduino ide before. I get an error:
    Pins for this chip not defined in Arduino.h!

    It’s been 20 years since I programmed in C++, but I can see this is happening on line 56 of fashion.h when it reaches the end of the else if statements. If this is not the place to discuss this, i will gladly make a new thread.

    Thanks


    Sent from my iPad using Tapatalk Pro
     
  17. WheresWaldo

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

    Joined:
    Feb 18, 2015
    Messages:
    5,905
    Likes Received:
    3,593
    Are you sure it is set up for ATMEGA2560 in both Board and Processor under Tools?
     
  18. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111
    no, but it is now. sorry for such a newbie mistake
     
  19. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111
    The important thing to note for those using 12v LEDs and Buck converters - you must have it wired up like this:

    24v source -> buck converter (12v out) -> PWM mosfet -> LEDs...


    Sent from my iPad using Tapatalk Pro
     
    #19 supercazzola, Feb 16, 2018
    Last edited: Feb 16, 2018
  20. supercazzola

    supercazzola Active Member

    Joined:
    Jun 1, 2017
    Messages:
    424
    Likes Received:
    111
    Just some photos to show how I routed the wires


    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]


    Sent from my iPhone using Tapatalk Pro
     
    Shrey, WheresWaldo and mark tomlinson like this.

Share This Page