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

Solved Realtime LED Tempurature Feedback

Discussion in 'Troubleshooting' started by Marquis Johnson, Aug 6, 2015.

  1. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    203
    I'll be sure to make a video on the installation too.

    If you want to see it prototyped, click here


    Any recommendations before I start making the video and solder everything together?

    I've made a transistor circuit that uses the PWM pins 4,5,6
    The way the code works so far is as follows:
    1. Startup each LED fades on and off then all fade on to make white
    Optimized-20150806_102251.jpg Optimized-20150806_102325.jpg Optimized-20150806_102150.jpg Optimized-20150806_102118.jpg
    2. After the printer is on if Target Temp is 0 then leds are white,
    Optimized-20150806_102118.jpg
    3. If target temp is above 0 (and not 5) leds will fade from blue to red depending on temp
    Optimized-20150806_102150.jpg Optimized-20150806_102214.jpg Optimized-20150806_102232.jpg Optimized-20150806_102251.jpg
    4. If target temp and extruder temp are the same + or - TEMP_HYSTERESIS leds are back to white
    Optimized-20150806_102300.jpg
    5. If target temp is 5 then leds will be green (you can set this in finish G-Code after a print is done)
    Optimized-20150806_102325.jpg

    Code:
    #ifdef TEMP_STAT_LEDS
    //#define START_UP
    static uint32_t stat_update = 0;
    //Virtual Variables
    int Rval = 0;
    int Gval = 0;
    int Bval = 0;
    int temp;
    int target;
    //Static Colors
    void white(){Rval = 255;Gval = 255;Bval = 255;}
    void red(){Rval = 255;Gval = 0;Bval = 0;}
    void green(){Rval = 0;Gval = 255;Bval = 0;}
    void blue(){Rval = 0;Gval = 0;Bval = 255;}
    //Handle Led Stauts
    void handle_status_leds(){
    //Fade Leds On when starting up
      if(Rval+Gval+Bval == 0){
    //length of delay
      int t = 1;
      for(int r = 0; r<255; r++){Rval = r;analogWrite(STAT_LED_RED, Rval);delay(t);}
      for(int r = 255; r>0; r--){Rval = r;analogWrite(STAT_LED_RED, Rval);delay(t);}
      for(int g = 0; g<255; g++){Gval = g;analogWrite(STAT_LED_GREEN, Gval);delay(t);}
      for(int g = 255; g>0; g--){Gval = g;analogWrite(STAT_LED_GREEN, Gval);delay(t);}
      for(int b = 0; b<255; b++){Bval = b;analogWrite(STAT_LED_BLUE, Bval);delay(t);}
      for(int b = 255; b>0; b--){Bval = b;analogWrite(STAT_LED_BLUE, Bval);delay(t);}
      for(int w = 0; w<255; w++){Rval = w; Gval = w; Bval = w;analogWrite(STAT_LED_RED, Rval);analogWrite(STAT_LED_GREEN, Gval);analogWrite(STAT_LED_BLUE, Bval);delay(t);}
      }
      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);
      }
    //White at Idle or at Temp
      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 < 190)){
      Rval = map(temp,40,190,0,255);
      Gval = 0;
      if(Rval == 0){Bval = 255;}
      if(Rval > 0){Bval = 255-Rval;}
      }
      }
      }
    //Write to LEDs
      analogWrite(STAT_LED_RED, Rval);
      analogWrite(STAT_LED_GREEN, Gval);
      analogWrite(STAT_LED_BLUE, Bval);
      }
    }
    #endif
    
     
    #1 Marquis Johnson, Aug 6, 2015
    Last edited: Aug 6, 2015
    nonmindo and Mike Kelly like this.
  2. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    203
    in pins.h I did this:

    Code:
    #ifdef TEMP_STAT_LEDS
      #if MOTHERBOARD == 67
      #define STAT_LED_RED  6
      #define STAT_LED_BLUE  11
      #endif
    //Marquis Johnson 8/6/2015
      #if MOTHERBOARD == 33
      //Transistor RGB configuration
      #define STAT_LED_RED 6
      #define STAT_LED_BLUE 5
      #define STAT_LED_GREEN 4
      #endif
      #endif
    
     
    #2 Marquis Johnson, Aug 6, 2015
    Last edited: Aug 6, 2015
    nonmindo likes this.
  3. donhuevo

    donhuevo Active Member

    Joined:
    Mar 29, 2014
    Messages:
    138
    Likes Received:
    100
    nonmindo and Marquis Johnson like this.
  4. Frankn

    Frankn Member

    Joined:
    Mar 1, 2015
    Messages:
    261
    Likes Received:
    22
    Why not just simply use 3 leds. Say yellow for warming up/low temp. Red for over temp. and green for ready to print.?
    When I designed a system where I worked my boss would often tell me KISS. No offense meant. lol Frank
     
  5. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    203
    Because, Frank, as far as programming goes, the code used for 3 separate LEDs is as simple as the code for an RGB LED. Only difference is that the RGB LED has 16,777,216 different states and the 3 LEDs have ... only 3. Also, I am using "if statements" and "for loops" to reference and define color values, so that allows the code to grab a color by itself.

    My engineering teacher (Mr. Pappano from that video) often told me KISS when I started programing, and I definitely keep simplicity in mind when writing code.
     
    #5 Marquis Johnson, Aug 6, 2015
    Last edited: Aug 6, 2015
  6. Frankn

    Frankn Member

    Joined:
    Mar 1, 2015
    Messages:
    261
    Likes Received:
    22
    It was just a suggestion. I don't program. I worked for Xerox on 2D copiers and printers for 32 years. It was all mechanical and electronics with very little computing integrated until the 1075's and that was in the troubleshooting and timing sequences.
    Any coding I stuck in there was copied from service literature. No, I am not a coder. I dealt strictly with the components like transistors, IC's, triacs, resistors, capacitors, etc. I agree, it's a nice looking light show, but being a Unitarian type person, 3 leds would serve the same purpose for me. Frank
    PS: or maybe only 1 tricolor type. LOL
     
  7. Marquis Johnson

    Marquis Johnson Active Member

    Joined:
    Feb 18, 2015
    Messages:
    204
    Likes Received:
    203
    Going to create tutorial thread soon, just need to get wiring diagram down.

    Jump to 7:02 to see demonstration

     
    #7 Marquis Johnson, Aug 12, 2015
    Last edited: Aug 12, 2015
    nonmindo, Mike Kelly and WheresWaldo like this.
  8. Mike Kelly

    Mike Kelly Volunteer

    Joined:
    Mar 11, 2013
    Messages:
    6,967
    Likes Received:
    2,276
    heh I like your reaction
     
  9. cjryker06

    cjryker06 New Member

    Joined:
    Mar 22, 2016
    Messages:
    22
    Likes Received:
    0
    Would this method apply to the R1+ in essentially the same manor or are there a lot of several differences? I would like to change my white stock LEDs to a functional light.
     
  10. Mike Kelly

    Mike Kelly Volunteer

    Joined:
    Mar 11, 2013
    Messages:
    6,967
    Likes Received:
    2,276
    In theory yes but the R1+ Doesn't have the pins soldered in for Aux so you'd have to add them
     
  11. cjryker06

    cjryker06 New Member

    Joined:
    Mar 22, 2016
    Messages:
    22
    Likes Received:
    0
    Any other way of doing something similar?
     

Share This Page