I'm building a temperature controller using ESP32s and industrial PT100 temperature transmitters.
The transmitter I'm using is this:
https://www.titec-gmbh.de/wp-content/up ... _de_en.pdf
It has selectable temperature ranges and outputs 1-10V according to the temperature read from the PT100.
I have selected the range -20C to 120C and made a voltage divider to lower the output down to something between 0 - 1.803V.
I have 3 issues:
- I don't seem to get stable readings:
I have selected 6db attenuation and 11 bit width as described here: https://esp32.com/viewtopic.php?f=19&t=2881&start=10 to try to address the fluctuations (also made sure my voltage divider gave less than 2V).
- The voltages I read with a multimeter don't match the values I get on the microcontroller
The formula I'm using to convert the ADC value to Volts is
Code: Select all
value_mv = ((rtc_value * ref_millivolt)/resolution)
What should ref_millivolt be?
a: 1.803V (the maximum my voltage divider will allow through
b: 3.3V (the ESP32 voltage)
c: 2V (the value micropython documentation gives for 6DB attenuation
https://docs.micropython.org/en/latest/ ... #ADC.atten
d: The Vref mentioned on expressif documentation? https://docs.espressif.com/projects/esp ... ttenuation
- I'm not sure I'm using the right approach to convert the Volts I read on the ADC to a temperature.
Since the range on my transmitter is selectable I don't have a mV/C scale so I calculated my own by dividing the maximum output of the voltage divider by the range: 1803mV/140C = 12.8785mV/C
I also calculated the offset by putting the sensors on a water/ice bath and checking the reading on a multimeter
Here is my test code, any help appreciated.
Code: Select all
from machine import Pin, ADC
from time import sleep
sensors = [32, 33, 34, 35, 36, 39]
def read_temp(rtc):
""" Offset: is the value returned when the sensor is immersed in water/ice solution.
Scale: 1.803V (output of the voltage divider) / 140C (selected range for the transmitter)
Ref_volt: The reference voltage used by the ADC to calculate the values read
Resolution: The amount of bits used for the adc reading. 4095 = 12 bits, 2047 = 11 bits
"""
offset = 315 # mv at 0C on a multimeter
scale = 12.8785 # mV/C The output scale factor
ref_millivolt = 3.3 * 1000
resolution = 2047 # 2 to the power of the amount of bits 2^11
reads = 400 # Read a bunch of times to diminish variation
rtc_value = 0
for n in range(0, reads):
rtc_value += rtc.read()
sleep(0.001)
rtc_value = rtc_value/reads
value_mv = ((rtc_value * ref_millivolt)/resolution)
temperature = (value_mv - offset) / scale
return {"millivolts":value_mv, "value_read":rtc_value, "temperature":temperature}
mvTotal = {32:0, 33:0, 34:0, 35:0, 36:0, 39:0}
tempTotal = {32:0, 33:0, 34:0, 35:0, 36:0, 39:0}
loops = 5
for sensor in sensors:
print("reading sensor {}".format(sensor))
rtc = ADC(Pin(sensor))
rtc.atten(ADC.ATTN_6DB)
rtc.width(ADC.WIDTH_11BIT)
for i in range (0,loops):
r = read_temp(rtc)
print("Values read from sensor {}: {}, {}mV, {}C".format(sensor, r["value_read"], r["millivolts"], r["temperature"]))
mvTotal[sensor] += r["millivolts"]
tempTotal[sensor] += r["temperature"]
for key in mvTotal:
mv = mvTotal[key] / loops
temp = tempTotal[key] /loops
print("Reading average for sensor {}: {}mV, {}C".format(key, mv, temp))