MLTP - My Little Temp Project :-)

Hi, I have a Raspberry Pico which is without any job. So I decided to do a little project without much time.

The pico should read its temp-sensor and communicate the temp while blinking the LED: First Figure, second figure.

23 degress (Celsius here) should be

blink blink (pause) blink blink blink (wait 5 min)

Connected to a USB-Powercable the pico can tell my through camera what temperature is in my caravan. ;-)

But: How can I calculate the real room-temperature better? The results are not very accurate.

Here is the source (public domain):

# Thermometer - get room temperature by CPU-Temperature # and tell it users by blinking, FW 2021

import machine, time

led = machine.Pin(25, machine.Pin.OUT)

# blink - blink "times" times with duration "duration" def blink (times, duration): for c in range (0,times): led.on() time.sleep_ms(duration) led.off() time.sleep_ms(duration)

# Greetings: Machine okay blink (3, 100) time.sleep_ms(1000)

while 1:

# Get CPU-Temperature, calculate ° Celsius sensor_temp = machine.ADC(4) sensor_temp = sensor_temp.read_u16() * (3.3 / (65535)) sensor_temp = int (27 - (sensor_temp - 0.706)/0.001721) zehner = int (sensor_temp / 10) einer = sensor_temp - (zehner * 10) einer = einer - 4 # room-temp vs. CPU-Temp

for c in range (0, 2): blink (zehner, 250) time.sleep_ms (1000) blink (einer, 250) time.sleep_ms (1000)

print ("Sensor-Temp: ", sensor_temp - 4, "° C") print ("Zehner.....: ", zehner) print ("Einer......: ", einer)

Thank you!

FW

Reply to
F. W.
Loading thread data ...

Even better with Morse Code?

In 1972 from Floor 11 of Keynes Tower at Essex Uni. I had a small beacon flashing "HI".

Long before the days of microprocessors, discounting the 4004, but done with reject (Plessey, I think) RTL logic chips.

Reply to
gareth evans

Attach an external sensor. Either way, you'd still have to calibrate it. So that's the only way: measure the temperature in a different, known good way and adjust the calculation accordingly.

Reply to
A. Dumas

Often the problem with internal temperature sensors is they're affected by self-heating. If the microcontroller is running in a loop it can consume some mA which raises its own temperature above ambient, at least until heat-in is equilibrated with extra heat loss due to the raised temperature.

The solution to that is to go into low power suspend until the package has matched ambient temperature. Then take a measurement as the first thing you do, transmit it, and go back to sleep.

In your code you could try longer sleep() periods between readings, but you'd have to check if that actually causes the device to go into suspend, or just spins in a loop. The other approach is to set a timer interrupt for some time hence and then 'Wait For Interrupt' (WFI instruction) which should enter CPU power saving mode. Although you might also need to consider whether any peripherals are also taking power.

As has been mentioned, using an external temperature sensor that's not right next to the MCU or other heat generating components avoids this problem.

Theo

Reply to
Theo

I solved this problem some years ago by buying a Sensirion temperature and humidity sensor, which is factory calibrated. It communicates via IIC.

May not be the sort of solution you want, of course! It depends on how much accuracy you need.

David

Reply to
David Higton

There are a number of cheap temperature sensors which you can connect via Pico's I2C pins, and will be far more accurate than the sensor in the chip package, which will be affected by the load on the CPU.

I use htu21df or si7021 for temperature and humidity, and BME280 for temperature, humidity and pressure.

Blinking lights are a start, but why not hook up either some 7 segment LEDs, or tiny LCD display to the Pico's output pins.

---druck

Reply to
druck

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.