Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pico-displayTemperature
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
abp1g20
pico-displayTemperature
Commits
cff37216
"...accelerator-project-secworks-aes-128.git" did not exist on "68704375f33a38f875c09098cd3b02515f973029"
Commit
cff37216
authored
3 years ago
by
abp1g20
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
8bed1213
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+54
-0
54 additions, 0 deletions
main.c
with
54 additions
and
0 deletions
main.c
0 → 100644
+
54
−
0
View file @
cff37216
#include
<stdlib.h>
#include
<stdio.h>
#include
<stdbool.h>
#include
"pico/stdlib.h"
#include
"hardware/gpio.h"
#include
"hardware/adc.h"
#include
"lib/fonts.h"
#include
"lib/st7735.h"
//this task covers how to use the on-board temperature sensor in the RP2040 chip on the Raspberry pi Pico
//it uses the analogue to digital converter (ADC) in the Pico to read the internal temperature of the RP2040 and
//does the necessary data conversion to output the temperature of the chip
//also covers how to perform the required data processing to take the raw ADC output and convert it
//into a voltage and then into temperature
//the temperature sensor might not be calibrated so temperatures might differ in different
//boards due to manufacturing inconsistencies
//as such, if you will be using this in a serious project that requires an accurate temperature value,
//I would recommend using an external sensor.
int
main
()
{
stdio_init_all
();
// Initialise serial in/output
//Configure ADC
adc_init
();
adc_set_temp_sensor_enabled
(
true
);
//Enable temperature sensor
adc_select_input
(
4
);
//Select fifth channel of the adc as the input
sleep_ms
(
1000
);
// Wait 1 sec
ST7735_Init
();
// Initialise the screen
//Update temperature display every second
//Infinite loop
while
(
1
)
{
uint16_t
raw
=
adc_read
();
//Define a variable to store the raw output value from the adc
//Do the conversion
const
float
conversion
=
3
.
3
f
/
(
1
<<
12
);
float
voltage
=
raw
*
conversion
;
// convert raw value to voltage
float
temperature
=
27
-
(
voltage
-
0
.
706
)
/
0
.
001721
;
// convert voltage to temperature value
char
strArray
[
25
];
sprintf
(
strArray
,
"Temperature: %d"
,
(
int
)
temperature
);
//store output on char buffer
ST7735_FillScreen
(
ST7735_BLACK
);
//set screen color
ST7735_WriteString
(
0
,
0
,
strArray
,
Font_16x26
,
ST7735_GREEN
,
ST7735_BLACK
);
//display temperature on screen
//can also use any other function from the library to display the temperature differently
//wait 1 sec
sleep_ms
(
1000
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment