davidanddiesel
Posts: 15
Joined: Sun Jan 18, 2015 4:03 am

Store beginning data?

Sat Feb 14, 2015 2:24 am

I am creating a temperature monitor with a BMP085 temperature sensor/barometer. It's working fine. But now I want the program to store the starting temperature and pressure as startpress and starttemp. When a keyboard interrupt is issued,I want the program to print the end temperature/pressure as endtemp and endpress. This is what I have so far (including what I need help on):

Code: Select all


import time
import colorama
from colorama import *
import Adafruit_BMP.BMP085 as BMP085
sensor = BMP085.BMP085()
colorama.init()
starttemp= MAKE THIS A CONSTANT WITH THE STARING TEMP
startpress = MAKE THIS A CONSTANT WITH STARTING PRESSURE
for i in range(0,6):
        print('\n')
try:
        while True:
                temp = sensor.read_temperature()
                pressure = sensor.read_pressure()

                tp = "Temp: %.2f *F" % ((temp * 1.8) + 32)
                pp = "Pressure: %.2f millibars" % (pressure / 100.0)
                p1 = str(pp)
                t1 = str(tp)
                print(Fore.MAGENTA + p1)
                print(Fore.BLUE + t1 + '\n\n\n\n\n\n\n\n\n\n' + Style.RESET_ALL)
                time.sleep(3)

except KeyboardInterrupt:
        ENDTEMP = The ending temp which I need made
        ENDPRESS = the ending pressure which I need made

        print starttemp
        print startpress
        print endtemp
        print endpress

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Store beginning data?

Sat Feb 14, 2015 2:42 am

You need to read the temperature and pressure once to be able to establish the starting values.

You could try something like this:

Code: Select all

    import time
    import colorama
    from colorama import *
    import Adafruit_BMP.BMP085 as BMP085
    sensor = BMP085.BMP085()
    colorama.init()
    starttemp= None
    startpress = None
    for i in range(0,6):
            print('\n')
    try:
            while True:
                    temp = sensor.read_temperature()
                    pressure = sensor.read_pressure()

                    if starttemp is None:
                        starttemp=temp
                    if startpress is None:
                        startpress=pressure

                    tp = "Temp: %.2f *F" % ((temp * 1.8) + 32)
                    pp = "Pressure: %.2f millibars" % (pressure / 100.0)
                    p1 = str(pp)
                    t1 = str(tp)
                    print(Fore.MAGENTA + p1)
                    print(Fore.BLUE + t1 + '\n\n\n\n\n\n\n\n\n\n' + Style.RESET_ALL)
                    time.sleep(3)

    except KeyboardInterrupt:
            ENDTEMP = temp
            ENDPRESS = pressure

            print starttemp
            print startpress
            print endtemp
            print endpress

Return to “General discussion”