Print Case Temperature - any benefits ? August 07, 2015 04:24PM |
Registered: 8 years ago Posts: 126 |
Re: Print Case Temperature - any benefits ? August 07, 2015 09:40PM |
Registered: 9 years ago Posts: 1,873 |
Re: Print Case Temperature - any benefits ? August 07, 2015 10:05PM |
Registered: 10 years ago Posts: 580 |
Re: Print Case Temperature - any benefits ? August 08, 2015 09:11AM |
Registered: 8 years ago Posts: 126 |
Quote
Paul Wanamaker
I'm sure others would be interested in the temp monitoring code as well. Please post it here if you want!
Re: Print Case Temperature - any benefits ? August 08, 2015 12:53PM |
Registered: 8 years ago Posts: 126 |
#include
#if NUM_SERVOS > 0 #include "Servo.h" #endif
// OneWire code // added for the case temp sensors #include OneWire myds(57); // Temperature Data wire is plugged into pin D57 ( A3 ) on the Arduino byte DSreadstage; byte DSresolution = 10; unsigned long DSstarttime; byte LocalTemp1[8] = { 0x28, 0xCC, 0xD1, 0xE1, 0x02, 0x00, 0x00, 0xE6 }; // temp sensor 1 at TOP of case - unique address byte LocalTemp2[8] = { 0x28, 0xE5, 0x18, 0xF0, 0x01, 0x00, 0x00, 0x45 }; // temp sensor 2 at BOTTOM of case - unique address byte LocalTemp3[8] = { 0x28, 0xE5, 0x18, 0xF0, 0x01, 0x00, 0x00, 0x46 }; // temp sensor 3 outside the case - unique address // NOTE : the 3 Device Address values are specific to MY sensors. You will need to get the correct addresses for each of your sensors. // See this page for instructions : // [www.hacktronics.com]
float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; bool axis_known_position[3] = {false, false, false}; float zprobe_zoffset;
// OneWire code float DStemp1; float DStemp2; float DStemp3;
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0) delay(PROBE_SERVO_DEACTIVATION_DELAY); servos[servo_endstops[Z_AXIS]].detach(); #endif }
// OneWire code int resolution = 10; // OneWire code void dssetresolution(OneWire myds, byte addr[8], byte resolution) { byte resbyte = 0x1F; // Get byte for desired resolution if (resolution == 12){ resbyte = 0x7F; } else if (resolution == 11) { resbyte = 0x5F; } else if (resolution == 10) { resbyte = 0x3F; } myds.reset(); // Set configuration myds.select(addr); myds.write(0x4E); // Write scratchpad myds.write(0); // TL myds.write(0); // TH myds.write(resbyte); // Configuration Register myds.write(0x48); // Copy Scratchpad } // OneWire code void dsconvertcommand(OneWire myds, byte addr[8]){ myds.reset(); myds.select(addr); myds.write(0x44); // start conversion } // OneWire code float dsreadtemp(OneWire myds, byte addr[8], byte resolution) { byte present = 0; int i; byte data[12]; byte type_s; float celsius; float fahrenheit; switch (addr[0]) { case 0x10: type_s = 1; //Serial.println(F(" Chip = DS18S20")); // or old DS1820 break; case 0x28: type_s = 0; //Serial.println(F(" Chip = DS18B20")); break; case 0x22: type_s = 0; //Serial.println(F(" Chip = DS1822")); break; } present = myds.reset(); myds.select(addr); myds.write(0xBE); // Read Scratchpad for ( i = 0; i < 9; i++) { // we need 9 bytes data = myds.read(); } // convert the data to actual temperature unsigned int raw = (data[1] << 8) | data[0]; if (type_s) { raw = raw << 3; // 9 bit resolution default if (data[7] == 0x10) { // count remain gives full 12 bit resolution raw = (raw & 0xFFF0) + 12 - data[6]; } else { byte cfg = (data[4] & 0x60); if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms // default is 12 bit resolution, 750 ms conversion time } } celsius = (float)raw / 16.0; fahrenheit = celsius * 1.8 + 32.0; return celsius; }
void setup() {
// OneWire code dssetresolution(myds,LocalTemp1,DSresolution); // added for the case temperature sensors dssetresolution(myds,LocalTemp2,DSresolution); // added for the case temperature sensors dssetresolution(myds,LocalTemp3,DSresolution); // added for the case temperature sensors
void manage_inactivity() { if(buflen < (BUFSIZE-1)) get_command();
// OneWire code if (DSreadstage == 0){ if(millis() > DSstarttime + 3000){ DSstarttime = millis(); dsconvertcommand(myds,LocalTemp1); dsconvertcommand(myds,LocalTemp2); dsconvertcommand(myds,LocalTemp3); DSreadstage = 1; } } else { if (myds.read()) { DStemp1 = dsreadtemp(myds,LocalTemp1, DSresolution); DStemp2 = dsreadtemp(myds,LocalTemp2, DSresolution); DStemp3 = dsreadtemp(myds,LocalTemp3, DSresolution); if (DStemp1 == -127.00 || DStemp1 >= 400) DStemp1 = 0; // very high value means no sensor detected if (DStemp2 == -127.00 || DStemp2 >= 400) DStemp2 = 0; if (DStemp3 == -127.00 || DStemp3 >= 400) DStemp3 = 0; DSreadstage = 0; } }
#ifdef DELTA extern float endstop_adj[3]; extern float delta_radius;
// OneWire code extern float DStemp1; extern float DStemp2; extern float DStemp3;
static void lcd_implementation_status_screen()
// OneWire code static void _draw_case_temp(int x, int DSsensor) { int y = 6; u8g.setFont(FONT_STATUSMENU); if(DSsensor == 1){ y = 6; u8g.setPrintPos(x,6); u8g.print(ftostr21ns(DStemp1)); lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); } if(DSsensor == 2){ y = 16; u8g.setPrintPos(x,16); u8g.print(ftostr21ns(DStemp2)); lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); } if(DSsensor == 3){ y = 26; u8g.setPrintPos(x,26); u8g.print(ftostr21ns(DStemp3)); lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); } u8g.setColorIndex(0); // white on black u8g.drawBox(x+7,y,2,2); u8g.setColorIndex(1); // black on white }
// Extruders _draw_heater_status(6, 0); #if EXTRUDERS > 1 _draw_heater_status(31, 1); #if EXTRUDERS > 2 _draw_heater_status(55, 2); #endif #endif
// Extruders _draw_heater_status(6, 0); #if EXTRUDERS > 1 _draw_heater_status(31, 1); // my setup only has 1 extruder so removed the option for the 3rd extruder to make space for the temperatures // #if EXTRUDERS > 2 // _draw_heater_status(55, 2); // #endif #endif // OneWire code // read, calc and print the case temperature/s _draw_case_temp(42,1); // display the temp of the top temperature sensor _draw_case_temp(42,2); // display the temp of the bottom temperature sensor _draw_case_temp(42,3); // display the temp of the outside temperature sensor
char *ftostr52(const float &x);
char *ftostr21ns(const float &x);
// Convert int to lj string with +123.0 format char *itostr31(const int &xx)
// OneWire code // Convert float to string with 2.1 format char *ftostr21ns(const float &x) { long xx=x*10; xx=abs(xx); conv[0]=(xx/1000)%10+'0'; if(conv[0] == '0') conv[0] = ' '; conv[1]=(xx/100)%10+'0'; if(conv[0] == ' ' && conv[1] == '0') conv[1] = ' '; conv[2]=(xx/10)%10+'0'; conv[3]='.'; conv[4]=(xx)%10+'0'; conv[5]=0; return conv; }
Re: Print Case Temperature - any benefits ? August 09, 2015 12:02PM |
Registered: 9 years ago Posts: 517 |
Quote
DaveOBbyte LocalTemp1[8] = { 0x28, 0xCC, 0xD1, 0xE1, 0x02, 0x00, 0x00, 0xE6 }; // temp sensor 1 at TOP of case - unique address byte LocalTemp2[8] = { 0x28, 0xE5, 0x18, 0xF0, 0x01, 0x00, 0x00, 0x45 }; // temp sensor 2 at BOTTOM of case - unique address byte LocalTemp3[8] = { 0x28, 0xE5, 0x18, 0xF0, 0x01, 0x00, 0x00, 0x46 }; // temp sensor 3 outside the case - unique address
Re: Print Case Temperature - any benefits ? August 09, 2015 12:19PM |
Registered: 8 years ago Posts: 126 |
Quote
ElmoC
Just to be sure, these are the values encoded in the device's ROM? So anyone wanting to add this feature in will have to determine the code and replace these values.
// NOTE : the 3 Device Address values are specific to MY sensors. You will need to get the correct addresses for each of your sensors. // See this page for instructions : // [www.hacktronics.com]