From the course: IoT Foundations: Operating System Applications

Use a temperature sensor

From the course: IoT Foundations: Operating System Applications

Start my 1-month free trial

Use a temperature sensor

- [Instructor] Obtaining temperature sensor is one of the common sensing tasks of an IOT device. Any temperature sensor can be connected to our processor as a peripheral, and the red through our program front processor. There are many kinds of temperature sensors available. Basically, we can work with analog temperature sensor where we need to use the analog to digital conversion circuits. Nowadays, many temperature sensor provide a digital communication interface, such as I squared C that can directly connect to and interact with a processor. Now, let's look at the example of how do you use an internal temperature sensor in the Nordic nRF5-1A22, or nRF5-1422 chip. This temperature sensor can be directly operated internally in the chip and it measures the di-temperature own chip. Let's open the exercise file directory for this chapter where there is a readme.txt file telling us how to make the program work on Windows and Linux or Mac OS. In order to compile to program, we'll need to use nRF5-SDK version 12.3.0 and the GCC arm embedded tool chain. For the nRF5-SDK, I just downloaded from the website and extracted to the downloads directory. For the GCC arm embedded tool chain, you can go to the arm website to install the package for you to host the platform. After that's done, we'll modify the MakeFile.windows file under the nRF5-SDK directory in order to use the arm tool chain we've installed. So here is the example path to the GCC arm embedded tool chain I installed on my computer. For Linux or Mac users, the make file dot posix file should be modified in the same way. You can check the readme.txt file in the directory of the exercise file for more details. Now, let's take a look at the main source file first. So let's go back to the exercise file directory and open the main.c file with the visual studio as your text editor. In this free add task application, we define a function reading the temperature values using the API from the nRF5-SDK. In the main function from line 132 to line 173, the hardware components are initialized first, followed by the creation of one free add task regular task, and the one timer task. These tasks are defined to make LEDs blink at two different intervals. In the timer callback function in the line 124, what you wrote temperature reading function defined from line 75 to line 99. Where at line 95 we used the nRF log module API to output information to the URAT-C report so that we can check the outputs on our host computer. Now, let's navigate to the arm GCC directory under the temp sensor example folder and then open the directory with the command prompt. Now we can use the new make utility to compile the program. After the program is built, we can connect an nRF51-DK board to our host through the USB. Then, we can copy and paste the battery excusable file named nrf51422_xxac.bin and then paste it to the J link device to get this free add task based application up and running. We now can review the C report output from the board with a terminal tool. On Linux or Mac OS, you can use the screen utility to do so. Here on Windows, I just used a free tool called PuTTY to configure it to open the C report. Make sure we use the correct C report name recognized with the Windows device manager. On my computer, the account four is the C report name, so I can put that in PuTTY to open it with the direct port rate. The boat right now is set at 115.2 kilobits per second. After we open the C report connection with the PuTTY, we can see that the temperature values are shown on the screen. So right now the trip temperature is at 32 degrees Celsius or 89 degrees Fahrenheit. In addition, we can do something more with the application. We can read and save the data to the buffer, and when the buffer is full, move that data to a flash storage, and then clear the buffer to store more series of temperature values. There is some considerations when using a temperature sensor. We may need to convert the values directly read from the temperature sensor into meaningful values. And we may also need to categorate the values considering its specific operational conditions. In order to manage the accurate environmental temperature, it's better to use an external temperature sensor and categorate the sensor based on a data sheet and actual testing results.

Contents