EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #133 background imageLoading...
Page #133 background image
133
Chapter 11 Thermistor
www.freenove.com
support@freenove.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
im port RPi. GPIO as GPIO
im port smbus
im port time
im port math
address = 0x48
bus=smbus.SMBus(1)
cmd=0x40
def analogRead(chn):
value = bus.read_byte_data(address,cmd+chn)
r eturn value
def analogWrite(value):
bus. write_byte_data(address,cmd,value)
def setup():
GPIO. setmode(GPIO.BOARD)
def loop():
w hile Tr ue:
value = analogRead(0) #read A0 pin
voltage = value / 255.0 * 3.3 #calculate voltage
Rt = 10 * voltage / ( 3.3 - voltage) #calculate resistance value of thermistor
tempK = 1/(1/(273.15 + 25) + math.log(Rt/10)/3950.0) #calculate temperature
(Kelvin)
tempC = tempK -273.15 #calculate temperature (Celsius)
print('ADC Value : %d, Voltage : %.2f, Temperature : %.2f'%(value,voltage,tempC))
time.sleep(0.01)
def destroy():
GPIO. cleanup()
if __name__ == '__main__':
p rint ('Program is starting ... ')
setup()
try:
loop()
e xcept KeyboardInterrupt:
destroy()
In the code, read the ADC value of PCF8591 A0 port, and then calculate the voltage and the resistance of
thermistor according to Ohms law. Finally, calculate the current temperature. according to the front formula.

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish