EnviopHAT analogue values


#1

I’ve been wanting to try out my TMP36’s with the EnviropHAT, though can’t get it to spit out a correct temperature.

I’ve taken the all.py example and modified it to suit, though having difficulty converting the analog value to millivolts for some reason.

#!/usr/bin/env python

from envirophat import light, weather, motion, analog
import time
import sys

def write(line):
    sys.stdout.write(line)
    sys.stdout.flush()

write("--- Enviro pHAT Monitoring ---")

try:
    while True:
        analog_values = analog.read_all()                       # reads all 4 inputs

        millivolts = analog_values[0] * (3300.0 / 1024) # eg. 0.728 =
       # 10 mv per degree
        temp_C = ((millivolts - 100.0) / 10.0) - 40.0
       # convert celsius to fahrenheit
        temp_F = (temp_C * 9.0 / 5.0) + 32
        # remove decimal point from millivolts
        millivolts = "%d" % millivolts
        # show only one decimal place for temprature and voltage readings
        temp_C = "%.1f" % temp_C
        temp_F = "%.1f" % temp_F

        output = """

Temp (onboard): {t1}c
Temp (TMP36)  : {t2}c
Analog: 0: {a0}
Analog: 1: {a1}
Analog: 2: {a2}
Analog: 3: {a3}
""".format(
        t1 = round(weather.temperature(),2),
        t2 = temp_C,
        a0 = analog_values[0],
        a1 = analog_values[1],
        a2 = analog_values[2],
        a3 = analog_values[3]
    )
        output = output.replace("\n","\n\033[K")
        write(output)
        lines = len(output.split("\n"))
        write("\033[{}A".format(lines - 1))

        time.sleep(1)

except KeyboardInterrupt:
    pass

Can anyone shed any light onto this?

Cheers


#2

You should only need to multiply the output values, which are in volts, by 1000 to obtain millivolts.


#3

I did think of that and discounted it as everywhere I’d read about using the TMP36 had the other equation. Perhaps becsuse they were using the MSP30xx (something like that).

Anyway, thanks very much, worked a treat!