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 #132 background imageLoading...
Page #132 background image
Chapter 11 Thermistor
132
www.freenove.com
support@freenove.com
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
int adcValue;
float tempK,tempC;
float voltage,Rt;
if(wiringPiSetup() == -1){ //when initialize wiring failed,print message to screen
printf("setup wiringPi failed !");
return 1;
}
pcf8591Setup(pinbase,address);
while(1){
adcValue = analogRead(A0); //read A0 pin
voltage = (float)adcValue / 255.0 * 3.3; // calculate voltage
Rt = 10 * voltage / (3.3 - voltage); //calculate resistance value of thermistor
tempK = 1/(1/(273.15 + 25) + log(Rt/10)/3950.0); //calculate temperature (Kelvin)
tempC = tempK -273.15; //calculate temperature (Celsius)
printf("ADC value : %d ,\tVoltage : %.2fV,
\tTemperature : %.2fC\n",adcValue,voltage,tempC);
delay(100);
}
return 0;
}
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.
Python Code 11.1.1 Thermometer
First observe the project result, and then analyze the code.
1. Use cd command to enter 11.1.1_Thermometer directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/11.1.1_Thermometer
2. Use python command to execute python code “Thermometer.py”.
python Thermometer.py
After the program is executed, the terminal window will print out the current ADC value, voltage value and
temperature value. Try to pinch the thermistor (do not touch pin) with hand lasting for a while, then the
temperature value will be increased.
The following is the code:

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