Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1246

Python • Converting w1thermsensor outputs to variables

$
0
0

Code:

from w1thermsensor import W1ThermSensorimport timewhile True:    localtime = time.asctime( time.localtime(time.time()))    print(localtime)    for sensor in W1ThermSensor.get_available_sensors():        print(f"Sensor {sensor.id} has temperature {sensor.get_temperature()}C")    print('\n')    time.sleep(1800)
I use the above code to display temperature from 2 DS18B20 sensors and it works very well.
However, I would like to be able to plot the results and have more control over the output, which sometimes prints out with multiple Decimal places.
Is anyone able to advise me how to copy the output to a normal variable so that I can then store the results in an array. I currently have 2 sensors but in the future I want to be able to add more sensors, so the code needs to be able to cope with as many sensors as are connected.
Thank you

Statistics: Posted by RDS — Sat Mar 30, 2024 5:58 pm



Viewing all articles
Browse latest Browse all 1246

Trending Articles