Fig. 1: Data logging In SD Card Using LPC1768 Prototype
A temperature data logger, is a portable measurement device that is able to recording temperature over a defined period of time automatically. The data can be retrieved and viewed after it has been recorded. In this device the temperature will record every 2 seconds in text file.
In this project we are using LM35 which is a three terminal linear temperature sensor from National semiconductors. It can measure temperature from-55c to +150C. The voltage output of the LM35 increases 10mV per degree Celsius rise in temperature. LM35 can be operated from a 5V supply and the stand by current is less than 60uA. For ADC interfacing with LPC1768 refer this article.
(For more detail in SD card interface refer SD Card interfacing with LPC1768).
To create a time stamp to be stored along with our measurements we need to access the Real Time Clock (RTC) block of the LPC1768. RTC Programming in LPC1768 is explained in this article.
Insert an SD card into the card holder and upload the sketch to your LPC1768. If the sketch is able to write to the SD card OK, it will create a text file called ‘Temperature.txt. The file is just a standard text file that can be read by any text editor. Once the file has been opened the sketch will start saving the sensor reading to it. If the file already exists it will just append the new reading onto the end. Here is what the contents of the Temperature.txt file should look like:
Fig. 2: Temperature.txt File Saving Sensor Reading In LPC1768
Temperature sensor LM35 is interfaced to the LPC1768 through the analog input pin 1.31. SD card is connected as per the SPI connections shown in the diagram. LCD is also interfaced to show the current temperature.
To log the temperature we will be repeating the following steps in software once two second:
Read the current date and time.
Read the current temperature from the LM35 connected to the analogue pin 1.31 and convert it into celcius.
Open a file on the SD card.
Save the measurement together with the date and time to the end of the file.
Close the file.
Create a project using Keil uvision4 for LPC1768 Microcontroller:
In this section, we will start creating a project in Keil MDK we have already installed Keil µVision and Co-MDK Plug-in + CoLinkEx Drivers required for the CoLinkEx programming adapter. You can start by downloading the project files and kick start your practical experiment.
The below function call is to get the current time values from the RTC
The below function calls are used to open the file and to write the values to it.
result = f_open(&file, “Temperature.txt”, FA_WRITE);//Open the file again.
result = f_lseek(&file, file.fsize);//Go to the end of the file
result = f_write(&file, buf,strlen(buf), &s1);//file type. result = f_close(&file);// Close the file.