Variables in a loop, Newby question
torriem at gmail.com
Thu Dec 26 07:34:13 CET 2013
On 12/24/2013 11:27 AM, vanommen.robert at gmail.com wrote:
> Indeed this is code what I found on the web to read temperatures from
> 10 DS18B20 singlewire sensors.
> My only programming (little) experience is VBA (Excel mostly).
Definitely you'll want to learn python before you go much farther in
this project. Check out the online docs, tutorials, etc.
> In this script i want to read the temperatures and make them
> available to other scripts.
Here's some almost runnable code that might help you get down the right
track. You'll have to fill in some of the stuff.
sensorids = [...] #fill in these with your ids
# open /sys/bus/w1/deevices/id/slave
text = ''
while text.split("\n").find("YES") == -1:
tfile = open("/sys/bus/w1/devices/"+ id +"/w1_slave")
text = tfile.read()
temperaturedata = text.split("\n").split(" ")it(" ")
temperature = float(temperaturedata [2:]) / 1000
# not using list comprehensions but we could
temps = 
for sensor in sensorids:
Then in your other python modules (scripts):
print temperatures.get_temperatures() # should print a list
Hope this gives you a bit of structure you can use. All the code you
need to fill in can come from the code you posted previously.
More information about the Python-list