Working better. Maybe a little more improvement needs to be made to the display algorithm.

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

Fork of Coffee_Roaster_testing by Eric Patterson

Committer:
ericspatterson
Date:
Thu Nov 13 01:21:06 2014 +0000
Revision:
2:c94244d1cab4
Parent:
1:26267401354a
Child:
3:0f0e79eff4a7
Touch Panel Working, but a bit buggy

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 2:c94244d1cab4 6 #include <mpr121.h>
ericspatterson 2:c94244d1cab4 7
ericspatterson 2:c94244d1cab4 8 DigitalOut led1(LED1);
ericspatterson 2:c94244d1cab4 9 DigitalOut led2(LED2);
ericspatterson 2:c94244d1cab4 10 DigitalOut led3(LED3);
ericspatterson 2:c94244d1cab4 11 DigitalOut led4(LED4);
ericspatterson 0:4fbaafa6574c 12
ericspatterson 0:4fbaafa6574c 13 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
ericspatterson 0:4fbaafa6574c 14 SPI thermoSPI(p5,p6,p7); // setup SPI interface
ericspatterson 0:4fbaafa6574c 15 max31855 max1(thermoSPI, p20); //setup max31855 interface
ericspatterson 0:4fbaafa6574c 16 Mutex lcd_mutex; // mutex to make the lcd lib thread safe
ericspatterson 0:4fbaafa6574c 17 Semaphore four_slots(1); //Activate semaphore
ericspatterson 1:26267401354a 18 DigitalOut toggle(p30); // toggle for Nichrome wire SSR
ericspatterson 1:26267401354a 19 DigitalIn up(p19); // User pushbutton up controller
ericspatterson 1:26267401354a 20 DigitalIn down(p18); // User pushbutton down button controller
ericspatterson 0:4fbaafa6574c 21
ericspatterson 2:c94244d1cab4 22 int settemp = 85; // initial temperature set
ericspatterson 0:4fbaafa6574c 23 float ftemperature = 0; // float variable for temperature
ericspatterson 0:4fbaafa6574c 24 float ctemperature = 0; // float variable for temperature
ericspatterson 0:4fbaafa6574c 25
ericspatterson 2:c94244d1cab4 26 int key_code=0;
ericspatterson 2:c94244d1cab4 27
ericspatterson 2:c94244d1cab4 28 // Create the interrupt receiver object on pin 26
ericspatterson 2:c94244d1cab4 29 InterruptIn interrupt(p26);
ericspatterson 2:c94244d1cab4 30
ericspatterson 2:c94244d1cab4 31 // Setup the i2c bus on pins 28 and 27
ericspatterson 2:c94244d1cab4 32 I2C i2c(p28, p27);
ericspatterson 2:c94244d1cab4 33
ericspatterson 2:c94244d1cab4 34 // Setup the Mpr121:
ericspatterson 2:c94244d1cab4 35 // constructor(i2c object, i2c address of the mpr121)
ericspatterson 2:c94244d1cab4 36 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
ericspatterson 2:c94244d1cab4 37
ericspatterson 1:26267401354a 38 // Thread 1: print the elapsed time on line 1 of the uLCD (i.e., HH:MM:SS)
ericspatterson 1:26267401354a 39 void elapsedtime(void const *args) { //elapsed timer for when program starts
ericspatterson 1:26267401354a 40 int s = 00; //seconds
ericspatterson 1:26267401354a 41 int m = 00; //minutes
ericspatterson 1:26267401354a 42 int h = 00; //hours
ericspatterson 0:4fbaafa6574c 43
ericspatterson 0:4fbaafa6574c 44 while(true){
ericspatterson 1:26267401354a 45 s++;
ericspatterson 0:4fbaafa6574c 46 if(s>59){
ericspatterson 0:4fbaafa6574c 47 s=00;
ericspatterson 0:4fbaafa6574c 48 m++;
ericspatterson 0:4fbaafa6574c 49 }
ericspatterson 0:4fbaafa6574c 50 if(m>59){
ericspatterson 0:4fbaafa6574c 51 m=00;
ericspatterson 0:4fbaafa6574c 52 h++;
ericspatterson 0:4fbaafa6574c 53 }
ericspatterson 1:26267401354a 54 four_slots.wait(); // lock screen resource
ericspatterson 0:4fbaafa6574c 55 //lcd_mutex.lock();
ericspatterson 1:26267401354a 56 uLCD.color(0xFFFF00); //set text color
ericspatterson 1:26267401354a 57 uLCD.locate(0,0); //col,row location of text
ericspatterson 1:26267401354a 58 wait(0.1);
ericspatterson 1:26267401354a 59 uLCD.printf("ET: %2d:%2d:%2d", h,m,s); // display time
ericspatterson 0:4fbaafa6574c 60 //lcd_mutex.unlock();
ericspatterson 1:26267401354a 61 four_slots.release(); //unlock screen resource
ericspatterson 0:4fbaafa6574c 62 Thread::wait(1000); // update once per secon
ericspatterson 0:4fbaafa6574c 63 }
ericspatterson 0:4fbaafa6574c 64 }
ericspatterson 0:4fbaafa6574c 65
ericspatterson 0:4fbaafa6574c 66
ericspatterson 1:26267401354a 67 // Thread 2: print the temperature from the thermocouple - MAX31855 device
ericspatterson 0:4fbaafa6574c 68 void thermoread(void const *args) { //line 2
ericspatterson 0:4fbaafa6574c 69 while(true){
ericspatterson 0:4fbaafa6574c 70 if (max1.ready()==1){
ericspatterson 0:4fbaafa6574c 71 ctemperature = max1.read_temp(); //Get the reading
ericspatterson 0:4fbaafa6574c 72 ftemperature = (ctemperature)*(9.0/5.0)+32.0;
ericspatterson 0:4fbaafa6574c 73 four_slots.wait();
ericspatterson 0:4fbaafa6574c 74 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 75 uLCD.locate(0,2); //col,row
ericspatterson 0:4fbaafa6574c 76 wait(0.1);
ericspatterson 0:4fbaafa6574c 77 uLCD.printf("Current Temp. F");
ericspatterson 0:4fbaafa6574c 78 uLCD.locate(0,3); //col,row
ericspatterson 0:4fbaafa6574c 79 uLCD.printf("%4.2f", ftemperature);
ericspatterson 0:4fbaafa6574c 80 four_slots.release();
ericspatterson 0:4fbaafa6574c 81 }
ericspatterson 0:4fbaafa6574c 82 }
ericspatterson 0:4fbaafa6574c 83 }
ericspatterson 0:4fbaafa6574c 84
ericspatterson 2:c94244d1cab4 85
ericspatterson 2:c94244d1cab4 86 void fallInterrupt() {
ericspatterson 2:c94244d1cab4 87 int i=0;
ericspatterson 2:c94244d1cab4 88 int value=mpr121.read(0x00);
ericspatterson 2:c94244d1cab4 89 value +=mpr121.read(0x01)<<8;
ericspatterson 2:c94244d1cab4 90 // LED demo mod
ericspatterson 2:c94244d1cab4 91 i=0;
ericspatterson 2:c94244d1cab4 92 // puts key number out to LEDs for demo
ericspatterson 2:c94244d1cab4 93 for (i=0; i<12; i++) {
ericspatterson 2:c94244d1cab4 94 if (((value>>i)&0x01)==1) key_code=i+1;
ericspatterson 2:c94244d1cab4 95 }
ericspatterson 2:c94244d1cab4 96 led4=key_code & 0x01;
ericspatterson 2:c94244d1cab4 97 led3=(key_code>>1) & 0x01;
ericspatterson 2:c94244d1cab4 98 led2=(key_code>>2) & 0x01;
ericspatterson 2:c94244d1cab4 99 led1=(key_code>>3) & 0x01;
ericspatterson 2:c94244d1cab4 100 }
ericspatterson 2:c94244d1cab4 101
ericspatterson 2:c94244d1cab4 102
ericspatterson 2:c94244d1cab4 103 int main() {
ericspatterson 2:c94244d1cab4 104 max1.initialise(); //initialize thermocouple IC
ericspatterson 2:c94244d1cab4 105 uLCD.baudrate(3000000); //set LCD baudrate
ericspatterson 2:c94244d1cab4 106
ericspatterson 2:c94244d1cab4 107 interrupt.fall(&fallInterrupt);
ericspatterson 2:c94244d1cab4 108 interrupt.mode(PullUp);
ericspatterson 2:c94244d1cab4 109
ericspatterson 2:c94244d1cab4 110 Thread t1(elapsedtime); //run elapsed time counter
ericspatterson 2:c94244d1cab4 111 Thread t2(thermoread); //read and display temperature from thermocouple
ericspatterson 2:c94244d1cab4 112
ericspatterson 2:c94244d1cab4 113 while(1){ //hystersis program
ericspatterson 2:c94244d1cab4 114 key_code = 0;
ericspatterson 2:c94244d1cab4 115 four_slots.wait();
ericspatterson 2:c94244d1cab4 116 uLCD.color(0xFFFF00);
ericspatterson 2:c94244d1cab4 117 uLCD.locate(0,10); //col,row
ericspatterson 2:c94244d1cab4 118 //wait(0.1);
ericspatterson 2:c94244d1cab4 119 uLCD.printf("Test.");
ericspatterson 2:c94244d1cab4 120 uLCD.locate(0,11); //col,row
ericspatterson 2:c94244d1cab4 121 uLCD.printf("%2d", key_code);
ericspatterson 2:c94244d1cab4 122 four_slots.release();
ericspatterson 2:c94244d1cab4 123
ericspatterson 2:c94244d1cab4 124 if (key_code == 1){
ericspatterson 0:4fbaafa6574c 125 settemp += 1;
ericspatterson 0:4fbaafa6574c 126 four_slots.wait();
ericspatterson 0:4fbaafa6574c 127 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 128 uLCD.locate(0,5); //col,row
ericspatterson 0:4fbaafa6574c 129 uLCD.printf("Set Temp. F");
ericspatterson 0:4fbaafa6574c 130 uLCD.locate(0,6); //col,row
ericspatterson 0:4fbaafa6574c 131 uLCD.printf("%d",settemp);
ericspatterson 0:4fbaafa6574c 132 four_slots.release();
ericspatterson 2:c94244d1cab4 133 //wait(.5);
ericspatterson 0:4fbaafa6574c 134 }
ericspatterson 2:c94244d1cab4 135 if (key_code== 2){
ericspatterson 0:4fbaafa6574c 136 settemp -= 1;
ericspatterson 0:4fbaafa6574c 137 four_slots.wait();
ericspatterson 0:4fbaafa6574c 138 uLCD.color(0xFFFF00);
ericspatterson 0:4fbaafa6574c 139 uLCD.locate(0,5); //col,row
ericspatterson 0:4fbaafa6574c 140 uLCD.printf("Set Temp. F");
ericspatterson 0:4fbaafa6574c 141 uLCD.locate(0,6); //col,row
ericspatterson 0:4fbaafa6574c 142 uLCD.printf("%d",settemp);
ericspatterson 0:4fbaafa6574c 143 four_slots.release();
ericspatterson 2:c94244d1cab4 144 //wait(.5);
ericspatterson 0:4fbaafa6574c 145 }
ericspatterson 2:c94244d1cab4 146
ericspatterson 2:c94244d1cab4 147 if(ftemperature < settemp-1){ //condition for 1 degree under
ericspatterson 2:c94244d1cab4 148 toggle=1; //turn on ssr for nichrome wire
ericspatterson 2:c94244d1cab4 149 }
ericspatterson 2:c94244d1cab4 150 if(ftemperature > settemp+1){ //condition for 1 degree over
ericspatterson 2:c94244d1cab4 151 toggle=0; //turn off ssr for nichrome wire
ericspatterson 2:c94244d1cab4 152 }
ericspatterson 2:c94244d1cab4 153 // wait(.1); //check every 1 second
ericspatterson 0:4fbaafa6574c 154 }
ericspatterson 0:4fbaafa6574c 155 }