Skip to content

Instantly share code, notes, and snippets.

@pwillard
Created July 8, 2015 14:58
Show Gist options
  • Save pwillard/d1f6171f10842c9fb7e0 to your computer and use it in GitHub Desktop.
Save pwillard/d1f6171f10842c9fb7e0 to your computer and use it in GitHub Desktop.
/*
This when finished will control a glass kiln with 4 settings
have a ramp to temp/ and timers based on system 96 glass settings.
Special thanks to:
Ryan McLaughlin <ryanjmclaughlin@gmail.com MAX6675
Brett Beauregard <www.brettbeauregard.com PID_Beta6
David A. Mellis SoftWareSerial
Jesse Tane for http://labs.ideo.com TimerOne
Bart Meijer (bart@sbo-dewindroos.nl) AdvButton an ButtonManager
and zer0vector from the Arduino forum for pointing out the TimerOne function
Any one is free to use this code for their project.
I AM NOT LIABLE FOR ANY DAMAGES CAUSED BY THE USE OF THIS CODE.
THERE IS NO WARRANTY EITHER EXPRESSED OR IMPLIED.
YOU USE THIS CODE AT YOUR OWN RISK.
REV 1.0.0.2
For Arduino UNO board.
Glenn Davina 10/30/2010
*/
#include <stdlib.h>
#include <PID_Beta6.h>
#include <MAX6675.h>
#include <SoftwareSerial.h>
#include <TimerOne.h>
#include <AdvButton.h> //I started with buttons but moved to this not sure if better or not
#include <ButtonManager.h>
// Convert the txPin to pin number 2
#define txPin 2 //For writting to SparkFun LCDSerial 2.5 board
long previousMillis = 0;
int Heater = 9; // To SSR for heater Coil mine is 12v
int CS = 10; // CS pin on MAX6675
int SO = 12; // SO pin of MAX6675
int SCK = 13; // SCK pin of MAX6675
int units = 0; // Units to readout temp (0 = degF, 1 = degC)
float error = -8.0; // Temperature compensation error
int temperature = 0; // Temperature output variable
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// Initialize the MAX6675 Library for our chip
// MAX6675 Library already sets pin modes for MAX6675 chip!
MAX6675 temp0(CS,SO,SCK,units,error);
// Initialize PID items
unsigned long RampStartTime;
double Input, Output, Setpoint,AmntTime,InitInput;
PID pid(&Input, &Output, &Setpoint, 4,3.75,1.5);
unsigned long InitStartTime= 0;
unsigned long MyDelay; //this will help us know when to talk with processing
int SelTemp,SelHold, SelButton,StartCycle;
int ButtonPressed=0;
unsigned long cumulativeSeconds = 0;
unsigned int totalseconds = 0;
unsigned int totalminutes = 0;
unsigned int totalhours = 0;
char totaltime[6] = " : ";
//char lasttotaltime[9] = " : : ";
//char stepelapsedtime[9] = " : : ";
unsigned long cyclecount=0;
//char steptotaltime[9] = " : : ";
char temptime[9] = " : : ";
#define PinBStart 7
#define PinButton1 3
#define PinButton2 4
#define PinButton3 5
#define PinButton4 6
AdvButton BStart = AdvButton(PinBStart,NULL,NULL,OnKeyDownBStart,btn_Digital);
AdvButton Button1 = AdvButton(PinButton1,NULL,NULL,OnKeyDownButton1,btn_Digital);
AdvButton Button2 = AdvButton(PinButton2,NULL,NULL,OnKeyDownButton2,btn_Digital);
AdvButton Button3 = AdvButton(PinButton3,NULL,NULL,OnKeyDownButton3,btn_Digital);
AdvButton Button4 = AdvButton(PinButton4,NULL,NULL,OnKeyDownButton4,btn_Digital);
void setup() {
Serial.begin(9600);
pinMode(Heater, OUTPUT);
pinMode(txPin, OUTPUT);
//Make sure heater is off SSR is 12v so using arduino as a sink
Timer1.initialize(); //turn on the Timer, default 1 second frequency
//Setup Serial for LCD
LCD.begin(9600);
LCDCLearScreen();
LCD.print ("Diane's Kiln");
pid.SetOutputLimits(0,255);
pid.SetInputLimits(0,2000);//with out this the inputs stop at 1023 and the kiln temp goes on up.
pid.SetTunings(3,4,1); //Is not easy to tune a system that takes 3hrs to get to temp this seems to hold at +- 2 degrees
Output=2;
MyDelay=0;
Timer1.pwm(Heater, Output);//start PWM on pin 9 with a 0% duty cycle
//BStart.assign(7);
//Button1.assign(3);
// Button2.assign(4);
// Button3.assign(5);
// Button4.assign(6);
// BStart.setMode(OneShotTimer);
// Button1.setMode(OneShotTimer);
// Button2.setMode(OneShotTimer);
// Button3.setMode(OneShotTimer);
// Button4.setMode(OneShotTimer);
delay(1000);//give a chance for the lcd to boot
SelButton=0;
digitalWrite(Heater, LOW);//get the SSR in a know state!
}
void loop() {
int MessageLoop=0;//the loop function only gets used on start up and when the kiln is down.
ButtonManager::instance()->checkButtons();
switch (ButtonPressed)
{
case 1:
MyDelay=millis()+(5000);
ButtonPressed=0;
SelTemp=1479;
SelHold=15;
SelButton=1;
LCDCLearScreen();
Serial.print("Button1");
LCDFirstLine();
LCD.print("Fuse ");
LCDSecondLine();
LCD.print("Select Start ");
delay(50);
break;
case 2:
MyDelay=millis()+(5000);
ButtonPressed=0;
SelTemp=1450;
SelHold=15;
SelButton=2;
LCDSecondLine();
Serial.print("Button2");
LCDFirstLine();
LCD.print("Tack Fuse ");
LCDSecondLine();
LCD.print("Select Start ");
break;
case 3:
MyDelay=millis()+(5000);
ButtonPressed=0;
SelTemp=1370;
SelHold=15;
SelButton=3;
LCDSecondLine();
Serial.print("Button3");
LCDFirstLine();
LCD.print("Fire Polish ");
LCDSecondLine();
LCD.print("Select Start ");
break;
case 4:
MyDelay=millis()+(5000);
ButtonPressed=0;
SelTemp=1250;
SelHold=15;
SelButton=4;
LCDSecondLine();
Serial.print("Button4");
LCDFirstLine();
LCD.print("Slump ");
LCDSecondLine();
LCD.print("Select Start ");
break;
case 5:
MyDelay=millis()+(5000);
ButtonPressed=0;
StartCycle=1;
//Serial.print("Button Start");
switch (SelButton){
case 0:
LCDCLearScreen();
LCD.print("Select a Cycle");
LCDSecondLine();
LCD.print(" ");
LCDSecondLine();
LCD.print("Button First");
break;
default :
Serial.print("In Default");
InitStartTime= millis();
LCDCLearScreen();
FUSE();
}
}
if (millis()>MyDelay){
InitInput = temp0.read_temp(5);
delay(40);
if(InitInput == -1) TCErrorPrint(); // If there is an error with the TC, temperature will be -1
else
{
if (MessageLoop<19){ //did this as a reset for a accidental button press.
LCDCLearScreen(); // resets the LCD text and the cycle button count.
LCDFirstLine();
LCD.print ("Diane's Kiln");
MessageLoop=0;
SelButton=0;
}
LCDSecondLine();
LCD.print(" ");//Was just doing the temp but when you lose a digit
LCDSecondLine(); // it leaves the original behind. Could probably figure out right
// justify save for later.
LCD.print("Curr.Temp: "); //Really should be writting in just the temp but this
LCD.print((int)InitInput);// works for now.
MyDelay=millis()+(1000);
MessageLoop++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment