from Tkinter import * from tkFileDialog import askopenfilename import tkMessageBox import matplotlib matplotlib.use('TkAgg') import numpy as np from numpy import arange, sin, pi import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import smbus import time import RPi.GPIO as GPIO Temperature = [-6.458, -6.458, -6.457, -6.456, -6.455, -6.453, -6.452, -6.45, -6.448, -6.444, -6.441, -6.441, -6.438, -6.435, -6.432, -6.429, -6.425, -6.421, -6.417, -6.413, -6.408, -6.404, -6.399, -6.393, -6.388, -6.382, -6.377, -6.37, -6.364, -6.358, -6.351, -6.344, -6.337, -6.329, -6.322, -6.314, -6.306, -6.297, -6.289, -6.271, -6.262, -6.262, -6.252, -6.243, -6.233, -6.213, -6.202, -6.192, -6.181, -6.17, -6.158, -6.158, -6.147, -6.135, -6.123, -6.111, -6.099, -6.087, -6.074, -6.061, -6.048, -6.035, -6.021, -6.007, -5.994, -5.98, -5.965, -5.951, -5.936, -5.922, -5.907, -5.891, -5.891, -5.876, -5.861, -5.845, -5.829, -5.813, -5.797, -5.78, -5.763, -5.747, -5.73, -5.713, -5.695, -5.678, -5.66, -5.642, -5.624, -5.606, -5.588, -5.569, -5.55, -5.531, -5.512, -5.493, -5.474, -5.454, -5.435, -5.415, -5.395, -5.374, -5.354, -5.333, -5.313, -5.292, -5.271, -5.25, -5.228, -5.207, -5.185, -5.163, -5.141, -5.119, -5.097, -5.074, -5.052, -5.029, -5.006, -4.983, -4.96, -4.936, -4.913, -4.889, -4.865, -4.841, -4.817, -4.793, -4.768, -4.744, -4.719, -4.694, -4.669, -4.644, -4.618, -4.593, -4.567, -4.542, -4.516, -4.49, -4.463, -4.437, -4.411, -4.384, -4.357, -4.33, -4.303, -4.276, -4.249, -4.221, -4.194, -4.166, -4.138, -4.11, -4.082, -4.054, -4.025, -3.997, -3.968, -3.939, -3.911, -3.882, -3.852, -3.823, -3.794, -3.764, -3.734, -3.705, -3.675, -3.645, -3.614, -3.584, -3.554, -3.523, -3.492, -3.462, -3.431, -3.4, -3.368, -3.337, -3.306, -3.274, -3.243, -3.211, -3.179, -3.147, -3.115, -3.083, -3.05, -3.018, -2.986, -2.953, -2.92, -2.887, -2.854, -2.821, -2.788, -2.755, -2.721, -2.688, -2.654, -2.62, -2.587, -2.553, -2.519, -2.485, -2.45, -2.416, -2.382, -2.347, -2.312, -2.278, -2.243, -2.208, -2.173, -2.138, -2.103, -2.067, -2.032, -1.996, -1.961, -1.925, -1.889, -1.854, -1.818, -1.782, -1.745, -1.709, -1.673, -1.637, -1.6, -1.564, -1.527, -1.49, -1.453, -1.417, -1.38, -1.343, -1.305, -1.268, -1.231, -1.194, -1.156, -1.119, -1.081, -1.043, -1.006, -0.968, -0.93, -0.892, -0.854, -0.816, -0.778, -0.739, -0.701, -0.663, -0.624, -0.586, -0.547, -0.508, -0.47, -0.431, -0.392, -0.353, -0.314, -0.275, -0.236, -0.197, -0.157, -0.118, -0.079, -0.039, 0.0, 0.039,0.079,0.119,0.158,0.198,0.238,0.277,0.317,0.357,0.397, 0.437,0.477,0.517,0.557,0.597,0.637,0.677,0.718,0.758,0.798, 0.838,0.879,0.919,0.960,1.000,1.041,1.081,1.122,1.163,1.203, 1.244,1.285,1.326,1.366,1.407,1.448,1.489,1.530,1.571,1.612, 1.653,1.694,1.735,1.776,1.817,1.858,1.899,1.941,1.982,2.023, 2.064,2.106,2.147,2.188,2.230,2.271,2.312,2.354,2.395,2.436, 2.478,2.519,2.561,2.602 ,2.644,2.685,2.727,2.768,2.810,2.851, 2.893,2.934,2.976,3.017,3.059,3.100,3.142,3.184,3.225,3.267, 3.308,3.350,3.391,3.433,3.474,3.516,3.557,3.599,3.640,3.682, 3.723,3.765,3.806,3.848,3.889,3.931,3.972,4.013,4.055,4.096, 4.138,4.179,4.220,4.262,4.303,4.344,4.385,4.427,4.468,4.509, 4.550,4.591,4.633,4.674,4.715,4.756,4.797,4.838,4.879,4.920, 4.961,5.002,5.043,5.084,5.124,5.165,5.206,5.247,5.288,5.328, 5.369,5.410,5.450,5.491,5.532,5.572,5.613,5.653,5.694,5.735, 5.775,5.815,5.856,5.896,5.937,5.977,6.017,6.058,6.098,6.138, 6.179,6.219,6.259,6.299,6.339,6.380,6.420,6.460,6.500,6.540, 6.580,6.620,6.660,6.701,6.741,6.781,6.821,6.861,6.901,6.941, 6.981,7.021,7.060,7.100,7.140,7.180,7.220,7.260,7.300,7.340, 7.380,7.420,7.460,7.500,7.540,7.579,7.619,7.659,7.699,7.739, 7.779,7.819,7.859,7.899,7.939,7.979,8.019,8.059,8.099,8.138, 8.178,8.218,8.258,8.298,8.338,8.378,8.418,8.458,8.499,8.539, 8.579,8.619,8.659,8.699,8.739,8.779,8.819,8.860,8.900,8.940, 8.980,9.020,9.061,9.101,9.141,9.181,9.222,9.262,9.302,9.343, 9.383,9.423,9.464,9.504,9.545,9.585,9.626,9.666,9.707,9.747, 9.788,9.828,9.869,9.909,9.950,9.991,10.031,10.072,10.113,10.153, 10.194,10.235,10.276,10.316,10.357,10.398,10.439,10.480,10.520,10.561, 10.602,10.643,10.684,10.725,10.766,10.807,10.848,10.889,10.930,10.971, 11.012,11.053,11.094,11.135,11.176,11.217,11.259,11.300,11.341,11.382, 11.423,11.465,11.506,11.547,11.588,11.630,11.671,11.712,11.753,11.795, 11.836,11.877,11.919,11.960,12.001,12.043,12.084,12.126,12.167,12.209, 12.250,12.291,12.333,12.374,12.416,12.457,12.499,12.540,12.582,12.624, 12.665,12.707,12.748,12.790,12.831,12.873,12.915,12.956,12.998,13.040, 13.081,13.123,13.165,13.206,13.248,13.290,13.331,13.373,13.415,13.457, 13.498,13.540,13.582,13.624,13.665,13.707,13.749,13.791,13.833,13.874, 13.916,13.958,14.000,14.042,14.084,14.126,14.167,14.209,14.251,14.293, 14.335,14.377,14.419,14.461,14.503,14.545,14.587,14.629,14.671,14.713, 14.755,14.797,14.839,14.881,14.923,14.965,15.007,15.049,15.091,15.133, 15.175,15.217,15.259,15.301,15.343,15.385,15.427,15.469,15.511,15.554, 15.596,15.638,15.680,15.722,15.764,15.806,15.849,15.891,15.933,15.975, 16.017,16.059,16.102,16.144,16.186,16.228,16.270,16.313,16.355,16.397, 16.439,16.482,16.524,16.566,16.608,16.651,16.693,16.735,16.778,16.820, 16.862,16.904,16.947,16.989,17.031,17.074,17.116,17.158,17.201,17.243, 17.285,17.328,17.370,17.413,17.455,17.497,17.540,17.582,17.624,17.667, 17.709,17.752,17.794,17.837,17.879,17.921,17.964,18.006,18.049,18.091, 18.134,18.176,18.218,18.261,18.303,18.346,18.388,18.431,18.473,18.516, 18.558,18.601,18.643,18.686,18.728,18.771,18.813,18.856,18.898,18.941, 18.983,19.026,19.068,19.111,19.154,19.196,19.239,19.281,19.324,19.366, 19.409,19.451,19.494,19.537,19.579,19.622,19.664,19.707,19.750,19.792, 19.835,19.877,19.920,19.962,20.005,20.048,20.090,20.133,20.175,20.218, 20.261,20.303,20.346,20.389,20.431,20.474,20.516,20.559,20.602,20.644, 20.687,20.730,20.772,20.815,20.857,20.900,20.943,20.985,21.028,21.071, 21.113,21.156,21.199,21.241,21.284,21.326,21.369,21.412,21.454,21.497, 21.540,21.582,21.625,21.668,21.710,21.753,21.796,21.838,21.881,21.924, 21.966,22.009,22.052,22.094,22.137,22.179,22.222,22.265,22.307,22.350, 22.393,22.435,22.478,22.521,22.563,22.606,22.649,22.691,22.734,22.776, 22.819,22.862,22.904,22.947,22.990,23.032,23.075,23.117,23.160,23.203, 23.245,23.288,23.331,23.373,23.416,23.458,23.501,23.544,23.586,23.629, 23.671,23.714,23.757,23.799,23.842,23.884,23.927,23.970,24.012,24.055, 24.097,24.140,24.182,24.225,24.267,24.310,24.353,24.395,24.438,24.480, 24.523,24.565,24.608,24.650,24.693,24.735,24.778,24.820,24.863,24.905, 24.948,24.990,25.033,25.075,25,118,25.160,25.203,25.245,25.288,25.330, 25.373,25.415,25.458,25.500,25.543,25.585,25.627,25.670,25.712,25.755, 25.797,25.840,25.882,25.924,25.967,26.009,26.052,26.094,26.136,26.179, 26.221,26.263,26.306,26.348,26.390,26.433,26.475,26.517,26.560,26.602, 26.644,26.687,26.729,26.771,26.814,26.856,26.898,26.940,26.983,27.025, 27.067,27.109,27.152,27.194,27.236,27.278,27.320,27.363,27.405,27.447, 27.489,27.531,27.574,27.616,27.658,27.700,27.742,27.784,27.826,27.869, 27.911,27.953,27.995,28.037,28.079,28.121,28.163,28.205,28.247,28.289, 28.332,28.374,28.416,28.458,28.500,28.542,28.584,28.626,28.668,28.710, 28.752,28.794,28.835,28.877,28.919,28.961,29.003,29.045,29.087,29.129, 29.171,29.213,29.255,29.297,29.338,29.380,29.422,29.464,29.506,29.548, 29.589,29.631,29.673,29.715,29.757,29.798,29.840,29.882,29.924,29.965, 30.007,30.049,30.090,30.132,30.174,30.216,30.257,30.299,30.341,30.382, 30.424,30.466,30.507,30.549,30.590,30.632,30.674,30.715,30.757,30.798, 30.840,30.881,30.923,30.964,31.006,31.047,31.089,31.130,31.172,31.213, 31.255,31.296,31.338,31.379,31.421,31.462,31.504,31.545,31.586,31.628, 31.669,31.710,31.752,31.793,31.834,31.876,31.917,31.958,32.000,32.041, 32.082,32.124,32.165,32.206,32.247,32.289,32.330,32.371,32.412,32.453, 32.495,32.536,32.577,32.618,32.659,32.700,32.742,32.783,32.824,32.865, 32.906,32.947,32.988,33.029,33.070,33.111,33.152,33.193,33.234,33.275, 33.316,33.357,33.398,33.439,33.480,33.521,33.562,33.603,33.644,33.685, 33.726,33.767,33.808,33.848,33.889,33.930,33.971,34.012,34.053,34.093, 34.134,34.175,34.216,34.257,34.297,34.338,34.379,34.420,34.460,34.501, 34.542,34.582,34.623,34.664,34.704,34.745,34.786,34.826,34.867,34.908, 34.948,34.989,35.029,35.070,35.110,35.151,35.192,35.232,35.273,35.313, 35.354,35.394,35.435,35.475,35.516,35.556,35.596,35.637,35.677,35.718, 35.758,35.798,35.839,35.879,35.920,35.960,36.000,36.041,36.081,36.121, 36.162,36.202,36.242,36.282,36.323,36.363,36.403,36.443,36.484,36.524, 36.564,36.604,36.644,36.685,36.725,36.765,36.805,36.845,36.885,36.925, 36.965,37.006,37.046,37.086,37.126,37.166,37.206,37.246,37.286,37.326, 37.366,37.406,37.446,37.486,37.526,37.566,37.606,37.646,37.686,37.725, 37.765,37.805,37.845,37.885,37.925,37.965,38.005,38.044,38.084,38.124, 38.164,38.204,38.243,38.283,38.323,38.363,38.402,38.442,38.482,38.522, 38.561,38.601,38.641,38.680,38.720,38.760,38.799,38.839,38.878,38.918, 38.958,38.997,39.037,39.076,39.116,39.155,39.195,39.235,39.274,39.314, 39.353,39.393,39.432,39.471,39.511,39.550,39.590,39.629,39.669,39.708, 39.747,39.787,39.826,39.866,39.905,39.944,39.984,40.023,40.062,40.101, 40.141,40.180,40.219,40.259,40.298,40.337,40.376,40.415,40.455,40.494, 40.533,40.572,40.611,40.651,40.690,40.729,40.768,40.807,40.846,40.885, 40.924,40.963,41.002,41.042,41.081,41.120,41.159,41.198,41.237,41.276, 41.315,41.354,41.393,41.431,41.470,41.509,41.548,41.587,41.626,41.665, 41.704,41.743,41.781,41.820,41.859,41.898,41.937,41.976,42.014,42.053, 42.092,42.131,42.169,42.208,42.247,42.286,42.324,42.363,42.402,42.440, 42.479,42.518,42.556,42.595,42.633,42.672,42.711,42.749,42.788,42.826, 42.865,42.903,42.942,42.980,43.019,43.057,43.096,43.134,43.173,43.211, 43.250,43.288,43.327,43.365,43.403,43.442,43.480,43.518,43.557,43.595, 43.633,43.672,43.710,43.748,43.787,43.825,43.863,43.901,43.940,43.978, 44.016,44.054,44.092,44.130,44.169,44.207,44.245,44.283,44.321,44.359, 44.397,44.435,44.473,44.512,44.550,44.588,44.626,44.664,44.702,44.740, 44.778,44.816,44.853,44.891,44.929,44.967,45.005,45.043,45.081,45.119, 45.157,45.194,45.232,45.270,45.308,45.346,45.383,45.421,45.459,45.497, 45.534,45.572,45.610,45.647,45.685,45.723,45.760,45.798,45.836,45.873, 45.911,45.948,45.986,46.024,46.061,46.099,46.136,46.174,46.211,46.249, 46.286,46.324,46.361,46.398,46.436,46.473,46.511,46.548,46.585,46.623, 46.660,46.697,46.735,46.772,46.809,46.847,46.884,46.921,46.958,46.995, 47.033,47.070,47.107,47.144,47.181,47.218,47.256,47.293,47.330,47.367, 47.404,47.441,47.478,47.515,47.552,47.589,47.626,47.663,47.700,47.737, 47.774,47.811,47.848,47.884,47.921,47.958,47.995,48.032,48.069,48.105, 48.142,48.179,48.216,48.252,48.289,48.326,48.363,48.399,48.436,48.473, 48.509,48.546,48.582,48.619,48.656,48.692,48.729,48.765,48.802,48.838, 48.875,48.911,48.948,48.984,49.021,49.057,49.093,49.130,49.166,49.202, 49.239,49.275,49.311,49.348,49.384,49.420,49.456,49.493,49.529,49.565, 49.601,49.637,49.674,49.710,49.746,49.782,49.818,49.854,49.890,49.926, 49.962,49.998,50.034,50.070,50.106,50.142,50.178,50.214,50.250,50.286, 50.322,50.358,50.393,50.429,50.465,50.501,50.537,50.572,50.608,50.644, 50.680,50.715,50.751,50.787,50.822,50.858,50.894,50.929,50.965,51.000, 51.036,51.071,51.107,51.142,51.178,51.213,51.249,51.284,51.320,51.355, 51.391,51.426,51.461,51.497,51.532,51.567,51.603,51.638,51.673,51.708, 51.744,51.779,51.814,51.849,51.885,51.920,51.955,51.990,52.025,52.060, 52.095,52.130,52.165,52.200,52.235,52.270,52.305,52.340,52.375,52.410, 52.445,52.480,52.515,52.550,52.585,52.620,52.654,52.689,52.724,52.759, 52.794,52.828,52.863,52.898,52.932,52.967,53.002,53.037,53.071,53.106, 53.140,53.175,53.210,53.244,53.279,53.313,53.348,53.382,53.417,53.451, 53.486,53.520,53.555,53.589,53.623,53.658,53.692,53.727,53.761,53.795, 53.830,53.864,53.898,53.932,53.967,54.001,54.035,54.069,54.104,54.138, 54.172,54.206,54.240,54.274,54.308,54.343,54.377,54.411,54.445,54.479, 54.513,54.547,54.581,54.615,54.649,54.683,54.717,54.751,54.785,54.819, 54.852,54.886] #Note this assumes a Rev A Raspberry Pi change to SMBus(1) for a Rev B bus = smbus.SMBus(1) #Set up the root window geometries root = Tk() root.geometry("375x130+200+200") root.resizable(0,0) #Set variables Sensors = [ 'LM75 Raspberry Pi', 'Thermocouple Raspberry pi','EOF'] Senselect=IntVar() chk= IntVar() Unit="Deg C" logtofile=0 SampleInterval=0 SampleNum=0 Interval = StringVar() Fname = StringVar() Timex =100 Tempmin=20 Tempmax=25 elapsedtime=0 tick = 1 Start = False i=0 #Version Definition def About(): tkMessageBox.showinfo("About","Pilogger v1.0\n") #Clear window after data entry has taken place def Clearwindow(): Radio1.grid_remove() Radio2.grid_remove() Label1.grid_remove() Label2.grid_remove() Label3.grid_remove() Label4 = Label(root, text = " ") Label4.grid(row=4,column=1,sticky=W) Label5 = Label(root, text = " ") Label5.grid(row=5,column=1,sticky=W) Logbutton.grid_remove() c.grid_remove() #Update root window def Task(): root.update() #Operates after log button has been pressed def Startlog(): global Sen global Senselect global Timex global Tempmax global Tempmin global i global temp_y global Start global tick global elapsedtime global Oldtime global logtofile global filename global a Sen = Senselect.get() SampleInterval= Interval.get() try: SampleInterval= int(SampleInterval) if (SampleInterval < 1): tkMessageBox.showerror("Error","Enter an integer number higher than 1") Start = False return else: Start = True except: tkMessageBox.showerror("Error","Enter an integer number higher than 1") Start = False return if (Start == True): tick = int(SampleInterval) filename = Fname.get() logtofile=chk.get() Clearwindow() return def GetData(): global Sen if (Sen==0): ReadLM75() if (Sen==1): ReadThermocouple() def Setup_ADC(): i=0 # issue a Reset to all registers GPIO.output(RESET, True) GPIO.output(RESET, False) time.sleep(0.2) GPIO.output(RESET, True) # Setup the Communications Register GPIO.output(CS, True) GPIO.output(SCLK, True) #Start CLK High GPIO.output(CS, False) commandout = 0x13 # Set to Gain = 128 Select Setup Register for next write for i in range(8): if (commandout & 0x80): GPIO.output(DIN, True) else: GPIO.output(DIN, False) commandout <<= 1 GPIO.output(SCLK, False) GPIO.output(SCLK, True) GPIO.output(CS, True) commandout = 0x6A # Do Calibration GPIO.output(CS, False) for i in range(8): if (commandout & 0x80): GPIO.output(DIN, True) else: GPIO.output(DIN, False) commandout <<= 1 GPIO.output(SCLK, False) GPIO.output(SCLK, True) GPIO.output(CS, True) while True: if (GPIO.input(DRDY) == False): print GPIO.input(DRDY) break def ReadThermocouple(): global i global temp_y global Tempmax global Tempmin global Timex global SampleNum GPIO.setmode(GPIO.BCM) # change these as desired - they're the pins connected from the # Raspberry pi to the AD7715 global RESET global SCLK global DRDY global DOUT global DIN global CS RESET = 7 SCLK = 8 DRDY = 25 DOUT = 24 DIN = 23 CS = 18 # set up the Interface Pins #GPIO.setwarnings(False) GPIO.setup(CS, GPIO.OUT) GPIO.setup(RESET, GPIO.OUT) GPIO.setup(DOUT, GPIO.IN) GPIO.setup(DRDY, GPIO.IN) GPIO.setup(SCLK, GPIO.OUT) GPIO.setup(DIN, GPIO.OUT) bus = smbus.SMBus(1) Setup_ADC() GPIO.output(CS, True) GPIO.output(SCLK, True) #Start CLK High GPIO.output(CS, False) commandout = 0x3B # Set up the communications register to read the ADC result for c in range(8): if (commandout & 0x80): GPIO.output(DIN, True) else: GPIO.output(DIN, False) commandout <<= 1 GPIO.output(SCLK, False) GPIO.output(SCLK, True) GPIO.output(CS, True) GPIO.output(CS, True) GPIO.output(SCLK, True) #Start CLK High GPIO.output(CS, False) adc_result = 0 # Do a 16 bit read from the ADC for b in range(16): GPIO.output(SCLK, False) GPIO.output(SCLK, True) adc_result <<=1 if (GPIO.input(DOUT)): adc_result |=0x1 GPIO.output(CS, True) millivolts = (((adc_result * 2500)/float(65536)) -1250) millivolts = millivolts / float(128) millivolts = "%.2f" % millivolts a=0 data = bus.read_i2c_block_data(0x48, 0) TempMSB = data[0] TempLSB = data[1] temp_y = (((TempMSB << 8) | TempLSB) >>7) * 0.5 if temp_y > 125: temp_y =(((((TempMSB << 8) | TempLSB) >>7) * 0.5) -256) Coldjunction = int(temp_y) ADC_COMP = float(millivolts) for a in range(1000): if(Temperature[a] >= ADC_COMP): temp_y = a break print a temp_y = (int(temp_y)-270) + Coldjunction if temp_y > Tempmax: Tempmax = temp_y + 2 if temp_y < Tempmin : Tempmin = temp_y - 2 if i > Timex * 0.75: Timex= i * 1.2 print i print temp_y SampleNum=SampleNum+1 print SampleNum def ReadLM75(): global i global temp_y global Tempmax global Tempmin global Timex global SampleNum data = bus.read_i2c_block_data(0x48, 0) TempMSB = data[0] TempLSB = data[1] temp_y = (((TempMSB << 8) | TempLSB) >>7) * 0.5 if temp_y > 125: temp_y =(((((TempMSB << 8) | TempLSB) >>7) * 0.5) -256) if temp_y > Tempmax: Tempmax = temp_y + 2 a.set_ylim([Tempmin,Tempmax]) if temp_y < Tempmin : Tempmin = int(temp_y) - 2 a.set_ylim([Tempmin,Tempmax]) if i > Timex * 0.75: Timex= i * 1.2 a.set_xlim([0,Timex]) SampleNum=SampleNum+1 def _quit(): root.quit() # stops mainloop root.destroy() # this is necessary on Windows to prevent # Fatal Python Error: PyEval_RestoreThread: NULL tstate def Logdata(): global SampleNum global Temp_y global Unit now = time.localtime(time.time()) if (logtofile == 1): fo = open(filename,"a") if(SampleNum == 0): fo.write("Sample Number,Time,Reading,Units\n") SampleNumstr = str(SampleNum) fo.write(SampleNumstr) fo.write(",") fo.write(time.strftime("%T",now)) fo.write(",") Data = str(temp_y) fo.write(Data) fo.write(",") fo.write(Unit) Unit = str(Unit) fo.write("\n") fo.close root.title("PiLogger") #Set up menus menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_separator() filemenu.add_command(label="Exit", command=_quit) helpmenu = Menu(menu) menu.add_cascade(label="Help", menu=helpmenu) helpmenu.add_command(label="About...", command=About) #Set up main Gui to get text entry Label1=Label(root,text="Choose a sensor: ") Label1.grid(row=1,column=1,sticky=W) Label2=Label(root,text="LM75 RasPi") Label2.grid(row=2,column=1,sticky=W) Radio1=Radiobutton(root,text = "",justify = RIGHT,variable=Senselect,value=0) Radio1.grid(row=2,column=2,sticky=W) Label3=Label(root,text="Thermocouple") Label3.grid(row=3,column=1,sticky=W) Radio2=Radiobutton(root,text = "",justify = RIGHT,variable=Senselect,value=1) Radio2.grid(row=3,column=2,sticky=W) Label4 = Label(root, text = "Enter Sample Period (Secs) :") Label4.grid(row=4,column=1,sticky=W) E1 = Entry(root, textvariable = Interval,width=5) E1.grid(row=4,column=2,sticky=W) Label5 = Label(root, text = "Enter filename :") Label5.grid(row=5,column=1,sticky=W) E2 = Entry(root,textvariable = Fname,width=10) E2.grid(row=5,column=2,sticky=W) c = Checkbutton(root, text ="Log to file", variable = chk) c.grid(row=5,column=3) Logbutton=Button(root,text='Log',command = Startlog) Logbutton.grid(row=6,column=3) while 1: Task() if(Start == True): LabelString = "Sensor : " + Sensors[Sen] Label (root,text=LabelString,justify=LEFT).grid(row = 1,column =1,sticky=W) SampleInterval=str(tick) LabelString = "Sample Period(Secs): " + SampleInterval Label (root,text=LabelString,justify=LEFT).grid(row = 2,column =1,sticky=W) if (logtofile==1): LabelString = "Logging to File : " + filename Label (root,text=LabelString,justify=LEFT).grid(row = 3,column =1,sticky=W) f = Figure(figsize=(4,3), dpi=100) a = f.add_subplot(111) a.set_xlim([0,Timex]) a.set_ylim([Tempmin,Tempmax]) GetData() LabelString = "Sample Nos : " + str(SampleNum) Label (root,text=LabelString,justify=LEFT).grid(row = 1,column =3,sticky=W) LabelString = "Last Sample : " + str(temp_y) + " " + Unit Label (root,text=LabelString,justify=LEFT).grid(row = 2,column =3,sticky=W) a.scatter(i,temp_y,color='red') canvas = FigureCanvasTkAgg(f, master=root) canvas.get_tk_widget().grid(row=4,column=1,columnspan=4,rowspan = 12) canvas.show() if (logtofile == 1): Logdata() i=i+tick Oldtime = time.time() while(Start == True) : root.geometry("450x375") root.resizable(0,0) if elapsedtime > tick: Oldtime = time.time() elaspedtime = tick GetData() LabelString = "Sample Nos : " + str(SampleNum) Label (root,text=LabelString,justify=LEFT).grid(row = 1,column =3,sticky=W) LabelString = "Last Sample : " + str(temp_y) + " " + Unit Label (root,text=LabelString,justify=LEFT).grid(row = 2,column =3,sticky=W) a.set_xlim([0,Timex]) a.set_ylim([Tempmin,Tempmax]) a.scatter(i,temp_y,color='red') canvas.show() if (logtofile==1): Logdata() i=i+tick Currenttime = time.time() elapsedtime = Currenttime - Oldtime Task()