Created
October 21, 2021 15:38
-
-
Save DanBrown47/3bf68c0f74df7f9bcb9d8d5920011d18 to your computer and use it in GitHub Desktop.
C code for getting temperature in Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
FILE *fp; | |
int temp = 0; | |
fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); | |
fscanf(fp, "%d", &temp); | |
printf("CPU Temp: %.2f°C\n", temp / 1000.0); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile this code
Then move this to a directory in path to run from anywhere