element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Temperature Measurement for Lab and Science Projects
  • Blog
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi Projects requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 14 Nov 2014 1:05 AM Date Created
  • Views 3476 views
  • Likes 20 likes
  • Comments 150 comments
  • stem
  • rpiintermediate
  • science_and_technology
  • rpibeginner
  • thermocouple
  • raspberry_pi
  • thermometer
  • stem_academy
  • texas_instruments
  • rpi
  • raspberry_pi_projects
  • ti
Related
Recommended

Temperature Measurement for Lab and Science Projects

shabaz
shabaz
14 Nov 2014

A Question of Scale

Enter Your Electronics & Design Project for a Chance to Win a Cartridge-Sized NES Portable or a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Introduction

Every lab (home, office, school) needs temperature measurement capabilities. Measuring temperature for science experiments is hard – all sorts of materials, liquids, and chemicals may be involved or a large temperature range may need to be covered. The sensor used for this (a thermocouple) is not easy to interface, and the sensor amplifier is non-trivial since it has to be able to measure an extremely small voltage.

 

For flexibility in the science experiments that it can be used for, high accuracy is needed along with a fast response and good update rate. It goes without saying that data should be logged in a convenient form, and it should be easy to use.

 

For convenience there are ready-built temperature measurement and logging products out there, sometimes they are not easy to use due to soft-button overload and a limited display. In addition for large lab or classroom use information should be logged and retrievable by people easily – and perhaps view the current status on a large screen. It also goes without saying that some experiments may take a long time, so the ability to check up on your experiment using a mobile phone during lunch is useful too. One last requirement was that this should be easy to build even for people new to electronics and software.

 

This project shows how to connect up a thermocouple board to a Raspberry Pi (RPI), and use it for temperature measurement and logging with great performance and ultra-low cost. This project is easy – no soldering required unless you want to. This is also a great project to start using the 'DIL (dual-in-line) header'  connector on the RPI if you have not already done so.

 

Here is a video showing the entire project in action; the brown cable is the temperature probe.

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

 

Design Overview

A lot of thermocouple-based hobbyist projects use the MAX31855 integrated circuit and ready-built ‘thermocouple amplifier’ boards are available for connecting to the RPI from several suppliers. This project however uses the far higher-resolution ADS1118 from Texas Instruments. It comes in a surface-mount package but fortunately a ready-built ADS1118 development boardready-built ADS1118 development board is available which contains all circuitry including a LCD display and thermocouple - it is extremely good value for money. If you don’t fancy soldering then it is possible to connect up this board to the Raspberry Pi (or any other computer board – it uses a standards based communicaton method called Serial Peripheral Interface or SPI) using eight jumper wires (male-to-female cables are needed). Alternatively, if you don’t mind a soldering exercise then a small adapter board can be constructed. This was the approach taken here. In summary you can see in the photo below all the bits that are used for this project, including the assembled adapter board.

 

The entire project can be controlled via a web browser or from the command line.

 

To build the adapter board, the simplest way is to use a circuit board; using EAGLE software I drew up a design for which the files are attached to this post ready to send off to a PCB manufacturer (it costs about $30 for ten boards).

 

Alternatively, prototyping board can be used; I obtained some perf-boardperf-board (the type with isolated pads, not stripboard) and cut it to size. A 3mm hole was drilled for attaching a support pillar (threaded hex spacer)support pillar (threaded hex spacer). The boards are next to each other, not on top of each other, to minimise temperature change and noise issues, both of which would have an effect on the thermocouple reading.

 

The next step was to solder a  40-way DIL header socket  40-way DIL header socket.

 

I wanted the ability to plug in the ADS1118 board onto the pad side of the perf-board, so there is a slight complication here. The solution was to use bent SIL headers. 10-way SIL headers10-way SIL headers are needed (the photo shows 8-way which is what I had at hand) - or use surface mount ones which are similar but with the bent ends alternating on either side. If you are using a circuit board and not perf-board, then straight SIL headersstraight SIL headers are needed.

 

To get them aligned, plug them into the ADS1118 board, and position it over the perf-board and then tack a few pins with solder. Then the ADS board can be very gently unplugged and the SIL headers can then be soldered properly. Note that at this stage it is quite difficult to unplug without tearing the pads off the board. Hold the bent part of the SIL headers against the board while unplugging the ADS1118 board.

 

Next, to make the SIL headers very secure, solder each pin to as many pads as possible (each one can be soldered to three pads).

 

The next step is to wire it up. I used Kynar wireKynar wire which is very thin but any wire will do.

 

To identify the connections, refer to the pin numbering photo below and the following table:

* Connections:
* TI board       RPI B+
* ------------   ------------------
* P1_1  VCC      1     3.3V
* P1_7  CLK      23    CLK
* P1_8  ADS_CS   26    SPI_CE1
* P2_8  LCD_CS   24    SPI_CE0
* P2_9  LCD_RS   11    GPIO_17_GEN0
* P2_1  GND      9     GND
* P2_6  SIMO     19    MOSI
* P2_7  SOMI     21    MISO
     

 

 

After testing the software and board functionality, it is possible to use some epoxy resin glue (e.g. Araldite) to make the SIL headers even more secure. A minimal amount was used so that it was possible to still just-about solder onto the pins if needed to in future.

 

With the PCB approach mentioned earlier, when the PCB arrives, the header pins and receptacle can be soldered, and it is an easy task (takes five minutes) so the PCB is the preferred method especially if you need to make many of them (I intend to make several). I used DIL header pins instead of SIL, but either will work with the PCB layout attached to this post.

Here it is attached to the RPI:

Underside view:

 

 

Software

The diagram here shows the entire solution overview. The majority of the code is in three files. The code that interfaces to the ADS1118 board is discussed first, because it is possible to run this code standalone if desired. It is shown in purple in the diagram.

 

To create the software, the first thing one of the things to do is to create a logo:

/**********************************************************************************************
* therm.c
 RPI  430BOOST-ADS1118 Thermocouple/LCD Board 
*
*         __                                __     ____   _____
*   ____ |  |   ____   _____   ____   _____/  |_  /_   | /  |  |
* _/ __ \|  | _/ __ \ /     \_/ __ \ /    \   __\  |   |/   |  |_
* \  ___/|  |_\  ___/|  Y Y  \  ___/|   |  \  |    |   /    ^   /
*  \___  >____/\___  >__|_|  /\___  >___|  /__|    |___\____   |
*      \/          \/      \/     \/     \/                 |__|
*                                                          
     

 

The next step is to make use of the wealth of code that TI usually offers. In this case, TI already had high quality ADS1118 code intended for the MSP430 Launchpad that could be reused. It was adapted slightly to be usable on the RPI, using some input/output (I/O) code from Gert van Loo and Dom.

 

Temperature measurement may seem to be an easy task (read an ADC value and convert to temperature) but thermocouples require ‘cold junction compensation’ which in the case of the ADS1118 means reading an internal temperature sensor too. The code interleaves reading the internal sensor and the external thermocouple. Another key point is that a thermocouple output is not linear compared to temperature; thermocouple manufacturers publish data that can be used to get a more accurate conversion from ADC value to actual temperature. The TI code already includes these capabilities for the supplied thermocouple.

 

The code was adapted to add logging capability. Since the board is to be powered by the noisy 3.3V supply from the RPI, and it is in close proximity to the RPI, some steps need to be taken to ensure that the measurement is cleaned up. The implemented algorithm every second reads the internal temperature sensor once, and the external thermocouple ten times in a short burst (a few hundred milliseconds total) so that the measurements can be averaged and finally output to 0.1 degrees C resolution. The end result was very good; see some example output here.

 

The LCD has two lines of 16 characters, so it was decided to use the bottom line to display the time and current thermocouple temperature. The top line is user-dependent; it can be set to something so that people immediately know what the experiment is about. For example, it can say “Test #1” or “Don’t touch’.

 

Using the code is easy.

 

First off, confirm that some features are enabled on the RPI. If the RPI is being used fresh, then after operating system installation, ensure that the ‘Advanced’ menu option is selected and then enable three things: SSH, SPI and I2C - we don't use all these for this project, but they are standards based interfaces that should always be enabled unless you never want to unplug the RPI from a monitor or not make use of the 40-way DIL connector on the RPI. If this was not done after OS install, then type raspi-config in a text window (also known as a command shell) on the RPI and then select ‘Advanced’ in the menu that appears.

 

Assuming the three features mentioned above are enabled, then create a folder for your work off your home directory (e.g. create a folder called development and then a sub-folder called therm) and copy the source code (stored at github.com) into that sub-folder.

Here is how to do all this:

 

To compile the code (also shown in the screenshot above) type:

gcc -o therm therm.c -lrt
     

 

The code is now ready to run. There are a few ways to use this project. One way is to just type commands into the command shell. Another way is to use a web browser. These two methods are discussed next.

 

Command Interface

The code can be run either using ‘sudo’ or as superuser (root) user.

For the latter, to become root user, first type sudo passwd root one time, and create a superuser (i.e. root user) password. Now, whenever you want to become superuser, you can just type 'su' and enter that password. To exit out of superuser privileges at any time, type 'exit'. Some people prefer sudo, others feel it is an unnecessary handcuff.

 

sudo ./therm
     

 

or (using the root user method)

sudo passwd root
su
./therm
     

 

The temperature will be displayed.

There are other variations, of which some are listed here. For example to dump the temperature every second to the command shell, type:

./therm 1
     

 

The command above will indefinitely dump temperature to the screen. To stop it at any time, press Ctrl-C.

 

To log the data, type:

./therm 1 mylogfile.csv
     

 

Press Ctrl-C to stop logging, and the generated file can be viewed and graphed using spreadsheet software (e.g. Excel).

 

To print some text to the LCD display, type:

./therm msg “Experiment #1”
     

 

or combine it with a filename to start logging too:

./therm 1 mylogfile.csv msg “Logging…”
     

 

Using a Web Browser

To use web browser capability, a platform called Node.js is run on the RPI. There are plenty of projects on Element 14 using Node.js with the RPI or BeagleBone Black. To avoid repeating, just follow the Node.js and Socket.IO install steps at this location (scroll to the section "Raspberry Pi web server and application software") and follow all the steps listed in that section up to and including the command ‘npm install socket.io’.

The code that will be used to enable web control is shown in blue and orange in the diagram below:

 

To run the web server/application software, type

node index.js
     

 

Now you can navigate using a web browser to http://xx.xx.xx.xx:8081/index.html to see the web page. Click ‘Live’ to see the live view of temperature.

 

Select a file name and click ‘Log’ to start logging data.

 

Summary

Thanks to TI’s skilful engineering with the ADS1118 board, a very high quality science lab temperature-logging instrument can be quickly assembled, ready to run interesting experiments. See the coffee cup blog post for an example.

 

The software is fresh and really just proof-of-concept level and will have a few bugs but it appears to work reasonably well in the limited testing I have done so far (I used it to log data for a few hours). It would be wise to do a practise run before trying to use the software in a classroom.

 

Although I have no means to measure accuracy, TI have published a PDF document about precision thermocouple measurement with the ADS1118 which shows the techniques they used to ensure an accurate result. It is reassuring to see the output using the board and algorithm appears clean and as expected.

 

For quick results, use the PCB design attached to this post, but the proto-board method works well too.

 

Additional Ideas

If desired (e.g. outdoor use), the solution can be powered from a Lithium Polymer (LiPo) cell. To do this, a BatteryBoosterPackBatteryBoosterPack is inserted in-between the adapter board that was created, and the thermocouple board. Here is what it looks like:

The Battery BoosterPack comes with the LiPo cell. Note that some slight modifications need to be done to the Battery BoosterPack before it is used for this project, in order to prevent any pins from clashing. See this blog post (scroll to the section titled "Battery Power" and perform the steps in that section).

 

Future Plans: A new version

As of July 2019, a new version is being developed (it is almost complete), that has two thermocouple connectors. The new board will connect to the Pi via jumper wires, it is not a plug-on board. Optionally, the same board will also work with the VIKI project, and in that case the thermocouples will be electrically isolated from the Pi. The display is a separate project. The new version needs to be tested, and then the details will be shared so anyone can make it. For more information about the new version, please see the comments below until the full details are written up in a blog.

 

Source Code

Code is available on GitHub, click here. The initial version has functionality to display temperature on the LCD display and on the browser dynamically, and also initiate logging (and displaying temperature). It is experimental code, and will need enhancements; currently it is not possible to stop the logging if started, except by going to the command line.

 

It has some bugs, such as if multiple users connect to the browser, expect occasional erroneous values of 0 degrees C on the display briefly if multiple users connect and the system is not logging (if the system is logging, this issue does not occur). Also it may display 'error' briefly when connecting. It continues to function.

 

There are no known issues with the actual measurements and the logging functionality, however if you are planning to run a very long (multiple hours) experiment, it would be good to have a dry run first, to confirm the system functions for an extended time - I only ran the system for an hour or two at a time. Also, you may wish to log less frequently in that case (currently it logs every second).

Attachments:
therm-cad-files.zip
therm-extend.zip
therm-cad-files-OSH.zip
therm_pi3bplus.zip
Anonymous

Top Comments

  • shabaz
    shabaz over 7 years ago in reply to mcb1 +6

    I just tried the PCB, way more convenient! It worked fine. Now I can build a few of these. I've been a bit slow to publish the code (one bit of functionality I still needed to add), but will publish this…

  • mcb1
    mcb1 over 7 years ago in reply to shabaz +3

    Nice board.

    I do like how you've really clearly idenified the 3v3 pin (top and bottom), along with the pin names.

     

     

    Mark

  • shabaz
    shabaz over 7 years ago in reply to michin +3

    Hi!

     

    I used iTead for this particular board, they were good! There may be a delay now due to Chinese New Year however.

    For that reason OSH Park may be another option, they are good too and are based in US…

  • shabaz
    shabaz over 3 years ago

    The new version is almost complete.. It still needs to be tested (and code still needs to be developed too, it will be based on the existing code, but tested with Pi 3 and Pi 4).

    With this new version, there are two thermocouple connectors built-in. The board no longer plugs directly on the Pi, but is attached using a few jumper wires. The display is not part of the board, the display is a separate project (or use a 16x2 display etc.).

    The other advantage of this new version is that it can be used with the VIKI project too, by removing the jumpers and replacing with a flat flex cable. With the VIKI project there is the extra advantage that the thermocouples are isolated from the Pi, and there is a built-in display there (16x2 characters).

    Once it is confirmed it all works (might be a few weeks, I need to write the code), I'll publish the details.

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to at0

    Hi at0,

     

    I've just tried a fix, it's not very pretty, but it works. For some reason, the direct GPIO isn't working with the Pi 3B+ in the way I'd coded it for the older Pi.

    Anyway, as a test, I tried using a library, and it works with that.

    To use it with the Pi 3B+, follow the same steps as before, i.e.

     

    git clone https://github.com/shabaz123/TemperatureMeasurement.git
    cd TemperatureMeasurement
    cd rpi

     

    In that folder, there's a file called therm.c. Make a backup of it if you want, and then download the file called therm_pi3bplus.zip which is attached to this blog post. Unzip that, and there's a file called therm_new.c inside there. Copy that to the rpi folder, and rename it to therm.c

     

    Then, compile it using:

    gcc -o therm therm.c -lrt -lwiringPi

     

    Then as superuser (or using sudo) run the code as described in the blog post, for example to display to the LCD, initialize first:

    ./therm lcdinit

     

    then you can use stuff like:

    ./therm msg "hello"

     

    Going forward, I've created a custom PCB (open source, the design will be shared here) that replaces the TI board, and has dual thermocouple connectors on it. It has no display, but there are some other projects, such as Building a 3.5 Digit Low Power LCD Module  that will work. Or, for a high-res screen, there is this project: VIKI (Versatile Intelligent Controller for Industry) Schematic, Bill of Materials and Component Placement Diagrams

     

    The thermocouple board can optionally plug onto that VIKI project.

    These projects require some soldering, but it's not too bad, and not all the components are required if all you need is the LCD portion, and the thermocouple portion.  It has the benefit that the thermocouples will be isolated, and a bit further away from the Pi too.

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • More
    • Cancel
  • at0
    at0 over 3 years ago

    Hi all,

     

    I have tried this project on a RPI 3 B and everything works perfectly fine, except of the LED output. Has anyone managed to succesfully adapt the code so that it also works on newer RPI models?

     

    Thanks a lot!

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to shabaz

    Hi Eugene,

     

    I've merged your code into the main branch, thank you for the excellent updates and the additional code you wrote too. Also it would have been impossible for me to have tested it the way you have, it's really valuable.

    Just to let you know, I've almost completed a dual-thermocouple PCB using the same chip to continue to use the effort you and Vema and others in the thread put in to build and test out the project.

    The prototype should be constructed and tested in a few weeks time, and then I'll modify the code to read both thermocouples. The new board has some improvements, that may make it more stable in some cases too. I'll keep this thread updated, and make sure we all have a way to get the latest board.

    Many thanks,

    Shabaz.

    • Cancel
    • Vote Up 0 Vote Down
    • Reply
    • More
    • Cancel
  • lornamca
    lornamca over 4 years ago in reply to shabaz

    Brilliant - thank you Shabaz, very helpful

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube