Introduction: Plotting Live Data of a Temperature Sensor (TMP006) Using MSP432 LaunchPad and Python

About: Electronics Engineer | Always in the phase of continuous learning

The TMP006 is a temperature sensor that measures the temperature of an object without the need to make contact with the object. In this tutorial we’ll plot live temperature data from the BoosterPack (TI BOOSTXL-EDUMKII) using Python.

Step 1: Software - Energia IDE, PyCharm

Step 2: Hardware - MSP432 LaunchPad, Educational BoosterPack MKII

Step 3: Energia IDE

Connect the MSP432 LaunchPad + Educational BoosterPack to one of your computer’s USB ports and open Energia IDE.

Step 4: Select the Appropriate COM Port and Board.

Step 5: Energia Comes Preloaded With the Example Code for TMP006.

The example code can be opened as shown in the figure.

Step 6: Upload the Below Program to the LaunchPad by Clicking on the Upload Button.

#include <Wire.h>
#include "Adafruit_TMP006.h"
#define USE_USCI_B1

Adafruit_TMP006 tmp006; void printFloat(float value, int places) ;

void setup() { Serial.begin(115200);
// Initalizes the TMP006 for operation and for I2C communication if (! tmp006.begin(TMP006_CFG_8SAMPLE)) { Serial.println("No sensor found"); while (1); } }
void loop() { float objt = tmp006.readObjTempC(); float diet = tmp006.readDieTempC(); Serial.print(objt); //Object Temperature Serial.print(" -- "); Serial.println(diet); //Die Temperature

delay(1000); }

Step 7: PyCharm

Before running the program below, make sure that the packages, pySerial and Matplotlib are installed. PySerial is a Python library which provides support for serial connections over a variety of different devices. Matplotlib is a plotting library for Python.

To install any package in PyCharm, follow the below steps:
1. File -> Settings.
2. Under Project, select Project Interpreter and click on the “+” icon.
3. In the search bar, type the package you wish to install and click on Install Package.

Step 8: Python Program

import serial 
import matplotlib.pyplot as plt"seaborn")
''' In interactive mode, pyplot functions automatically draw to the screen. Interactive mode may also be turned on via matplotlib.pyplot.ion(), and turned off via matplotlib.pyplot.ioff(). '''

msp432 = serial.Serial('COM4', 115200) #(port number, baudrate) - create a serial object
i = 0 x0 = [] y1 = [] y2 = []

while True: msp432Serial = msp432.readline() tempArray = msp432Serial.split(b'--') objTemp = float(tempArray[0]) dieTemp = float(tempArray[1]) x0.append(i) y1.append(objTemp) y2.append(dieTemp) i += 1

plt.xlim(left=max(0, i-20), right=i+10) #set the x-limits of the current axis plt.ylim(20, 40) #set the y-limits of the current axis

plt.ylabel('Temperature (C)', fontname='Comic Sans MS', color='blue', fontsize=14) #set the label for the y-axis plt.grid(True) #turn the grid on plt.title('TMP006 Live Data', fontname='Comic Sans MS', color='red', fontsize=16) #set a title

p1, = plt.plot(x0, y1, color='r', linewidth=2) #plot x0 versus y1 - red line p2, = plt.plot(x0, y2, color='g', linewidth=2) #plot x0 versus y2 - green line

plt.legend([p1, p2], ['Object Temperature', 'Die Temperature'], loc='upper right', frameon=True) #place legends in upper right corner of the chart #display the figure
plt.pause(.000001) #pause for interval seconds

Step 9: Final Plot!

Object Temperature: It is the temperature of the chip surrounding area.
Die Temperature: It is the temperature of the chip itself.

Educational BoosterPack MKII:

Infrared Thermopile Sensor in Chip-Scale Package: