ECE4180 Final Project

Dependencies:   4DGL-uLCD-SE DS1820 PinDetect Speaker mbed

Fork of SousVide by Minsuk Chun

Files at this revision

API Documentation at this revision

Comitter:
Mcplokqaws
Date:
Sun Dec 04 23:10:56 2016 +0000
Parent:
0:03ec282c2908
Commit message:
Sous Vide

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
DS1820.lib Show annotated file Show diff for this revision Revisions of this file
DS18B20.cpp Show diff for this revision Revisions of this file
DS18B20.h Show diff for this revision Revisions of this file
DS1Wire.cpp Show diff for this revision Revisions of this file
DS1Wire.h Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
Speaker.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 03ec282c2908 -r 2d86c674a78b 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sun Dec 04 23:10:56 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 03ec282c2908 -r 2d86c674a78b DS1820.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1820.lib	Sun Dec 04 23:10:56 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/DS1820/#196e9e54b033
diff -r 03ec282c2908 -r 2d86c674a78b DS18B20.cpp
--- a/DS18B20.cpp	Fri Jan 29 19:01:56 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-#include "DS18B20.h"
-#include "DS1Wire.h"
-#include "mbed.h"
-#include <stdint.h>
-
-// Device byte commands over 1-wire serial
-enum COMMANDS { READ_ROM = 0x33, CONVERT = 0x44, READ_SCRATCHPAD = 0xBE,  SKIP_ROM = 0xCC };
-
-// device onboard register layout
-typedef struct {
-    uint8_t    LSB;
-    uint8_t    MSB;
-    uint8_t    Th;
-    uint8_t    Tl;
-    uint8_t    config;
-    uint8_t    reserved0xFF;
-    uint8_t    reserved0xCH;
-    uint8_t    reserved0x10;
-    uint8_t    CRC;
-} ScratchPad_t;
-
-
-DigitalOut conversionInProgress(LED4);  // conversion in progress
-DigitalOut resetFailure(LED1);          // for error reporting
-extern DigitalInOut sensor;     // sensor pin
-
-static void inError() {
-    while (1) {
-        resetFailure = !resetFailure;
-        wait(0.2);
-    }
-}
-
-void DoConversion() {
-    if (Reset(sensor) != 0) {
-        inError();
-    } else {
-        conversionInProgress = 1;       // led on
-        WriteByte(sensor, SKIP_ROM);            // Skip ROM
-        WriteByte(sensor, CONVERT);             // Convert
-        while (ReadBit(sensor) == 0) {
-            // wait for conversion to complete
-        }
-        conversionInProgress = 0;       // led off
-    }
-}
-
-uint32_t GetTemperature() {
-    uint32_t result = 0;
-    if (Reset(sensor) != 0) {
-        inError();
-    } else {
-        ScratchPad_t scratchpad;
-        WriteByte(sensor, SKIP_ROM);    // Skip ROM
-        WriteByte(sensor, READ_SCRATCHPAD);    // Read Scrachpad
-        scratchpad.LSB = ReadByte(sensor);
-        scratchpad.MSB = ReadByte(sensor);
-        Reset(sensor);    // terminate read as we only want temperature
-        result = ((scratchpad.MSB << 8) | scratchpad.LSB);
-    }
-    return result;
-}
-
-ROM_Code_t ReadROM() {
-    ROM_Code_t ROM_Code;
-    if (Reset(sensor) != 0) {
-        inError();
-    } else {
-        
-        WriteByte(sensor, READ_ROM);    // Read ROM
-        for (uint32_t i = 0; i < 8; ++i) {
-            ROM_Code.rom[i] = ReadByte(sensor);
-        }
-    }
-    return ROM_Code;
-}
-
-// temperature is store as 7.4 fixed point format (assuming 12 bit conversion)
-void displayTemperature(Serial& s) {
-    DoConversion();
-    uint32_t temp = GetTemperature();
-    float f = (temp & 0x0F) * 0.0625;    // calculate .4 part
-    f += (temp >> 4);    // add 7.0 part to it
-    s.printf("Temp is %2.1fC\n\r", f);    // display in 2.1 format
-}
-
diff -r 03ec282c2908 -r 2d86c674a78b DS18B20.h
--- a/DS18B20.h	Fri Jan 29 19:01:56 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef _DS18B20_
-#define _DS18B20_
-
-#include <stdint.h>
-#include "mbed.h"
-
-// Device Faimly ID and Setial number information
-typedef union {
-    uint8_t rom[8];
-    struct {
-        uint8_t    familyCode;
-        uint8_t    serialNo[6];
-        uint8_t    CRC;
-    } BYTES;
-} ROM_Code_t;
-
-ROM_Code_t ReadROM() ;
-
-// temperature is store as 7.4 fixed point format (assuming 12 bit conversion)
-void displayTemperature(Serial& s) ;
-
-#endif
\ No newline at end of file
diff -r 03ec282c2908 -r 2d86c674a78b DS1Wire.cpp
--- a/DS1Wire.cpp	Fri Jan 29 19:01:56 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#include "DS1Wire.h"
-#include "mbed.h"
-#include <stdint.h>
-
-// Timing delay for 1-wire serial standard option
-enum DELAY { A = 6, B = 64, C = 60, D = 10, E = 9, F = 55, G = 0, H = 480, I = 70, J = 410 };
-
-   
-int Reset(DigitalInOut& pin) {
-    pin.output();
-    pin = 0;    // drive bus low
-    wait_us(H);
-    pin.input(); // release bus
-    wait_us(I);
-    uint32_t result = pin;  // read bus value
-    wait_us(J);
-    return result;
-}
-
-void WriteBit(DigitalInOut& pin, uint32_t bit) {
-    pin.output();
-    if (bit) {
-        pin = 0;        // drive bus low
-        wait_us(A);        // delay A
-        pin.input();      // release bus
-        wait_us(B);        // delay B
-    } else {
-        pin = 0;    // drive bus low
-        wait_us(C);    // delay C
-        pin.input();  // release bus
-        wait_us(D);    // delay D
-    }
-}
-
-uint32_t ReadBit(DigitalInOut& pin) {
-    uint32_t bit_value;
-    pin.output();
-    pin = 0;        // drive bus low
-    wait_us(A);        // delay A
-    pin.input();      // release bus
-    wait_us(E);        // delay E
-    bit_value  = pin;    // master sample bus
-    wait_us(F);
-    return bit_value;
-}
-
-void WriteByte(DigitalInOut& pin, uint32_t byte) {
-    for (uint32_t bit = 0; bit < 8; ++bit) {
-        WriteBit(pin, byte & 0x01); // lsb to msb
-        byte >>= 1;    // right shift by 1-bit
-    }
-}
-
-uint32_t ReadByte(DigitalInOut& pin) {
-    uint32_t byte = 0;
-    for (uint32_t bit = 0; bit < 8; ++bit) {
-        byte |= (ReadBit(pin) << bit);    // Reads lsb to msb
-    }
-    return byte;
-}
\ No newline at end of file
diff -r 03ec282c2908 -r 2d86c674a78b DS1Wire.h
--- a/DS1Wire.h	Fri Jan 29 19:01:56 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#ifndef __DS_1_WIRE__
-#define __DS_1_WIRE__
-#include <stdint.h>
-#include "mbed.h"
-
-int Reset(DigitalInOut& pin);
-
-void WriteBit(DigitalInOut& pin, uint32_t bit);
-uint32_t ReadBit(DigitalInOut& pin);
-
-void WriteByte(DigitalInOut& pin, uint32_t byte);
-uint32_t ReadByte(DigitalInOut& pin);
-
-
-#endif
\ No newline at end of file
diff -r 03ec282c2908 -r 2d86c674a78b PinDetect.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Sun Dec 04 23:10:56 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 03ec282c2908 -r 2d86c674a78b Speaker.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.lib	Sun Dec 04 23:10:56 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/zchen311/code/Speaker/#41292907c9cb
diff -r 03ec282c2908 -r 2d86c674a78b main.cpp
--- a/main.cpp	Fri Jan 29 19:01:56 2010 +0000
+++ b/main.cpp	Sun Dec 04 23:10:56 2016 +0000
@@ -1,29 +1,207 @@
 #include "mbed.h"
-#include <stdint.h>
-#include "DS18B20.h"
+#include "uLCD_4DGL.h"
+#include "Speaker.h"
+#include "DS1820.h"
+#include "PinDetect.h"
+#include <time.h>
+
+//Program by: Tianhang Ren, Minsuk Chun, Richard Lee
+
+////////////////////////////////////////////////////////
+//Initialize
+///////////////////////////////////////////////////////
 
-DigitalInOut sensor(p5);     // sensor connected to pin 5
+DS1820 probe(p5);
+PinDetect pbUp(p18);          // Buttons to raise/lower/enter temperature
+PinDetect pbDown(p19);
+PinDetect pbEnter (p20);
+Serial pc(USBTX, USBRX);     // serial comms over usb back to console
+//Timer T;
+DigitalOut myled1(LED1);       // On when relay is engaged
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object
 
-Ticker timer;                // used for our microsec timing
-Serial pc(USBTX, USBRX);     // serial comms over usb back to console
+DigitalOut ctrl(p8); //relay control
+
+// setup instance of new Speaker class, mySpeaker using pin 21
+// the pin must be a PWM output pin
+Speaker mySpeaker(p26);
+
+float userTemp = 0; //user desired temperature of device
+int check = 0; //indicates whether enter key is pressed
+float timeCook = 0;
+
 
-int main() {
-    pc.printf("\n\r=====================================================\n\r");
-    pc.printf("DS18B20 Configuration\n\r");
-    sensor.mode(PullUp);
-    
-    ROM_Code_t ROM_Code = ReadROM();
-    pc.printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode);
-    pc.printf("Serial Number: ");
-    for (uint32_t i = 6; i != 0; --i) {
-        pc.printf("%02X%s", ROM_Code.BYTES.serialNo[i-1], (i != 1)?":":"\r\n");
+////////////////////////////////////////////////////////
+// Initialize pushbuttons
+///////////////////////////////////////////////////////
+
+
+// Callback routine is interrupt activated by a debounced pb1 hit
+void pbUp_hit_callback (void)
+{
+    // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED
+    myled1 = !myled1;
+    mySpeaker.PlayNote(200.0,0.25,0.1);
+    userTemp++;
+    timeCook +=5; //TODO CHANGE TIME BACK TO 10 INTERVALS
+}
+
+// Callback routine is interrupt activated by a debounced pb2 hit
+void pbDown_hit_callback (void)
+{
+    // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED
+    myled2 = !myled2;
+    mySpeaker.PlayNote(400.0,0.25,0.1);
+    userTemp--;
+    if (userTemp <=0) {
+        userTemp = 0;
     }
-    pc.printf("CRC: 0x%X\r\n", ROM_Code.BYTES.CRC);
-    
-    pc.printf("\n\rRunning temperature conversion...\n\r");
-    while (1) {
-        displayTemperature(pc);
-        wait(10);
-    }
+    timeCook-=5;
+    if (timeCook <=0)
+        timeCook=0;
+}
+// Callback routine is interrupt activated by a debounced pb3 hit
+void pbEnter_hit_callback (void)
+{
+    // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED
+    myled3 = !myled3;
+    mySpeaker.PlayNote(800.0,0.10,0.1);
+    mySpeaker.PlayNote(1000.0,0.10,0.1);
+    mySpeaker.PlayNote(1200.0,0.10,0.1);
+    check++;
 }
 
+////////////////////////////////////////////////////////
+// Main method starts here
+////////////////////////////////////////////////////////
+
+int main()
+{
+//setup three SPST push buttons
+    pbUp.mode(PullUp); //add internal pullup resistor
+    pbDown.mode(PullUp);
+    pbEnter.mode(PullUp);
+
+// Delay for initial pullup to take effect
+    wait(.01);
+
+// Setup Interrupt callback functions for a pb hit
+    pbUp.attach_deasserted(&pbUp_hit_callback);
+    pbDown.attach_deasserted(&pbDown_hit_callback);
+    pbEnter.attach_deasserted(&pbEnter_hit_callback);
+
+// Start sampling pb inputs using interrupts
+    pbUp.setSampleFrequency();
+    pbDown.setSampleFrequency();
+    pbEnter.setSampleFrequency();
+
+// pushbuttons now setup and running
+
+////////////////////////////////////////////////////////
+// Ask for temperature and time desired
+////////////////////////////////////////////////////////
+
+    uLCD.printf("Enter desired temperature"); //Ask for desired temperature
+    while(check ==0) { //if check flag is 0, means enter has not been pushed
+        if (pbUp) {
+            uLCD.locate(0,3);
+            uLCD.printf("%4.0f", userTemp);
+        }
+        if (pbDown) {
+            uLCD.locate(0,3);
+            uLCD.printf("%4.0f", userTemp);
+        }
+    }
+
+    float finalTemp = userTemp; //reassign to final temp
+    check = 0;
+    uLCD.cls();
+    uLCD.locate(0,0);
+    timeCook = 0; //reset timeCook
+    uLCD.printf("Enter cooking time"); //Cooking time in minutes
+    while (check == 0) {
+        if (pbUp) {
+            uLCD.locate(0,3);
+            uLCD.printf("%4.0f", timeCook);
+        }
+        if (pbDown) {
+            uLCD.locate(0,3);
+            uLCD.printf("%4.0f", timeCook);
+        }
+    }
+    float finalTime = timeCook *60; //reassign to final time
+    ctrl = 1;                   // Turn on relay
+    float tempLimit = 0;        //intitialize variable to track temperature
+    uLCD.locate(0,0);
+    uLCD.printf("Set Temp (C)", finalTemp);  //print set temperature
+    while (tempLimit < (finalTemp + 1)) {       //Loop while temperature is 1 degrees over destination
+        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
+        tempLimit = probe.temperature();
+        uLCD.locate(0,3);
+        uLCD.printf("It is %3.1foC\r", probe.temperature());
+        wait(1);
+    }
+////////////////////////////////////////////////////////
+// Start cooking with finalized temperatures and time
+////////////////////////////////////////////////////////
+
+    //PLAY SOUND FROM SPEAKER
+    /*    T.start();  //Timer start (s)*/
+    float time_remaining = 1;
+    ctrl = 0;
+    uLCD.cls();
+    uLCD.locate(0,0);
+    uLCD.printf("Set Temperature %4.0foC\r", finalTemp);
+    set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
+    // time_t seconds = time(NULL);
+
+    while(time_remaining > 0) { //Loop while timer has not reached desired time
+        if (tempLimit < (finalTemp - 1)) { //If temperature is 2 degrees C lower than desired, turn relay on
+            ctrl = 1;
+        } else if (tempLimit >= finalTemp) {
+            ctrl = 0;
+        }
+        tempLimit = probe.temperature();
+        probe.convertTemperature(true, DS1820::all_devices);        //Start temperature conversion, wait until ready
+        uLCD.locate(0,3);
+        uLCD.printf("It is %3.1foC\r", probe.temperature());
+        uLCD.locate(0,5);
+        time_t seconds = time(NULL); //Cycle RTC
+        time_remaining = finalTime - (seconds - 1256729737);
+
+        if ((time_remaining/3600) >= 1 )
+            uLCD.printf("Time remaining: \n%4.0f hours", time_remaining/3600);
+        else if ((time_remaining/60) >= 1)
+            uLCD.printf("Time remaining: %4.0f minutes", time_remaining/60);
+        else
+            uLCD.printf("Time remaining: %4.0f seconds", time_remaining);
+    }
+
+    ctrl = 0;
+    
+    //PLAY SOUND FROM SPEAKER
+    mySpeaker.PlayNote(1567.98,0.25,0.1);
+    mySpeaker.PlayNote(1046.50,0.25,0.1);
+    mySpeaker.PlayNote(1174.66,0.25,0.1);
+    mySpeaker.PlayNote(1318.51,0.25,0.1);
+    mySpeaker.PlayNote(1396.91,0.25,0.1);
+    mySpeaker.PlayNote(1567.98,0.25,0.1);
+    mySpeaker.PlayNote(1046.50,0.25,0.1);
+    mySpeaker.PlayNote(1046.50,0.25,0.1);
+    mySpeaker.PlayNote(1760.00,0.25,0.1);
+    mySpeaker.PlayNote(1396.91,0.25,0.1);
+    mySpeaker.PlayNote(1567.98,0.25,0.1);
+    mySpeaker.PlayNote(1760.00,0.25,0.1);
+    mySpeaker.PlayNote(1975.53,0.25,0.1);
+    mySpeaker.PlayNote(2093.00,0.25,0.1);
+    mySpeaker.PlayNote(1046.50,0.25,0.1);
+    mySpeaker.PlayNote(1046.50,0.25,0.1);
+    
+    uLCD.cls();
+    uLCD.locate(0,0);
+    uLCD.printf("Food is ready");
+}
+