Project

Dependencies:   4DGL-uLCD-SE MAX31855 mbed-rtos mbed

Fork of Coffee_Roaster by Eric Patterson

Committer:
ericspatterson
Date:
Wed Nov 12 18:56:57 2014 +0000
Revision:
0:4fbaafa6574c
Child:
1:26267401354a
First Publish..Need to work on Touch Panel controls and get motor controlled with SSR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ericspatterson 0:4fbaafa6574c 1 #include "mbed.h"
ericspatterson 0:4fbaafa6574c 2 #include "uLCD_4DGL.h"
ericspatterson 0:4fbaafa6574c 3 #include "rtos.h"
ericspatterson 0:4fbaafa6574c 4 #include "stdio.h"
ericspatterson 0:4fbaafa6574c 5 #include "max31855.h"
ericspatterson 0:4fbaafa6574c 6
ericspatterson 0:4fbaafa6574c 7 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
ericspatterson 0:4fbaafa6574c 8 SPI thermoSPI(p5,p6,p7); // setup SPI interface
ericspatterson 0:4fbaafa6574c 9 max31855 max1(thermoSPI, p20); //setup max31855 interface
ericspatterson 0:4fbaafa6574c 10 Mutex lcd_mutex; // mutex to make the lcd lib thread safe
ericspatterson 0:4fbaafa6574c 11 Semaphore four_slots(1); //Activate semaphore
ericspatterson 0:4fbaafa6574c 12 DigitalOut toggle(p30);
ericspatterson 0:4fbaafa6574c 13 DigitalIn up(p19);
ericspatterson 0:4fbaafa6574c 14 DigitalIn down(p18);
ericspatterson 0:4fbaafa6574c 15
ericspatterson 0:4fbaafa6574c 16 int settemp = 75;
ericspatterson 0:4fbaafa6574c 17
ericspatterson 0:4fbaafa6574c 18 float ftemperature = 0; // float variable for temperature
ericspatterson 0:4fbaafa6574c 19 float ctemperature = 0; // float variable for temperature
ericspatterson 0:4fbaafa6574c 20
ericspatterson 0:4fbaafa6574c 21 // Thread t1
ericspatterson 0:4fbaafa6574c 22 // print the elapsed time on line 1 of the uLCD (i.e., HH:MM:SS)
ericspatterson 0:4fbaafa6574c 23 void elapsedtime(void const *args) { //line 2
ericspatterson 0:4fbaafa6574c 24 int s = 00;
ericspatterson 0:4fbaafa6574c 25 int m = 00;
ericspatterson 0:4fbaafa6574c 26 int h = 00;
ericspatterson 0:4fbaafa6574c 27
ericspatterson 0:4fbaafa6574c 28 while(true){
ericspatterson 0:4fbaafa6574c 29 s++;
ericspatterson 0:4fbaafa6574c 30 if(s>59){
ericspatterson 0:4fbaafa6574c 31 s=00;
ericspatterson 0:4fbaafa6574c 32 m++;
ericspatterson 0:4fbaafa6574c 33 }
ericspatterson 0:4fbaafa6574c 34 if(m>59){
ericspatterson 0:4fbaafa6574c 35 m=00;
ericspatterson 0:4fbaafa6574c 36 h++;
ericspatterson 0:4fbaafa6574c 37 }
ericspatterson 0:4fbaafa6574c 38 four_slots.wait();
ericspatterson 0:4fbaafa6574c 39 //lcd_mutex.lock();
ericspatterson 0:4fbaafa6574c 40 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 41 uLCD.locate(0,0); //col,row
ericspatterson 0:4fbaafa6574c 42 wait(0.1);
ericspatterson 0:4fbaafa6574c 43 uLCD.printf("ET: %2d:%2d:%2d", h,m,s);
ericspatterson 0:4fbaafa6574c 44 //lcd_mutex.unlock();
ericspatterson 0:4fbaafa6574c 45 four_slots.release();
ericspatterson 0:4fbaafa6574c 46 Thread::wait(1000); // update once per secon
ericspatterson 0:4fbaafa6574c 47 }
ericspatterson 0:4fbaafa6574c 48 }
ericspatterson 0:4fbaafa6574c 49
ericspatterson 0:4fbaafa6574c 50
ericspatterson 0:4fbaafa6574c 51 // Thread t2
ericspatterson 0:4fbaafa6574c 52 // print the temperature from the thermocouple - MAX31855 device
ericspatterson 0:4fbaafa6574c 53 void thermoread(void const *args) { //line 2
ericspatterson 0:4fbaafa6574c 54
ericspatterson 0:4fbaafa6574c 55
ericspatterson 0:4fbaafa6574c 56 while(true){
ericspatterson 0:4fbaafa6574c 57 if (max1.ready()==1){
ericspatterson 0:4fbaafa6574c 58 ctemperature = max1.read_temp(); //Get the reading
ericspatterson 0:4fbaafa6574c 59 ftemperature = (ctemperature)*(9.0/5.0)+32.0;
ericspatterson 0:4fbaafa6574c 60 four_slots.wait();
ericspatterson 0:4fbaafa6574c 61 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 62 uLCD.locate(0,2); //col,row
ericspatterson 0:4fbaafa6574c 63 wait(0.1);
ericspatterson 0:4fbaafa6574c 64 uLCD.printf("Current Temp. F");
ericspatterson 0:4fbaafa6574c 65 uLCD.locate(0,3); //col,row
ericspatterson 0:4fbaafa6574c 66 uLCD.printf("%4.2f", ftemperature);
ericspatterson 0:4fbaafa6574c 67
ericspatterson 0:4fbaafa6574c 68 //uLCD.locate(0,5); //col,row
ericspatterson 0:4fbaafa6574c 69 // uLCD.printf("Set Temp. F");
ericspatterson 0:4fbaafa6574c 70 // uLCD.locate(0,6); //col,row
ericspatterson 0:4fbaafa6574c 71 // uLCD.printf("%d",settemp);
ericspatterson 0:4fbaafa6574c 72
ericspatterson 0:4fbaafa6574c 73 four_slots.release();
ericspatterson 0:4fbaafa6574c 74 }
ericspatterson 0:4fbaafa6574c 75 }
ericspatterson 0:4fbaafa6574c 76 }
ericspatterson 0:4fbaafa6574c 77
ericspatterson 0:4fbaafa6574c 78
ericspatterson 0:4fbaafa6574c 79 void thermoset (void const *args) { //line 2
ericspatterson 0:4fbaafa6574c 80 while(true){
ericspatterson 0:4fbaafa6574c 81 if (up==1){
ericspatterson 0:4fbaafa6574c 82 settemp += 1;
ericspatterson 0:4fbaafa6574c 83 four_slots.wait();
ericspatterson 0:4fbaafa6574c 84 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 85 uLCD.locate(0,5); //col,row
ericspatterson 0:4fbaafa6574c 86 uLCD.printf("Set Temp. F");
ericspatterson 0:4fbaafa6574c 87 uLCD.locate(0,6); //col,row
ericspatterson 0:4fbaafa6574c 88 uLCD.printf("%d",settemp);
ericspatterson 0:4fbaafa6574c 89 four_slots.release();
ericspatterson 0:4fbaafa6574c 90 wait(.5);
ericspatterson 0:4fbaafa6574c 91 }
ericspatterson 0:4fbaafa6574c 92 if (down==1){
ericspatterson 0:4fbaafa6574c 93 settemp -= 1;
ericspatterson 0:4fbaafa6574c 94 four_slots.wait();
ericspatterson 0:4fbaafa6574c 95 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 96 uLCD.locate(0,5); //col,row
ericspatterson 0:4fbaafa6574c 97 uLCD.printf("Set Temp. F");
ericspatterson 0:4fbaafa6574c 98 uLCD.locate(0,6); //col,row
ericspatterson 0:4fbaafa6574c 99 uLCD.printf("%d",settemp);
ericspatterson 0:4fbaafa6574c 100 four_slots.release();
ericspatterson 0:4fbaafa6574c 101 wait(.5);
ericspatterson 0:4fbaafa6574c 102 }
ericspatterson 0:4fbaafa6574c 103 }
ericspatterson 0:4fbaafa6574c 104 }
ericspatterson 0:4fbaafa6574c 105
ericspatterson 0:4fbaafa6574c 106
ericspatterson 0:4fbaafa6574c 107
ericspatterson 0:4fbaafa6574c 108 int main() {
ericspatterson 0:4fbaafa6574c 109 max1.initialise(); //initialize thermocouple IC
ericspatterson 0:4fbaafa6574c 110 uLCD.baudrate(3000000); //set LCD baudrate
ericspatterson 0:4fbaafa6574c 111 Thread t1(elapsedtime); //run elapsed time counter
ericspatterson 0:4fbaafa6574c 112 Thread t2(thermoread); //read and display temperature from thermocouple
ericspatterson 0:4fbaafa6574c 113 Thread t3(thermoset);
ericspatterson 0:4fbaafa6574c 114
ericspatterson 0:4fbaafa6574c 115
ericspatterson 0:4fbaafa6574c 116 while(1){ //While so program doesn't end
ericspatterson 0:4fbaafa6574c 117 if(ftemperature < settemp-1){
ericspatterson 0:4fbaafa6574c 118 toggle=1; //turn on ssr
ericspatterson 0:4fbaafa6574c 119 }
ericspatterson 0:4fbaafa6574c 120 if(ftemperature > settemp+1){
ericspatterson 0:4fbaafa6574c 121 toggle=0;
ericspatterson 0:4fbaafa6574c 122 }
ericspatterson 0:4fbaafa6574c 123 wait(1);
ericspatterson 0:4fbaafa6574c 124 }
ericspatterson 0:4fbaafa6574c 125 }