Plotting Live Data of a Temperature Sensor (TMP006) Using MSP432 LaunchPad and Python
by thesharanmohan in Circuits > Sensors
1907 Views, 3 Favorites, 0 Comments
Plotting Live Data of a Temperature Sensor (TMP006) Using MSP432 LaunchPad and Python
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.
Software - Energia IDE, PyCharm
Energia IDE: https://energia.nu/
PyCharm: https://www.jetbrains.com/pycharm/
Hardware - MSP432 LaunchPad, Educational BoosterPack MKII
Energia IDE
Connect the MSP432 LaunchPad + Educational BoosterPack to one of your computer’s USB ports and open Energia IDE.
Select the Appropriate COM Port and Board.
Energia Comes Preloaded With the Example Code for TMP006.
The example code can be opened as shown in the figure.
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); }
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.
Python Program
import serial
import matplotlib.pyplot as plt
plt.style.use("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(). '''
plt.ion()
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
plt.show() #display the figure
plt.pause(.000001) #pause for interval seconds
Final Plot!
Object Temperature: It is the temperature of the chip surrounding area.
Die Temperature: It is the temperature of the chip itself.
References:
Educational BoosterPack MKII:
http://www.ti.com/tool/BOOSTXL-EDUMKII
Infrared Thermopile Sensor in Chip-Scale Package:
http://www.ti.com/ww/eu/sensampbook/tmp006.pdf
Matplotlib:
https://matplotlib.org/
pySerial:
https://pyserial.readthedocs.io/en/latest/shortintro.html