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 beblink 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