def sample(channel): """ Callback function for button interrupt that causes a sample to be taken from both sensors. """ time.sleep(0.1) print("Button pushed!") DAQC.getINTflags(0) # clear the interrupt # use light strobes to indicate measurement DAQC.setDOUTall(0, 0) for j in range(7): DAQC.setDOUTbit(0, j) time.sleep(0.1) DAQC.clrDOUTbit(0, j) time.sleep(0.1) # measure from the BME280 (ORDER MATTERS!) temp = sensor.read_temperature() pressure = sensor.read_pressure() / 100. # convert to hectopascals humidity = sensor.read_humidity() t = sensor.t_fine # measure from the (analog) photo-sensor light = DAQC.getADC(0, 0) global data data.append([t, temp, pressure, humidity, light]) # turn off LEDs DAQC.setDOUTall(0, 0)
def task(): global lastT global lastR global lastSW global swMode global GC adata = DAQC.getADCall(3) val = round(DAQC.getADC(0, 8), 1) Power5Text.set(val) val = round((adata[1] - 2.73) * 100, 2) val = 0.2 * val + 0.8 * lastT lastT = val TempText.set(str("{:>3.1f}".format(val)) + 'C') val = round(adata[2] * 12.21 / 1.636, 1) Power12Text.set(val) val = round(adata[0] / 4.096 * 100, 1) FanText.set(str(val) + '%') DAQC.setPWM(0, 0, int(val * 1024 / 100)) val = DAQC.getRANGE(0, 6, 'c') if isinstance(val, float): if val > 100: val = 99.9 else: val = 0 val = round(val, 1) val = 0.8 * lastR + 0.2 * val lastR = val RangeText.set(str("{:>2.1f}".format(val)) + 'cm') lamp = 0 if (DAQC.getDINbit(0, 2) == 1): lamp = 32 sw = DAQC.getSWstate(0) if (sw == 1) and (lastSW == 0): lastSW = 1 swMode = not swMode if swMode: GCmode.set('Binary Code :') else: GCmode.set('Grey Code :') if (sw == 0) and (lastSW == 1): lastSW = 0 val = (int(adata[7] * 32 / 4.096)) if swMode == 0: GCText.set(GC[val]) num = GC[val] else: GCText.set(val) num = val DAQC.setDOUTall(0, (num + lamp)) root.after(100, task)
def task(): global logFile, lfOpen, Logging, streamOpen, fName, SampleC, SampleT, logHeader global theta, dnum aChannelCount = 0 dChannelCount = 0 try: SampleT = float(SamplePeriod.get()) if (SampleT < SampleTmin): SampleT = SampleTmin except ValueError: SampleT = SampleTmin root.after(int(SampleT * 1000), task) logString = '' dTypes = '' j = 0 for i in range(0, 8): #for boards 0 through 8 a2dvals = range(8) dinvals = range(8) if (DAQCpresent[i] == 1): #Test Signal Generation if (DoutSignal.get() == 1): dnum[i] = (dnum[i] + 1) % 128 DAQC.setDOUTall(i, dnum[i]) if (AoutSignal.get() == 1): theta[i] = (theta[i] + 1) % 360 rad = math.radians(theta[i]) dacval = 2.048 * (1 + math.sin(rad)) dacval2 = 2.048 * (1 + math.sin(2 * rad)) DAQC.setDAC(i, 0, dacval) DAQC.setDAC(i, 1, dacval2) #Retrieve and plot values a2dvals = daqc[i].a2dupdate() dinvals = daqc[i].dinupdate() #Convert data to strings for log for k in range(8): if (a2dvals[k] != ''): logString = logString + str(a2dvals[k]) + ',' aChannelCount += 1 dTypes = dTypes + 'a,' for k in range(8): if (dinvals[k] != ''): logString = logString + str(dinvals[k]) + ',' dChannelCount += 1 dTypes = dTypes + 'd,' dtypes = dTypes[:-1] logString = logString[:-1] logString = time.strftime("%H:%M:%S", time.localtime()) + ',' + logString if (Logging and lfOpen): #logString = logString[:-1] #logString = time.strftime("%H:%M:%S",time.localtime())+','+logString logFile.write(logString) logFile.write('\n') if (Logging and streamOpen): headerList = logHeader.split(",") #logString = logString[:-1] dataList = logString.split(",") typeList = dTypes.split(",") #print aChannelCount, dChannelCount, aChannelCount+dChannelCount for i in range(0, aChannelCount + dChannelCount): k = i + 1 if (typeList[i] == 'a'): streamer.log(headerList[k], float(dataList[k])) #print i,typeList[i],headerList[k],float(dataList[k]) else: if (dataList[k] == '0'): streamer.log(headerList[k], "false") #print i,typeList[i],headerList[k], 'false' else: streamer.log(headerList[k], "true") #print i,typeList[i],headerList[k], 'true' if (Logging): SampleC -= 1 root.wm_title("DAQCplate Data Logger - LOGGING - " + str(SampleC) + " Samples and " + str(SampleT * SampleC) + " Seconds Remaining") if (SampleC == 0): StopLog() try: updateSheets() StartLog() #showinfo("Logging","Logging Complete") except: shutDown()
notebook = Pmw.NoteBook(root, borderwidth=2, pagemargin=2) notebook.pack(fill='both', expand=1) DAQCpresent = range(8) daqc = range(8) DAQCFoundCount = 0 #daqcpage=range(8) SampleTmin = 0 for i in range(0, 8): rtn = DAQC.getADDR(i) if ((rtn - 8) == i): DAQCpresent[i] = 1 DAQCFoundCount += 1 DAQC.setDOUTall(i, 0) DAQC.setPWM(i, 0, 0) DAQC.setPWM(i, 1, 0) page = notebook.add('DAQC' + str(i)) notebook.tab('DAQC' + str(i)).focus_set() daqc[i] = daqcDASH(page, i) SampleTmin += 0.2 else: DAQCpresent[i] = 0 if (SampleTmin > 0): SampleT = SampleTmin else: SampleT = 0.2 SamplePeriod = StringVar()
if ColdState == 0: daqc.clrDOUTbit(0,0) #Hot Off daqc.setDOUTbit(0,1) #Cold On HotState = 0 ColdState = 1 Toggled = 1 elif Temp < MinTemp: if HotState == 0: daqc.setDOUTbit(0,0) #Hot On daqc.clrDOUTbit(0,1) #Cold Off HotState = 1 ColdState = 0 Toggled = 1 else: if (ColdState == 1) or (HotState == 1): daqc.setDOUTall(0,0) #all Off HotState = 0 ColdState = 0 Toggled = 1 #update Last Run if Toggled == 1: lrf = open("{0}/last.run".format(PID_PATH), 'w') lrf.write("{0}".format(now)) lrf.close() #Update curr.data, then sleep for 1 seconds out = open("{0}/curr.data".format(PID_PATH), 'w') out.write("{0},{1},{2},{3},{4},{5},{6}".format(InputVoltage, MainAmps, HotAmps, ColdAmps, Temp, HotState, ColdState)) out.close() time.sleep(1)