What I am trying to do is sample a group of 5 temp reading and get the average reading of those 5.
This statement Pool_Temp = [60, 95]I thought I could use a an array to include all numbers
from 60-95. For some reason it shows up as a print statement. Thank You for your help
import machine
import onewire
import ds18x20
import time
ds_pin = machine.Pin(4)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
roms = ds_sensor.scan()
# print('Found DS devices: ', roms)
temperatures = []
ds_sensor.convert_temp()
time.sleep_ms(750)
for rom in roms:
# print(rom)
# print(ds_sensor.read_temp(rom))
temperatures.append(ds_sensor.read_temp(rom))
time.sleep(.750)
while True:
temperature1 = temperatures[0]
Solar_Temp = temperature1 * (9 / 5) + 32.0
print('Solar')
print(Solar_Temp)
time.sleep(2)
# print (temperature1)
temperature2 = temperatures[1]
Pool_Temp = temperature2 * (9 / 5) + 32.0 # Ist on temp block
Pool_Temp = [60, 95]
Pool_Temp_last_five = Pool_Temp[-5:]
#print (pool_temp_last_five)
avg_Pool_Temps = sum(Pool_Temp_last_five)/len(Pool_Temp_last_five)
print ('Avg Pool Temp')
print(avg_Pool_Temps)
print('Pool')
print(Pool_Temp)
print('Pool')
#print(Pool_Temp)
time.sleep(1)
Hi Ray.
You want to create an array to store how many temperature values? Are those values from the same sensor or from different sensors?
Pool_Temp = [60, 95] creates an array with two numbers: 60 and 95
Regards,
Sara
I am trying to create an array of multiply numbers. I know I can just list all the numbers to be poll. But I was trying to list a range of number like between 75 to 100. After giving some more thought the pool numbers do not have to be poll just the solar numbers. They will fluctuate a lot more than the pool temp. The Pool_Temp = [60, 95] shows up when I print the temps. It I take the Pool_Temp = [60, 95] the code stops running???? Thanks as always for your help
>>> import random >>>
>>> # simple random draw >>> l = [random.randint(75,100) for i in range(20)] >>> l [87, 99, 85, 100, 97, 94, 85, 97, 87, 96, 87, 98, 78, 99, 82, 80, 93, 88, 81, 96] >>>
>>> # without repetitions >>> l = random.sample(range(75,100), 20) >>> l [87, 80, 96, 76, 82, 85, 83, 81, 92, 88, 94, 97, 91, 86, 99, 95, 78, 79, 75, 77] >>>