Alert.png

Notice: This page contains information for the legacy Phidget21 Library.

Phidget21 is out of support. Bugfixes may be considered on a case by case basis.

Phidget21 does not support VINT Phidgets, or new USB Phidgets released after 2020. We maintain a selection of legacy devices for sale that are supported in Phidget21.

We recommend that new projects be developed against the Phidget22 Library.


Click on the 2phidget22.jpg button in the menu bar to go to the Phidget22 version of this page.

Alert.png

Data Logging With a Thermocouple

From Phidgets Legacy Support

The project described here is a data recording program for the Phidget Temperature Sensors. We play with the program and record data to learn things about our environment. The emphasis in this project is on passing data and writing to files in different languages, to also learn about data logging in general.


Practical concepts covered are (click on links to see other projects on that topic):
  • Data Logging
    • Writing to a text file
    • Adding timestamps to your data
    • Using Phidgets with C/C++
    • Using Phidgets with Python
    • Using Phidgets with Java
  • Analyzing your Phidget Data
 


As with any of our described projects, Phidgets takes care of the electrical component design. Here, we also provide some simple code so you can play around with your Temperature Sensor and thermocouple, and save the data to plot later.

Time: About two hours for the basics, three hours for looking at and analysing the data
Special Needed Tools: Something hot (tea, your skin), or something cold (ice, etc)
Materials and Phidgets: A Phidget Temperature Sensor (1048 or 1051), a Thermocouple, a USB cord, and your computer

Also:



Introduction

This application guide is all about basic data logging and analysis with Phidgets. The ability to write an automatic data logger is one of the strong advantages to Phidgets - you do not have to take visual readings of a thermometer (or other sensor) and record the readings in a log book manually, rather, you can simply log directly to a computer.

Thermocouples provide a way to inexpensively measure the temperature of a material through physical contact. Although we use thermocouples and a Phidget Temperature Sensor (1048 or 1051) as our Phidget to log data from, basic data logging will be similar for many other Phidgets.

Phidgets

To use the code in this Guide, you will need to have a Phidget Temperature sensor and a thermocouple.

Some example ways to set this up are:

Example Setup Strengths
Basic thermocouple setup
Ability to measure multiple points
Wide temperature range thermocouple

Of course, these are only examples - any thermocouple with either Temperature Sensor Phidget board will work.

We will log data from thermocouple port 0. On a one-input board, this is the only thermocouple input; on a four-input board, make sure you have a thermocouple plugged in to port 0:

Then:

  • Make sure you have followed the Getting Started guide for your Phidget
  • Make sure you have the programming language libraries that you want installed
  • Plug the USB in to your computer
  • Continue on to the next section and start writing code!

Code

Java Code and Discussion

Python Code and Discussion

C Code and Discussion

If you are using Windows, please refer to the Java or Python section as the C code was written on Linux. The use of Phidgets in C on any operating system is the same. However, ANSI-based C does not include support for getting time on any resolution smaller than one second. So, to obtain timing for the data as it comes in, we need to use operating-system specific code. It would probably be fairly straightforward to modify this code to use a Windows method of obtaining time.

You will need to link in both the Phidgets library (-lphidget21) and the Real Time POSIX library (-lrt) when compiling your code:


Putting it All Together

The code above saves the data from the Temperature Sensor Phidget into a Comma Separated Value file (*.csv). It will be named based on the code snippet you use and written into the directory where you run the code:

  • Java code writes to "temperature_data_java.csv"
  • Python code writes to "temperature_data_py.csv"
  • C code writes to "temperature_data.csv"

Try running the code on a command line or in a terminal, and you will probably see something like this:

Data Analysis


Extra Credit

  • As mentioned above, the thermocouple is a contact temperature sensor - it works by becoming the same temperature as the material it is touching. There were a few materials