Example project for the Rioux Chem control box

Dependencies:   mbed MODSERIAL

Dependents:   screentest

Rioux Chem Control Box

/media/uploads/emh203/ccb.jpg

This is the example project for the Rioux Chem Control Box. I have posted some youtube videos to guide you through the hardware and software:

Rioux Chem Control Box - Hardware

http://www.youtube.com/watch?v=MoZ92GRYa4s

Rioux Chem Control Box - Software - Part I

http://www.youtube.com/watch?v=_MwaTLL4dyA==

Rioux Chem Control Box - Software - Part II

http://www.youtube.com/watch?v=j_P89izfgoQ

Committer:
wavenumber
Date:
Mon Aug 31 13:00:37 2020 +0000
Revision:
2:73a028278c5c
Parent:
0:7798270c1f52
Child:
3:cb48919cd5e8
Fixed issue with Thermocouple bit masking.  Added Echo off command

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emh203 0:7798270c1f52 1 #include "mbed.h"
emh203 0:7798270c1f52 2 #include "CHEM_BOX_INTERFACE.h"
emh203 0:7798270c1f52 3
emh203 0:7798270c1f52 4 Timer ControlLoopTimer;
emh203 0:7798270c1f52 5 float CurrentTemperature;
emh203 0:7798270c1f52 6
wavenumber 2:73a028278c5c 7 #define VT100_RED "\033[31;40m"
wavenumber 2:73a028278c5c 8 #define VT100_GREEN "\033[32;40m"
wavenumber 2:73a028278c5c 9 #define VT100_YELLOW "\033[33;40m"
wavenumber 2:73a028278c5c 10 #define VT100_BLUE "\033[34;40m"
wavenumber 2:73a028278c5c 11 #define VT100_MAGENTA "\033[35;40m"
wavenumber 2:73a028278c5c 12 #define VT100_CYAN "\033[36;40m"
wavenumber 2:73a028278c5c 13 #define VT100_WHITE "\033[37;40m"
wavenumber 2:73a028278c5c 14 #define VT100_RESET "\033c"
wavenumber 2:73a028278c5c 15
emh203 0:7798270c1f52 16
emh203 0:7798270c1f52 17 int main()
emh203 0:7798270c1f52 18 {
emh203 0:7798270c1f52 19 int i;
wavenumber 2:73a028278c5c 20 char * Color = VT100_WHITE;
emh203 0:7798270c1f52 21 //This function always needs called before you do anythign wit the CHEM BOX.
emh203 0:7798270c1f52 22 InitChemBox();
emh203 0:7798270c1f52 23
emh203 0:7798270c1f52 24 //Beep 6 times
emh203 0:7798270c1f52 25 for(i=0;i<6;i++)
emh203 0:7798270c1f52 26 {
emh203 0:7798270c1f52 27 Buzz(.05); //Since the Buzz function immediately returns we should wait a bit before calling it again in the loop
emh203 0:7798270c1f52 28 wait(.1); //I want a 50% duty cycle so I will wait twice as long as my previous Buzz() call
emh203 0:7798270c1f52 29 }
emh203 0:7798270c1f52 30
emh203 0:7798270c1f52 31
emh203 0:7798270c1f52 32 //Here is an example of how to draw on the screen!
emh203 0:7798270c1f52 33
emh203 0:7798270c1f52 34 //This makes the backlight white. Each color can be between 0 and 3 (integers... 0,1,2,3)
emh203 0:7798270c1f52 35 SmartSwitch_SetBackLightColor(3, 3, 3);
emh203 0:7798270c1f52 36
emh203 0:7798270c1f52 37 //The display routines are fully buffered. When you call the draw routines, the write to the backbuffer, not the screen.
emh203 0:7798270c1f52 38 //The flow is to clear the backbuffer, call all the drawing routines, then dump the backbuffer to the screen.
emh203 0:7798270c1f52 39
emh203 0:7798270c1f52 40 //This clears the back buffer
emh203 0:7798270c1f52 41 GFX_FullDisplayBufferClear(&BackBuffer);
emh203 0:7798270c1f52 42
emh203 0:7798270c1f52 43 //Draw a box around the edge of the screen
emh203 0:7798270c1f52 44
emh203 0:7798270c1f52 45 GFX_DrawLine(&BackBuffer, 0,0, PHYSICAL_DISPLAY_XRES - 1,0);
emh203 0:7798270c1f52 46 GFX_DrawLine(&BackBuffer, PHYSICAL_DISPLAY_XRES - 1,0,PHYSICAL_DISPLAY_XRES - 1 ,PHYSICAL_DISPLAY_YRES - 1);
emh203 0:7798270c1f52 47 GFX_DrawLine(&BackBuffer, PHYSICAL_DISPLAY_XRES - 1 ,PHYSICAL_DISPLAY_YRES - 1,0,PHYSICAL_DISPLAY_YRES - 1);
emh203 0:7798270c1f52 48 GFX_DrawLine(&BackBuffer,0, PHYSICAL_DISPLAY_YRES - 1,0,0);
emh203 0:7798270c1f52 49
emh203 0:7798270c1f52 50 //Draw a plain string using the 5x7 font.
emh203 0:7798270c1f52 51 GFX_DrawString(&BackBuffer,"Rioux Box",6,2, &Font5x7);
emh203 0:7798270c1f52 52
emh203 0:7798270c1f52 53 GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES - 1 ,12);
emh203 0:7798270c1f52 54
emh203 0:7798270c1f52 55 //This shows how to do a printf. Using this allows you to put internal variables, etc on the screen.
emh203 0:7798270c1f52 56 //Just lookup documentation on printf on the web to see examples of escape sequences in the control strings
emh203 0:7798270c1f52 57 //In this example API_VERSION is a string so we use %s to display it
emh203 0:7798270c1f52 58 GFX_printf(&BackBuffer,15,20, &Font3x5,"Ver: %s",API_VERSION);
emh203 0:7798270c1f52 59
emh203 0:7798270c1f52 60 //Move the backbuffer to the actual display
emh203 0:7798270c1f52 61 GFX_DumpRenderContextToPhysicalScreen(&BackBuffer);
emh203 0:7798270c1f52 62
emh203 0:7798270c1f52 63
emh203 0:7798270c1f52 64 //Here is the main super loop
emh203 0:7798270c1f52 65
emh203 0:7798270c1f52 66 //reset and start our control loop Timer
emh203 0:7798270c1f52 67 ControlLoopTimer.reset();
emh203 0:7798270c1f52 68 ControlLoopTimer.start();
emh203 0:7798270c1f52 69
emh203 0:7798270c1f52 70 while(1)
emh203 0:7798270c1f52 71 {
emh203 0:7798270c1f52 72 //Call this often if you want the USB interface/Terminal
emh203 0:7798270c1f52 73 ProcessTerminal();
wavenumber 2:73a028278c5c 74 /*RS232_0.printf(" RUN\r");
wavenumber 2:73a028278c5c 75 if(ControlLoopTimer.read_ms() >= 1000)
wavenumber 2:73a028278c5c 76 {
wavenumber 2:73a028278c5c 77 ControlLoopTimer.reset();
wavenumber 2:73a028278c5c 78
wavenumber 2:73a028278c5c 79
wavenumber 2:73a028278c5c 80 PC.printf(VT100_RESET);
wavenumber 2:73a028278c5c 81
wavenumber 2:73a028278c5c 82 for(int channel=0;channel<12;channel++)
wavenumber 2:73a028278c5c 83 {
wavenumber 2:73a028278c5c 84 if(channel & 0x01)
wavenumber 2:73a028278c5c 85 Color = VT100_CYAN;
wavenumber 2:73a028278c5c 86 else
wavenumber 2:73a028278c5c 87 Color = VT100_GREEN ;
wavenumber 2:73a028278c5c 88
wavenumber 2:73a028278c5c 89
wavenumber 2:73a028278c5c 90 float ThermocoupleTemperature = ReadThermocouple(channel);
wavenumber 2:73a028278c5c 91 float InternalReferenceTemperature = ReadInternalTemperature(channel);
wavenumber 2:73a028278c5c 92
wavenumber 2:73a028278c5c 93 bool IsDisconnected = (ReadThermocouple_OC() & (1<<channel));
wavenumber 2:73a028278c5c 94
wavenumber 2:73a028278c5c 95 if(IsDisconnected == true)
wavenumber 2:73a028278c5c 96 {
wavenumber 2:73a028278c5c 97 PC.printf(VT100_WHITE"Channel %i: ",channel);
wavenumber 2:73a028278c5c 98 PC.printf(VT100_RED"disconnected\r\n");
wavenumber 2:73a028278c5c 99 }
wavenumber 2:73a028278c5c 100 else
wavenumber 2:73a028278c5c 101 {
wavenumber 2:73a028278c5c 102 PC.printf(VT100_WHITE"Channel %i: ",channel);
wavenumber 2:73a028278c5c 103 PC.printf(VT100_WHITE"%s%.2f ",Color,ThermocoupleTemperature);
wavenumber 2:73a028278c5c 104 PC.printf(VT100_WHITE"INT: ",channel);
wavenumber 2:73a028278c5c 105 PC.printf(VT100_WHITE"%s%.2f\r\n",Color,InternalReferenceTemperature);
wavenumber 2:73a028278c5c 106 }
wavenumber 2:73a028278c5c 107
wavenumber 2:73a028278c5c 108 }
wavenumber 2:73a028278c5c 109 }*/
wavenumber 2:73a028278c5c 110
emh203 0:7798270c1f52 111
emh203 0:7798270c1f52 112 /*
emh203 0:7798270c1f52 113
emh203 0:7798270c1f52 114 //control loop example
emh203 0:7798270c1f52 115 //We will do something ever 250mS.
emh203 0:7798270c1f52 116 //Use a timer and an if statement we won't hold the microprocessor from do other things in the main super loop!
emh203 0:7798270c1f52 117 if(ControlLoopTimer.read_ms >= 250)
emh203 0:7798270c1f52 118 {
emh203 0:7798270c1f52 119 ControlLoopTimer.reset();
emh203 0:7798270c1f52 120
emh203 0:7798270c1f52 121 //if 250mSec has elapsed then do our control loop
emh203 0:7798270c1f52 122
emh203 0:7798270c1f52 123 CurrentTemperature = ReadThermocouple(0);
emh203 0:7798270c1f52 124
emh203 0:7798270c1f52 125 if(CurrentTemperature < 15.5)
emh203 0:7798270c1f52 126 {
emh203 0:7798270c1f52 127 EnableHeater(0);
emh203 0:7798270c1f52 128 }
emh203 0:7798270c1f52 129 else
emh203 0:7798270c1f52 130 {
emh203 0:7798270c1f52 131 DisableHeater(0);
emh203 0:7798270c1f52 132 }
emh203 0:7798270c1f52 133
emh203 0:7798270c1f52 134 FlushDigitalIO(); //Remeber, the digital outs are queued up until this is called!
emh203 0:7798270c1f52 135 }
emh203 0:7798270c1f52 136 */
emh203 0:7798270c1f52 137 }
emh203 0:7798270c1f52 138
emh203 0:7798270c1f52 139 }