May-21-2018, 03:58 PM
Thanks everybody and my apologies for the confusion caused by my unfamiliarity with the BB.
I got the problem solved with thanks to killirrex for putting me on the right track.
The whole scripot now looks like:
Should i do that in the same script or write a new one and somehow point it??
Tks Steffen
I got the problem solved with thanks to killirrex for putting me on the right track.
The whole scripot now looks like:
#!/usr/bin/env python #Versie 2.3; 21mei2018 #Dit programma leest elke sensor apart uit en slaat aan het einde #de resultaten op in een csv file. #Importeer benodigde libraries. #21/05File not found opgelost. import sys import time import csv import os import spidev import RPi.GPIO as GPIO spi = spidev.SpiDev() spi.open(0,0) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(22,GPIO.IN) GPIO.setup(27,GPIO.OUT) GPIO.setup(23,GPIO.OUT) GPIO.setup(24,GPIO.OUT) GPIO.setup(25,GPIO.OUT) def read_MCP(sensorid): #Function reads MCP3008. adc = spi.xfer2([1,(8+sensorid)<<4,0],20000) adcread = ((adc[1]&3) << 8) + adc[2] return adcread def read_ds18b20(sensorid): #Function reads DS18B20 sensor. device="/sys/bus/w1/devices/"+ sensorid +"/w1_slave" try: with open (device) as tfile: text=tfile.read() except FileNotFoundError: GPIO.output(25,True) notemp = 9999 return notemp sensor_data =text.split(" ")[20] #Select 21st word start with zero. # Haal 't=' weg en maak floating temp_raw = float(sensor_data[2:]) #Remove 'T="and make floating. #print (temp_raw) temp = temp_raw digitemp = '%.1f' % temp #Round to one decimal. return digitemp datum = (time.strftime('%d/%m/%Y')) # Define date/time variables. tijd = (time.strftime('%H:%M:%S')) GPIO.output(25,False) #reset FileNotFound LED while True: while True: time.sleep(1) if GPIO.input(22): #Contact key is ON GPIO.output(27,True) #Turn on LED indicator. break else: #Contact key is dus OFF GPIO.output(27,False) #LED indicator OFF print ('Schakelaar is UIT') # Checked water level BB with key OFF #Check watersensor SB, channel0 of ADC. level = read_MCP(0) level_SB = round(level,1) print (level_SB) # Turn on the SB pump if value > 510. if (level_SB) > 510: GPIO.output(23,GPIO.HIGH) #LED/pomprelais SB ON. else: GPIO.output(23,GPIO.LOW) #LED/pomprelais SB OFF. #Check watersensor BB, channel1 of ADC. level =read_MCP(1) level_BB= round(level,1) print (level_BB) # Turn on the BB pump if value > 510 if (level) > 510: GPIO.output(24,GPIO.HIGH) #LED/pomprelais BB ON. else: GPIO.output(24,GPIO.LOW) #LED/pomprelais BB OFF. # Exec DS18B20 function for sensorID's below. temp1 = float(read_ds18b20('28-000009aeba12')) #Motor 1 temp2 = float(read_ds18b20('28-000009aeba12')) #Motor 2 temp3 = float(read_ds18b20('28-000009adc801')) #Buitentemperatuur # Define 'lijst'. lijst = [0,0,0,0,0,0,0,0] # Exec function 'read_temp36' for each ADC channel. for offset in range(0,8): adcread = read_MCP(offset) print (adcread) result = (adcread*330)/float(1024) lijst[offset] = adcread offset +=1 #Decrease offset by 1 data = [datum,tijd,temp1,temp2,temp3,round(lijst[0],1),round(lijst[1],1),round((((lijst[2]*3.3/1024)-0.52)/0.08),1),round((((lijst[3]*3.3/1024)-0.52)/0.08),1)] # lijst 0 is watersensor SB, lijst 1 is idem BB, lijst 3 is stroom SB, lijst 4 is stroom BB # Turn on the SB pump if value > 510. if (lijst[0]) > 510: GPIO.output(23,GPIO.HIGH) #LED/pomprelais SB ON else: GPIO.output(23,GPIO.LOW) #LED/pomprelais SB ON # Turn on the BB pump if value > 510. if (lijst[1]) > 510: GPIO.output(24,GPIO.HIGH) #LED/pomprelais BB ON else: GPIO.output(24,GPIO.LOW) #LED/pomprelais BB ON print (data) #Output naar csv file #csvfile = "/home/pi/programs/testdata.csv" #with open (csvfile,'a') as output: # writer = csv.writer(output, delimiter = ',' ,lineterminator = '\n') # writer.writerow(data) time.sleep(0.5)Now i will try to get a 4 x 20 LCD screen incorporated to display various values.
Should i do that in the same script or write a new one and somehow point it??
Tks Steffen