How Cold??
So we've had a really cold snap here in the UK, but not being content with knowing everything was cold, I'd rather know exactly how cold it is, and what the profile looks like. Mainly because I can.
Objectives
I want to use the SPI Thermometer to take temperature measurements every minute and log them to a CSV file (comma separated values) on the mbed board. Microsoft Excel will happily open the CSV file and allow me to plot a nice graph.
Ingredients
To do this experiment I drew upon :
- The MAX6662 digital SPI thermomenter page SPI Thermometer?.
- The local file system pages Local File System.
The circuit
Exactly the same as the that on the SPI thermometer page. the only difference I added was an enable pin, so that I can switch the data logging on and off.
The code
#include "mbed.h" #include "MAX6662.h" // Create the local filesystem under the name "local" LocalFileSystem local("local"); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalIn button(12); MAX6662 st(5, 6, 7, 8); Serial pc (USBTX,USBRX); float sample_delay = 60.0; int main() { /* ==================================== Some rudimentary code to set the RTC Note that this initialised to a hard coded time If I'd had time, and a battery to back up the RTC I'd have programmed it once, then removed this code */ PCONP |= 0x200; RTC_CCR = 0x10; RTC_SEC = 00; RTC_MIN = 05; RTC_HOUR = 22; RTC_DOM = 6; RTC_MONTH = 1; RTC_YEAR = 2009; RTC_DOW = 1; // Enable the RTC RTC_CCR |= 0x1; /* ==================================== */ while (!button) {} led1 = 1; // Open "out.txt" on the local file system for writing FILE *fp = fopen("/local/Temp.csv", "w"); while (button) { led2 = !led2; // time,data<cr> fprintf(fp,"%02d/%02d/%02d %02d:%02d,%f\n",RTC_DOM,RTC_MONTH,RTC_YEAR,RTC_HOUR,RTC_MIN,st.read()); pc.printf("%02d/%02d/%02d %02d:%02d,%f\n",RTC_DOM,RTC_MONTH,RTC_YEAR,RTC_HOUR,RTC_MIN,st.read()); wait (sample_delay); } fclose(fp); led1 = 0; }
The result
After the data logging was complete, I copied the .csv file from the mbed board. In Excel (2003),
- Click File-> Open.
- In the dialog box change the drop down box named "Files of type" to say "All files *.*".
- Select Temp.csv, Click "Open"
- Make sure "Delimited" is selected, then click "Next"
- Check the "Comma" box, click "finish"
Your worksheet should now contain the logged data. You can use all the features of Excel to plot graphs etc.
Here is one I made earlier... OvernightTemp.xls
To save you downloading it, here is the graph
