This demonstration shows how to use the PmodTC1. You will also see how to plot a graph using matplotlib.
The PmodTC1 is required.
The thermocouple sensor is initialized and set to log a reading every 1 second. The temperature of the sensor can be changed by touching it with warm fingers or by blowing on it.
In [1]:
from pynq import Overlay
Overlay("base.bit").download()
In [2]:
from pynq.iop import Pmod_TC1
from pynq.iop import PMODB
# TC1 sensor is on PMODB
my_tc1 = Pmod_TC1(PMODB)
r = my_tc1.read()
print('Raw Register Value: %08x hex' % r)
print('Ref Junction Temp: %.4f' % my_tc1.reg_to_ref(r))
print('Thermocouple Temp: %.2f' % my_tc1.reg_to_tc(r))
print('Alarm flags: %08x hex' % my_tc1.reg_to_alarms(r))
In [3]:
my_tc1.start_log()
In [4]:
my_tc1.stop_log()
log = my_tc1.get_log()
In [23]:
%matplotlib inline
import matplotlib.pyplot as plt
tc = [my_tc1.reg_to_tc(v) for v in log]
ref = [my_tc1.reg_to_ref(v) for v in log]
plt.plot(range(len(tc)), tc, 'ro', label='Thermocouple')
plt.plot(range(len(ref)), ref, 'bo', label='Ref Junction')
plt.title('TC1 Sensor log')
plt.axis([0, len(log), min(tc+ref)*0.9, max(tc+ref)*1.1])
plt.legend()
plt.xlabel('Sample Number')
plt.ylabel('Temperature (C)')
plt.grid()
plt.show()
In [ ]: