• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Array Help

Q&A Forum › Category: ESP32 › Array Help
0 Vote Up Vote Down
self.raymond asked 5 years ago

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)
4 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
self.raymond answered 5 years ago

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

0 Vote Up Vote Down
Steph answered 5 years ago
>>> 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] >>>
0 Vote Up Vote Down
self.raymond answered 5 years ago

Thank You

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.