For all the parts to this project, click here! Smart Doorbell System

 

Introduction

This short blog post discusses a wireless temperature probe! It re-uses hardware and software that was designed earlier, for a Smart Doorbell system. All the hardware and software is documented, click on the link above for deep-diving into it.

 

I was originally about to add some functionality to measure outdoor temperature, but then got bored when I realized it did not involve soldering - there is an internal temperature sensor inside the CC2640R2F CC2640R2F chip : )

 

So, this project evolved to use an external temperature sensor – a thermocouple, which makes it ideal for all sorts of lab or industrial use-cases. Thermocouples are not always the right solution, but there is the advantage that they can operate over a wide range of temperatures, beyond 1000 degrees C.

 

The advantage in using Bluetooth Low Energy (BLE) for this project is is that the system could be connected up and monitored from a safe location, using either the Pi or (say) a mobile phone.

 

This 90-second video shows it in action: (having trouble embedding it)

https://youtu.be/WdXkmSTfriU

 

 

How Does It Work?

The project re-uses the Bell Push Module hardware, which is basically a small battery-powered circuit board. There isn’t a lot to assemble, hence why this blog post is short. The Bell Push Module has an expansion port, and a Maxim thermocouple interface chip was soldered to it, along with a decoupling capacitor, and a thermocouple socket. That’s it, the hardware is very straightforward!

 

In terms of the software, the code was modified to make the Bell Push Module look like a BLE ‘Peripheral’. It can connect to the Pi, using code that was written in the blog post Smart Doorbell System - Part 9 - Working with BLE - What it is, and How to Use It! , but modified slightly. All the software for this project is attached to this blog post.

 

When run, the microcontroller repeatedly reads the thermocouple measurement from the thermocouple interface chip, and from the internal temperature sensor inside the chip too. The chip measures the voltage from the thermocouple and from this and the internal sensor information, the probe sensed temperature can be worked out. The Maxim chip states an accuracy of +-2 degrees C but it would also depend on the actual thermocouple being used. The thermocouple can be used over a huge temperature range, depending on the construction and materials used for it. The resolution is 0.25 degrees C, and the measurement rate can be up to 10 times a second (I only tested at 1 measurement per second).

 

The Pi connects to the Bell Push Module using BLE, and then retrieves the measurements every second. This could be speeded up if desired – I didn’t test at any higher speeds.

 

The information is just dumped to the screen but it could be redirected to a file, or plotted for instance.

 

Building It

Please refer to the earlier blog posts for the CAD files and circuit diagrams. If it is desired to use off-the-shelf hardware, then the TI CC2640R2 LaunchPad boardTI CC2640R2 LaunchPad board can be used. The thermocouple interface chip can be attached using jumper cables. The chip on its own is very low-cost but it is also available pre-soldered onto a breakout board. This isn’t worth it in this case – the chip is quite large and easy to solder.

 

The MAX31855 MAX31855 integrated circuit comes in several varieties; you need one that matches the thermocouple. So, for a Type J thermocouple, a MAX31855J chip is needed and so on.

 

Using It

The instructions in the earlier blog post can be followed, to make the Pi into a BLE Central device. Then, copy and paste the code below into a file, called (say) therm.js :

 

#!/usr/local/bin/node
// therm.js
// rev 1.0 July 2018 Shabaz
//


var noble=require('noble');
var util = require('util');
var events = require('events');




var THERM_SERVICE_UUID = 'fff0';
var THERM_CHARACTERISTIC_UUID = 'fff5';


var therm_characteristic=null;




noble.on('stateChange', function(state){
  if (state==='poweredOn'){
    console.log('scanning..');
    noble.startScanning([THERM_SERVICE_UUID], false);
  }
  else {
    noble.stopScanning();
  }
})


noble.on('discover', function(peripheral){
  noble.stopScanning();
  console.log('found: ', peripheral.advertisement);
  peripheral.connect(function(err){
    peripheral.discoverServices([THERM_SERVICE_UUID], function(err, services){


      services.forEach(function(service){
        console.log('found service: ', service.uuid);
        service.discoverCharacteristics([], function(err, characteristics){
          characteristics.forEach(function(characteristic) {
            console.log('found characteristic:', characteristic.uuid);
            if (THERM_CHARACTERISTIC_UUID == characteristic.uuid){
              therm_characteristic = characteristic;
              setInterval(handleThermSystem, 1000);
            }
            else {
            //console.log('Error, some characteristics were missing');
           }
          })
        }) // end service.discoverCharacteristics
      }) // end services.forEach
    }) // end peripheral.discoverServices
  }) // end peripheral.connect
}) // end noble.on


function handleThermSystem() {
  therm_characteristic.read(function(error, data) {
    fault=0;
    faultparams=0;
    if (data.length>=4) {
      byte0=data[3]; // least significant bits D7..0
      byte1=data[2]; // D15..8
      byte2=data[1]; // D23..16
      byte3=data[0]; // most significant bits D31..24
      if (byte2 & 0x01) {
        fault=1;
        faultparams=byte0 & 0x07;
        console.log("Thermocouple fault #"+faultparams);
      } else {
        refval=(byte0>>4)+(16*(byte1 & 0x7f));
        if (byte1 & 0x80) refval=0-refval;
        reftemp=0.0625*refval;
        thermval=(byte2>>2)+(64*(byte3 & 0x7f));
        if (byte3 & 0x80) thermval=0-thermval;
        thermtemp=0.25*thermval;


        console.log("Temperature: "+thermtemp+"degC (Ref: "+reftemp+"degC)");
      }
    }
  });
}

 

To run it, as root user (or prepend the commands with sudo) type:

chmod 755 therm.js
./therm.js

 

When run, the output will say scanning.. (it is looking out for BLE advertisements). Power up the Bell Push Module and the Pi will connect to it, and will begin dumping the temperature to the screen every second!

It seems to work in the limited tests so far! I tried the thermocouple with a hot air tool.

 

 

Summary

It is really easy to make remote measurement gadgets with the CC2640R2F chip, and connect to the Pi or BeagleBone for display/monitoring or logging purposes.

I intend to make another PCB design, with two thermocouple interfaces, and perhaps an LCD too (although that is unnecessary), all based on this same design. Battery life should be excellent; I believe around one month of continuous logging and capture to a Pi is achievable with that AA-sized battery, and of course longer if the logging rate is decreased from 1 measurement per second to (say) 1 measurement every ten seconds.

 

All the code needed to get this going is attached to this blog post. It is proof-of-concept level, but I will refine it once I have a PCB layout with the thermocouple interfaces on-board.

 

Thanks for reading!