Skip to content
Snippets Groups Projects
Commit eca09b16 authored by abp1g20's avatar abp1g20
Browse files

Upload New File

parent 9eb2f3f2
No related branches found
No related tags found
No related merge requests found
#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
//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() {
//Configure ADC
adc_init();
//Task starts here
//Enable temperature sensor
//Select fifth channel of the adc as the input (0 is considered as the first channel)
sleep_ms(1000); // Wait 1 sec (not necessary)
// Initialise the screen (use ST7735_Init() function from the st7735 library)
//Infinite loop to update temperature display every second
while (1) {
//store the raw output value from the adc
const float conversion = 3.3f / (1 << 12); //Use this conversion to go from raw value to voltage
//convert raw value to voltage (multiply conversion with the raw value)
//convert voltage to temperature value (temp = 27 - (voltage - 0.706) / 0.001721)
//create char buffer
//store temperature output on char buffer
//use the fillScreen(uint16_t color) to set the screen color
//use the ST7735_WriteString(uint16_t x, uint16_t y, const char* str, FontDef font, uint16_t color, uint16_t bgcolor) function to write the temperature to the screen
//can also use any other function from the library to display the temperature differently
sleep_ms(1000); //wait 1 sec
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment