Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help creating a loop
#1
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)
Reply


Messages In This Thread
Need help creating a loop - by codingnewbie - Jul-17-2019, 04:02 PM
RE: Need help creating a loop - by Yoriz - Jul-18-2019, 11:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,539 Jul-27-2022, 08:50 PM
Last Post: rob101
  creating a loop yk303 2 1,885 Feb-08-2021, 08:41 PM
Last Post: nilamo
  Creating a variables inside FOR loop zazas321 5 4,145 Sep-16-2020, 04:42 PM
Last Post: Naheed
  Need help creating complex loop around existing script CephloRhod 5 2,809 Apr-16-2020, 01:23 PM
Last Post: deanhystad
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 1,379 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  Question about for loop not creating an infinite loop. FWendeburg 1 2,137 Feb-03-2019, 08:45 PM
Last Post: ichabod801
  I need help with loop one function and creating variables don 3 2,837 Jan-24-2019, 07:31 AM
Last Post: buran
  Creating a variable in for loop dan789 9 4,222 Dec-19-2018, 06:23 PM
Last Post: nilamo
  Creating multiple lists from file without long for loop Curtnos 2 4,491 Jan-28-2018, 09:11 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020