Arduino rock!
Created a simple program to monitor oven temperature using arduino, TCmux shield, and TV out library.
Take note that the picture attached do not have the TCmux circuit connected.
Code as below:
// Note: This code uses TV-OUT for Arduino library. Also credit to Shadi Soundation for the TV oscilloscope code
#include <TVout.h>
#include <fontALL.h>
TVout TV;
#include <SPI.h>
#define CS_TEMP 8 // MAX6674/6675 /CS Line
//#define MUX_EN 7 // ADG608 MUX Enable
#define MUX_A0 4 // ADG608 Addr0
#define MUX_A1 5 // ADG608 Arrd1
#define MUX_A2 6 // ADG608 Addr2
#define BUZZER 3 // BUZZER pinout3
#define SO 12 // MISO
#define RESETBTN 2// MISO
#define SCK 13 // Serial Clock
int temperature = 0;
int channelAI = A0; // select the input pin for the Oscilioscope
int scaleYAI = A1; // select the input pin for the Y (horizontal) potentiometer
int scaleXAI = A2; // select the input pin for the X (Vertical) potentiometer
int delayVariable = 0; // define a variable for the Y scale / delay
int xVariable = 0; // define a variable for the x scale
int yCtr = 0; // define a variable for the y counter used to collect y position into array
int posy = 0; // define a variable for the y position of the dot
int myArray[127]; // define an array to hold the data coming in
int RESETval = 0;
unsigned long cure_t=0;
unsigned long base_t=0;
unsigned long minute=0;
unsigned long seconds;
void setup() {
TV.begin(_PAL,128,96); //for devices with only 1k sram(m168) use TV.begin(_PAL,128,56)
pinMode(SO, INPUT);
pinMode(SCK, OUTPUT);
pinMode(CS_TEMP, OUTPUT);
pinMode(MUX_A0, OUTPUT);
pinMode(MUX_A1, OUTPUT);
pinMode(MUX_A2, OUTPUT);
//pinMode(MUX_EN, OUTPUT);
pinMode (BUZZER, OUTPUT);
pinMode (RESETBTN, INPUT);
digitalWrite(CS_TEMP,HIGH);// Set MAX7765 /CS High
//digitalWrite(MUX_EN,HIGH); // Enable on
digitalWrite(BUZZER,LOW); // Enable on
digitalWrite(MUX_A0,LOW);
digitalWrite(MUX_A1,LOW);
digitalWrite(MUX_A2,LOW);
//Serial.begin(9600);
TV.select_font(font6x8);
TV.println(15,30,"TIM TEMPERATURE");
TV.println(15,50," OVEN CHECKER");
draw_axis();
delay(5000);
TV.clear_screen();
draw_axis();
}
void loop()
{
//base_time==millis();
//cure_time==0;
update_display();
}
void update_display() {
exit_loop:
//base_t==Read_time();
//delayVariable = analogRead(scaleYAI);
//delayVariable = (5000/100);
delayVariable = 100; // change to plot slower or faster
//xVariable = analogRead(scaleXAI);
xVariable = 1; //
TV.select_font(font4x6);
for(yCtr = 0; yCtr < 127; yCtr += 1) // the for loop runs from 0 and < 127, it fills the array with 126 records
{
//if(!(millis() / 1000)) seconds++;
seconds=millis()/1000;
minute=seconds/60;
// check door status
if(digitalRead(RESETBTN))
{
TV.clear_screen();
base_t=seconds;
TV.println(90,10,seconds);
TV.println(90,18,"OPEN ");
cure_t=0;
draw_axis();
goto exit_loop;
}
else
{
TV.println(90,18,"CLOSE");
cure_t=millis()/1000 - base_t;
TV.println(90,2,cure_t/60);
TV.println(90,10,seconds);
}
//posy = analogRead(channelAI); // read the value from the sensor:
temperature = Read_Temperature(); // + temptol;
posy = 120-temperature;
//-------------------------------------------------------------------------------------------------
//check temp here
//
if((cure_t > 60*30) || (cure_t < 60*60)) // check low temp during ramp
{
if(temperature < 100) error_low();
}
if((cure_t > 60*60) || (cure_t < 60*60*2)) // check low temp during soak first hour
{
if(temperature < 175) error_low();
}
if((cure_t > 60*60*2) || (cure_t < 60*60*4)) // check low temp during soak 2, 3, 4 hour
{
if(temperature < 175) error_low();
}
if((cure_t > 60*60*4) || (cure_t < 60*60*5)) // check high temp during cool down
{
if(temperature > 175) error_high();
}
if(temperature > 185) error_high(); // check high temp at any time
//-------------------------------------------------------------------------------------------------
TV.select_font(font4x6);
TV.println(30,2,temperature);
TV.println(50,2,"*C, Cure= m");
myArray[yCtr] = (posy/xVariable); // scale the value based on the x scale potentiometer
delay (delayVariable); // scale the y collection of data using the delay from the y potentiometer
TV.set_pixel(yCtr, myArray[yCtr], 1); // Prepare the 126 pixels
}
yCtr == 0;
TV.clear_screen();
draw_axis();
for(yCtr = 0; yCtr < 127 ; yCtr += 1) // for loop runs 126 times
{
TV.get_pixel(yCtr, myArray[yCtr]); // Output to TV
}
yCtr == 0;
}
void error_low()
{
TV.select_font(font6x8);
TV.println(10,50,"ERROR LOW TEMP ");
digitalWrite(BUZZER,HIGH); // Enable on
while(digitalRead(RESETBTN)){}
}
void error_high()
{
TV.select_font(font6x8);
TV.println(10,50,"ERROR HIGH TEMP");
digitalWrite(BUZZER,HIGH); // Enable on
while(digitalRead(RESETBTN)){}
}
//int Read_time()
//{
// return (millis() );
//}
//int Cure_time()
//{
// return millis()- base_t;
//}
void draw_axis() {
TV.select_font(font4x6);
TV.println(5,2,"Temp= ");
TV.draw_line(2,2,2,96,INVERT);
TV.draw_line(2,94,128,94,INVERT);
TV.draw_line(12,94,12,96,WHITE);
TV.draw_line(12,93,12,96,WHITE);
TV.draw_line(24,93,24,96,WHITE);
TV.draw_line(36,93,36,96,WHITE);
TV.draw_line(48,93,48,96,WHITE);
TV.draw_line(60,93,60,96,WHITE);
TV.draw_line(72,93,72,96,WHITE);
TV.draw_line(84,93,84,96,WHITE);
TV.draw_line(96,93,96,96,WHITE);
TV.draw_line(108,93,108,96,WHITE);
TV.draw_line(128,93,128,96,WHITE);
TV.draw_line(0,10,4,10,WHITE);
TV.draw_line(0,20,4,20,WHITE);
TV.draw_line(0,30,4,30,WHITE);
TV.draw_line(0,40,4,40,WHITE);
TV.draw_line(0,50,4,50,WHITE);
TV.draw_line(0,60,4,60,WHITE);
TV.draw_line(0,70,4,70,WHITE);
TV.draw_line(0,80,4,80,WHITE);
TV.draw_line(0,90,4,90,WHITE);
}
int Read_Temperature() {
int value = 0;
float temp;
int temp_out;
int samples = 10;
float error_tc;
digitalWrite(CS_TEMP,LOW);
delay(2);
digitalWrite(CS_TEMP,HIGH);
delay(220);
for (int i=samples; i>0; i--){
digitalWrite(CS_TEMP,LOW); // Enable device
/* Cycle the clock for dummy bit 15 */
digitalWrite(SCK,HIGH);
delay(1);
digitalWrite(SCK,LOW);
for (int i=11; i>=0; i--){
digitalWrite(SCK,HIGH); // Set Clock to HIGH
value += digitalRead(SO) << i; // Read data and add it to our variable
digitalWrite(SCK,LOW); // Set Clock to LOW
}
/* Read the TC Input inp to check for TC Errors */
digitalWrite(SCK,HIGH); // Set Clock to HIGH
error_tc = digitalRead(SO); // Read data
digitalWrite(SCK,LOW); // Set Clock to LOW
for (int i=1; i>=0; i--) {
digitalWrite(SCK,HIGH);
delay(1);
digitalWrite(SCK,LOW);
}
digitalWrite(CS_TEMP, HIGH); //Disable Device
}
value = value/samples; // Divide the value by the number of samples to get the average
temp = (value*0.25); // Multiply the value by 25 to get temp in [ch730]C
temp_out = temp; // Send the float to an int (X10) for ease of printing.
/* Output 9999 if there is a TC error, otherwise return 'temp' */
if(error_tc != 0) {
return -1;
}
else {
return temp_out;
}
}
No comments:
Post a Comment