May-20-2018, 04:28 PM
Hi All,
I have concocted a piece of coding to read and log temperatures from DS18B20 sensors.
I use the following to read the multiple sensors:
How can i make the program continue without intervention?
Any comments on the construction of the function are also welcomed.
Rgds Steffen
I have concocted a piece of coding to read and log temperatures from DS18B20 sensors.
def read_ds18b20(sensorid): #Functon reads DS15B20 sensor tfile = open("/sys/bus/w1/devices/"+ sensorid +"/w1_slave") text = tfile.read() # Close file after reading it. tfile.close() # Select 21st word starting from 0. sensor_data =text.split(" ")[20] # Remove 't=' and make floating. temp_raw = float(sensor_data[2:]) #print (temp_raw) temp = temp_raw / 1000 digitemp = '%.1f' % temp #round to 1 decimal #print ("digitemp = " + digitemp) return digitempThe ID's (like 28-000009adc801) of the sensors appear as files in /sys/bus/w1/devices/ .
I use the following to read the multiple sensors:
# Execute DS18B20 function for sensor ID's below. temp1 = float(read_ds18b20('28-000009aeba12')) #Motor 1 temp. temp2 = float(read_ds18b20('28-000009aeba12')) #Motor 2 temp. temp3 = float(read_ds18b20('28-000009adc801')) #outside temp.If there is a change of motor and thus another sensor id, the program halts with "file not found" because the new ID has no file in /sys/bus/w1/devices/.
How can i make the program continue without intervention?
Any comments on the construction of the function are also welcomed.
Rgds Steffen