SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
(continued from previous page)
thermistor
=
machine
.
ADC(
28
)
while
True
:
temperature_value
=
thermistor
.
read_u16()
Vr
=
3.3
*
float
(temperature_value)
/
65535
Rt
=
10000
*
Vr
/
(
3.3
-
Vr)
temp
=
1
/
(((math
.
log(Rt
/
10000
))
/
3950
)
+
(
1
/
(
273.15
+
25
)))
Cel
=
temp
-
273.15
Fah
=
Cel
*
1.8
+
32
(
'Celsius:
%.2f
C
Fahrenheit:
%.2f
F'
%
(Cel, Fah))
utime
.
sleep_ms(
200
)
How it works?
Each thermistor has a normal resistance. Here it is 10k ohm, which is measured under 25 degree Celsius. When
the temperature gets higher, the resistance of the thermistor decreases. Then the voltage data is converted to digital
quantities by the A/D adapter.
The temperature in Celsius or Fahrenheit is output via programming.
import
math
There is a numerics library which declares a set of functions to compute common mathematical operations and trans-
formations.
•
temperature_value
=
thermistor
.
read_u16()
This function is used to read the value of the thermistor.
Vr
=
3.3
*
float
(temperature_value)
/
65535
Rt
=
10000
*
Vr
/
(
3.3
-
Vr)
temp
=
1
/
(((math
.
log(Rt
/
10000
))
/
3950
)
+
(
1
/
(
273.15
+
25
)))
Cel
=
temp
-
273.15
Fah
=
Cel
*
1.8
+
32
(
'Celsius:
%.2f
C
Fahrenheit:
%.2f
F'
%
(Cel, Fah))
utime
.
sleep_ms(
200
)
These calculations convert the thermistor values into centigrade degree and Fahrenheit degree.
Vr
=
3.3
*
float
(temperature_value)
/
65535
Rt
=
10000
*
Vr
/
(
3.3
-
Vr)
In the two lines of code above, the voltage is first calculated using the read analoge value, and then get Rt (the resistance
of the thermistor).
temp
=
1
/
(((math
.
log(Rt
/
10000
))
/
3950
)
+
(
1
/
(
273.15
+
25
)))
Note:
Here is the relation between the resistance and temperature:
RT =RN expB(1/TK – 1/TN)
• RT is the resistance of the NTC thermistor when the temperature is TK.
92
Chapter 3. For MicroPython User
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...