![]() |
Need help creating a loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help creating a loop (/thread-19863.html) |
Need help creating a loop - codingnewbie - Jul-17-2019 Hey everyone so I need help creating a loop, Im trying to get temperature with 2 DS18B20 temperature sensors with a Raspberry Pi. So far I have managed to read a display temperature but only once, Ive been trying to turn it into a loop however I have no clue where to even start. Ill post the code Im using below, hopefully someone can help. import os import glob import time import datetime import RPi.GPIO as iO import os,subprocess from subprocess import call from w1thermsensor import W1ThermSensor from Adafruit_IO import * aio = Client(x,x')#UserID and KEY os.system('modprobe w1-gpio') os.system('modprobe w1-therm') mySensor = W1ThermSensor() # ------------------------------------- # Define sensors by ID sensorID_Case = "00000a99ccc8" sensorID_Shed = "000009171ec6" for mySensor in W1ThermSensor.get_available_sensors(): curSensorID = mySensor.id curTemp = mySensor.get_temperature() curTemp = round(curTemp,1) if curSensorID == sensorID_Case: myTempCase = curTemp print("Top=" + str(myTempCase*1.8+32)) elif curSensorID == sensorID_Shed: myTempShed = curTemp print("Bottom=" + str(myTempShed*1.8+32)) else: print("Unexpected SensorID=" + curSensorID) myTimeStamp = datetime.datetime.now().strftime("%Y-%m-%d@%H:%M:%S") print(curSensorID + " Temp = " + str(curTemp) + " at " + datetime.datetime.now().strftime("%Y-%m-%d %H%M%S")) aio.send("top-temperature", myTempCase*1.8+32) aio.send("bottom-temperature", myTempShed*1.8+32) RE: Need help creating a loop - Yoriz - Jul-18-2019 If you want an infinite loop you can use the following while True: $$ looped code goes here break can be used to exit the loop
|