Welcome! Log In Create A New Profile

Advanced

Neo-Pixel LED's for a Prusa i3 clone

Posted by Ricky146a 
Neo-Pixel LED's for a Prusa i3 clone
February 16, 2019 12:57PM
Hello All

After building my Sintron Prusa i3 and getting it to produce decent prints I decided I wanted to add some modifications to it.
First on my list was a bunch of LED's to illuminate the extruder/build area.

After investigating the neo-pixels available I thought it would be neat to have one led that indicated the state of the extruder temp and one that indicated the heat bed temp then all the rest could be white.

In the end I have one led that starts blue and changes to red when the extruder is hot and finally turns white when it is fully hot.
The same for the bed temp led.
The remaining 10 leds are all white but increase in brightness in line with the bed temp.

I am using a 12 neo-pixel led ring from here neo-pixel ring

I know neo-pixels have been covered elsewhere on this forum but I could not find a start to finish explanation so here goes.

Neo-pixels are different from ordinary led's in that in a strip or ring, each colour of each led can be addressed individually but the whole array of led's only uses 5 volt supply, ground and one signal wire from your Arduino/Ramps electronics.

The 5 volt from the Arduino does not have the amperage required to drive 12 led's so I use a well regulated external supply. The ground of this supply is also connected to the ground of the Arduino.
A digital pin is required and I used pin 6 (this is the signal pin of one of the servo pins (can be seen in the link above). Also, a 100uf capacitor is connected across the +ve and -ve power supply to the ring.

Now to the firmware...
I used the very good guide by donhuevo from here as my inspiration so well worth a read.

Most of the magic happens in Marlin-main-cpp

At the top I include these lines

#ifdef NEOPIXEL_LEDS
#include "Adafruit_NeoPixel.h"
Adafruit_NeoPixel ext_neopixel = Adafruit_NeoPixel(12, 6, NEO_GRB + NEO_KHZ800);
#endif

The next code just sets up the neo-pixels for action and defines the variable.
This is added towards the top of Void setup section

void setup()
{
setup_killpin();
setup_powerhold();
MYSERIAL.begin(BAUDRATE);
SERIAL_PROTOCOLLNPGM("start");
SERIAL_ECHO_START;
// start code for neo pixels
bed_neopixel.begin();
// bed_neopixel.show();
ext_neopixel.begin();
// ext_neopixel.show();
uint32_t w = ext_neopixel.Color(0, 0, 0);

// Check startup - does nothing if bootloader sets MCUSR to 0

The "show" commands are commented out as there is no point at this stage.

The next large lump of code goes immediately before TEMP_STAT_LEDS near the end of the file.

void handle_neopixels(void) {
if(millis() > stat_update) {
stat_update += 500;
// SET Bed LED
if(degBed() > 0) {
if(degBed() > degTargetBed() && degTargetBed() > 0) {
curr_bed_temp = degTargetBed();
} else {
curr_bed_temp = degBed();
}
}
target_bed_temp = degTargetBed();

if(curr_bed_temp >= 30.0) {
if(target_bed_temp > 0) { //Heating Up
c_diff = (curr_bed_temp - 30)*255/(target_bed_temp-30);
if(c_diff>255) {c_diff = 255;}
} else { //Cooling Down
c_diff = (curr_bed_temp-30)*6;
if(c_diff>255) {c_diff = 255;}
}
neo_r = c_diff; // sets a variable value to use later for brightness of pixels
neo_b = 255 - c_diff; // reduces the blue content as bed heats up
} else { //Temp is less than 30.0
neo_r = 0;
neo_b = 255;
}
last_bed_c = bed_c;
bed_c = bed_neopixel.Color(neo_r, neo_g, neo_b);
if(bed_c != last_bed_c) { //only update if there's a change
uint32_t w = ext_neopixel.Color(neo_r, neo_r, neo_r); //will cause neopixels to brighten as bed pixel changes to red
ext_neopixel.setPixelColor(2, w); // next lines set pixels to white with variable brightness
ext_neopixel.setPixelColor(3, w); // remember pixel numbers start from 0 so this is pixel 4 of 12
ext_neopixel.setPixelColor(4, w);
ext_neopixel.setPixelColor(5, w);
ext_neopixel.setPixelColor(6, w);
ext_neopixel.setPixelColor(7, w);
ext_neopixel.setPixelColor(8, w);
ext_neopixel.setPixelColor(9, w);
ext_neopixel.setPixelColor(10, w);
ext_neopixel.setPixelColor(11, w);
ext_neopixel.setPixelColor(1, bed_c); //pixel 1 will start blue but change red as bed heats up
ext_neopixel.show();
if(neo_b < 30) {
ext_neopixel.setPixelColor(1, 255, 250, 250); // will change bed pixel to change white when fully red ie blue content less than 30
ext_neopixel.show();
}
}
// SET Extruder LED
if(degHotend(0) > 0) {
if(degHotend(0) > degTargetHotend(0) && degTargetHotend(0) > 0) {
curr_ext_temp = degTargetHotend(0);
} else {
curr_ext_temp = degHotend(0);
}
}
target_ext_temp = degTargetHotend(0);
if(curr_ext_temp > 30.0) {
if(target_ext_temp > 0) {
c_diff = (curr_ext_temp - 30)*255/(target_ext_temp-30);
if(c_diff>255) {c_diff = 255;}
} else {
c_diff = (curr_ext_temp-30)*2;
if(c_diff>255) {c_diff = 255;}
}
neo_r = c_diff;
neo_b = 255 - c_diff;
} else {
neo_r = 0;
neo_b = 255;
}
last_ext_c = ext_c;
ext_c = ext_neopixel.Color(neo_r, neo_g, neo_b);
if(ext_c != last_ext_c) {
ext_neopixel.setPixelColor(0, ext_c);
ext_neopixel.show();
}
if(neo_b < 30) {
ext_neopixel.setPixelColor(0, 255, 250, 250); // will change extruder pixel to change white when fully red ie blue content less than 30
ext_neopixel.show();
}
}
}
#endif

#ifdef TEMP_STAT_LEDS

Very near the end of the file add this one "if" statement

#ifdef TEMP_STAT_LEDS
handle_status_leds();
#endif

#ifdef NEOPIXEL_LEDS
handle_neopixels();
#endif

And finally near the end of Configuration.h add this one line

// Temperature status LEDs that display the hotend and bet temperature.
// If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on.
// Otherwise the RED led is on. There is 1C hysteresis.
//#define TEMP_STAT_LEDS
#define NEOPIXEL_LEDS

That is all there is.
If you want to try this and want a copy of my sketch then let me know.
It makes no difference whether you use a ring or a strip and you can change the number of led's or colours as you wish.

Have fun!
Sorry, only registered users may post in this forum.

Click here to login