Tuesday, April 11, 2017

3D Printer neopixel enclosure

PROJECT 2: 3D PRINTER ENCLOSURE


So I decided to make an enclosure for my 3d printer (mp select mini). After researching for a while the most affordable and possibly the easiest way to build an enclosure for my mini is the Lack table from Ikea method. There is a tutorial on how to make one on instructables.com but i did not go that route but instead. I designed my own enclosure. Now the number one problem that i have with this printer is noise. I live in a very small space so I'd like to get some sleep and still be able to print/design. The most popular reason why people want to go with this enclosure is heat. An enclosure is very ideal for printing ABS .
My enclosur consists of 2 Ikea Lack tables stack on top of each others. I glued the legs to the top of the bottom table and drill a hole to insert a pin between the legs. You can easily print out your own pins. For me I was using the pins I bought from Lowes.

The next step is to enclose four sides somehow. Thats when I bought 1 piece of 18x24 arcrylic sheet and cut it to size for my front door. On the sides I bought 3 pieces of congugated plastic because they ar super cheap and they get the job done. Then I cut them to size and glued them on the sides of the top table.

The next step is attaching noise insulation foams. These foams ar designed to absorb some of the soud energy therefore reduce the noise level. Probably not by much but good enough for me.

After that I drilled a hole in th back to feed the power cable through and voila. You have your enclosure. It looks pretty neat. It does make me feel like it's a chamber. Maybe I'll call it the mini chamber.


For the glass door you can print out a latch and attach it to the sides. Itl work pretty well too. You can stop here but since I have a couple of electronic sitting around. I decided to pimp it. :))
Heres what it looks like with the electronics





The Control box consists of 1 Arduino Uno (Micro controller), 1 TFT Touchscreen Display, 1 Battery pack (9.6V RC) battery, this one is Lithium Nickel I think. And a LM298 Motor Driver. All of these components are spare since I've upgraded my RC project I no longer need these. And I did not want to throw it away either. I mainly use the motor driver for that 5V regulator. There are 2 voltage sources on the side leaving room for improvement in the future. You do not have to use it. Yo u can just use a 5V regulator and it should be good. The Neopixel and the Arduino combine I think draw less than half of an Amp. So your IC chip should be enough to supply for these.
The  LOADS:
There are 2 loads. 1 is the Neopixel Ring from Adafruit. which is super colorful and super fun to play with. Costs only about $10.

The other load is the temperture sensor from ebay. This guy is also very affordable. The name is DHT11 Sensor. There is a library for it for Arduino so it was super easy to work with. And the temperature reading is quite accurate.




Connecting/Wiring is pretty straigh forward, For Neopixel, connect the data in pin to Arduino pin number 5 (written in the code), and temperature sensor pin to pin number 10. Vcc to Vcc and GND to GND. If you are not sure what this mean please contact me.


Okay.
So here is the code for the arduino
://neopixel package sections
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 5

#define NUM_LEDS 60

#define BRIGHTNESS 50

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);

int gamma[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
//END neopixel includes

//***********************************TOUCH SCREEN PACKAGE SECTIONS
#include <dht.h>
dht DHT;
// Paint example specifically for the TFTLCD breakout board.
// If using the Arduino shield, use the tftpaint_shield.pde sketch instead!
// DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO

// Modified for SPFD5408 Library by Joao Lopes
// Version 0.9.2 - Rotation for Mega

// *** SPFD5408 change -- Begin
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
// *** SPFD5408 change -- End



#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7

// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 22
//   D1 connects to digital pin 23
//   D2 connects to digital pin 24
//   D3 connects to digital pin 25
//   D4 connects to digital pin 26
//   D5 connects to digital pin 27
//   D6 connects to digital pin 28
//   D7 connects to digital pin 29

// For the Arduino Due, use digital pins 33 through 40
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 33
//   D1 connects to digital pin 34
//   D2 connects to digital pin 35
//   D3 connects to digital pin 36
//   D4 connects to digital pin 37
//   D5 connects to digital pin 38
//   D6 connects to digital pin 39
//   D7 connects to digital pin 40

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

// Original values
//#define TS_MINX 150
//#define TS_MINY 120
//#define TS_MAXX 920
//#define TS_MAXY 940

// Calibrate values
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define BOXSIZE 120
#define PENRADIUS 3

#define MINPRESSURE 10
#define MAXPRESSURE 1000
int oldcolor, currentcolor;

TSPoint p;

void setup(void) {


  tft.reset();

  // *** SPFD5408 change -- Begin
//  uint16_t identifier = tft.readID();
//
//  if(identifier == 0x9325) {
//    Serial.println(F("Found ILI9325 LCD driver"));
//  } else if(identifier == 0x9328) {
//    Serial.println(F("Found ILI9328 LCD driver"));
//  } else if(identifier == 0x7575) {
//    Serial.println(F("Found HX8347G LCD driver"));
//  } else if(identifier == 0x9341) {
//    Serial.println(F("Found ILI9341 LCD driver"));
//  } else if(identifier == 0x8357) {
//    Serial.println(F("Found HX8357D LCD driver"));
//  } else {
//    Serial.print(F("Unknown LCD driver chip: "));
//    Serial.println(identifier, HEX);
//    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
//    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
//    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
//    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
//    Serial.println(F("Also if using the breakout, double-check that all wiring"));
//    Serial.println(F("matches the tutorial."));
//    return;
//  }
//
//  tft.begin(identifier);

  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial

  // Border

  drawBorder();

  // Initial screen

  tft.setCursor (55, 50);
  tft.setTextSize (6);
  tft.setTextColor(BLUE);
  tft.println("ECU");

  tft.setCursor(40,100);
  tft.setTextSize(1);
  tft.println("Enviromental Control Unit");

  tft.setCursor(60,150);
  tft.setTextSize(1);
  tft.setTextColor(RED);
  tft.println("Khoa Au");
  tft.setCursor(60,160);
  tft.println("au0516.blogspot.com");

  tft.setCursor (70, 250);
  tft.setTextSize (1);
  tft.setTextColor(BLACK);
  tft.println("Tap to continue");

  // Wait touch
  waitOneTouch();

// *** SPFD5408 change -- End

  // -- End

  // Paint
  //--------------
  tft.fillScreen(BLACK);
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, RED);
  tft.setCursor (20, 20);
  tft.setTextSize (1);
  tft.setTextColor(RED);
  tft.println("Temperature");

  tft.setCursor (150, 20);
  tft.setTextSize (1);
  tft.setTextColor(RED);
  tft.println("Humidity");

  tft.setCursor (10, 180);
  tft.setTextSize (2);
  tft.setTextColor(WHITE);
  tft.println("NEOPIXEL CONTROL");
//
  tft.drawRect(10, 200, 40, 40, RED);
  tft.setCursor (20, 220);
  tft.setTextSize(1);
  tft.println("ON");
  tft.drawRect(50,200, 40, 40, RED);
  tft.setCursor (60, 220);
  tft.setTextSize(1);
  tft.println("OFF");

//
  pinMode(13, OUTPUT);
 //******************************Neopixel Sections
   Serial.begin(115200);
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code
  strip.setBrightness(BRIGHTNESS);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  //end neopixel section


}



void loop()
{


  digitalWrite(13, HIGH);
  ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    */
 
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
      // press the bottom of the screen to erase
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }
    // scale from 0->1023 to tft.width

    // *** SPFD5408 change -- Begin
    // Bug in in original code
    //p.x = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    // *** SPFD5408 change -- End
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
  }

 tft.fillRect(20,60,50,30,BLACK);
 tft.fillRect(150,60,50,30,BLACK);

//temperature sensor section
  DHT.read11(10);
  tft.setCursor (20, 60);
  tft.setTextSize (2);
  tft.setTextColor(BLUE);
  tft.print(DHT.temperature,1);

  tft.println(" C");

  tft.setCursor (150, 60);
  tft.setTextSize (2);
  tft.setTextColor(BLUE);
  tft.println((int)DHT.humidity,1);

  colorWipe(strip.Color(255, 0, 0), 2); // Red
  colorWipe(strip.Color(0, 255, 0), 2); // Green
  colorWipe(strip.Color(0, 0, 255), 2); // Blue
  colorWipe(strip.Color(0, 0, 0, 255), 2); // White

  // whiteOverRainbow(20,75,5);
 // pulseWhite(5);
 // rainbowFade2White(3,1,1);






////Neopixel section
//  colorWipe(strip.Color(255, 0, 0), 2); // Red
//  colorWipe(strip.Color(0, 255, 0), 2); // Green
//  colorWipe(strip.Color(0, 0, 255), 2); // Blue
//  colorWipe(strip.Color(0, 0, 0, 255), 2); // White
//
//  //whiteOverRainbow(20,75,5);
//
//  //pulseWhite(5);
//
//  // fullWhite();
//  // delay(2000);
//
//  //rainbowFade2White(3,3,1);
////End neopixel section

}

// Wait one touch

TSPoint waitOneTouch() {

  // wait 1 touch to exit function

  TSPoint p;

  do {
    p= ts.getPoint();

    pinMode(XM, OUTPUT); //Pins configures again for TFT control
    pinMode(YP, OUTPUT);

  } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE));

  return p;
}

//****************************************************************NEOPIXEL METHODS*************************************
void drawBorder () {

  // Draw a border

  uint16_t width = tft.width() - 1;
  uint16_t height = tft.height() - 1;
  uint8_t border = 10;

  tft.fillScreen(BLACK);
  tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE);

}
  void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void pulseWhite(uint8_t wait) {
  for(int j = 0; j < 256 ; j++){
      for(uint16_t i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
        }
        delay(wait);
        strip.show();
      }

  for(int j = 255; j >= 0 ; j--){
      for(uint16_t i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
        }
        delay(wait);
        strip.show();
      }
}


void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) {
  float fadeMax = 100.0;
  int fadeVal = 0;
  uint32_t wheelVal;
  int redVal, greenVal, blueVal;

  for(int k = 0 ; k < rainbowLoops ; k ++){
 
    for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel

      for(int i=0; i< strip.numPixels(); i++) {

        wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255);

        redVal = red(wheelVal) * float(fadeVal/fadeMax);
        greenVal = green(wheelVal) * float(fadeVal/fadeMax);
        blueVal = blue(wheelVal) * float(fadeVal/fadeMax);

        strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) );

      }

      //First loop, fade in!
      if(k == 0 && fadeVal < fadeMax-1) {
          fadeVal++;
      }

      //Last loop, fade out!
      else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){
          fadeVal--;
      }

        strip.show();
        delay(wait);
    }

  }



  //delay(500);


  for(int k = 0 ; k < whiteLoops ; k ++){

    for(int j = 0; j < 256 ; j++){

        for(uint16_t i=0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
          }
          strip.show();
        }

       // delay(2000);
    for(int j = 255; j >= 0 ; j--){

        for(uint16_t i=0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
          }
          strip.show();
        }
  }

  //delay(500);


}

void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength ) {

  if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;

  int head = whiteLength - 1;
  int tail = 0;

  int loops = 3;
  int loopNum = 0;

  static unsigned long lastTime = 0;


  while(true){
    for(int j=0; j<256; j++) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
        if((i >= tail && i <= head) || (tail > head && i >= tail) || (tail > head && i <= head) ){
          strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
        }
        else{
          strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
        }
     
      }

      if(millis() - lastTime > whiteSpeed) {
        head++;
        tail++;
        if(head == strip.numPixels()){
          loopNum++;
        }
        lastTime = millis();
      }

      if(loopNum == loops) return;
 
      head%=strip.numPixels();
      tail%=strip.numPixels();
        strip.show();
        delay(wait);
    }
  }

}
void fullWhite() {

    for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
    }
      strip.show();
}


// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256 * 5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
}

uint8_t red(uint32_t c) {
  return (c >> 8);
}
uint8_t green(uint32_t c) {
  return (c >> 16);
}
uint8_t blue(uint32_t c) {
  return (c);
}



No comments:

Post a Comment