Two part question.
Although these questions might sound more generally like linux questions, my need is to have these answers specific to the pi.
Part 1 - Does the raspberry pi 2, 3B, 3B+, 4B, have only one temperature sensor that measures the overall processor temperature, or does it have a separate sensor for the CPU, and an additional separate sensor for the GPU?
I have found posted solutions (answers) on half a dozen support forums that claim to measure both (implied separately) in a bash shell, but if there is only one sensor, I wish to simplify my script(s), and know that those posts that showed the GPU sensor, separately, were ... misleadingly misinformed or unclear ... by not explaining that there is in fact only one sensor that measures the cpu/gpu silicon.
Also, testing some of those posted answers for finding the gpu temperature (with vcgencmd measure_temp), those results were always 0 for the decimal, ie 45.0, while the cpu temperature results were often a non zero decimal value, such as 42.173.
Here, on the pi forum, someone with a title of engineer (something I respect) implies two sensors with his code... but please understand that I intend no offense to any person or title by focusing a bit on this. Any and every contributor, whether an engineer or not, may simply be faithfully communicating what is in the resources available to that person at that time. That is an unavoidable dynamic in any opensource community, something we embrace because of how great the benefits can be. In context, for me, reading the post of an engineer, among all the others, makes arriving at a final conclusion that much more confusing, since certainly I prefer to go with the word of an engineer, which then makes all other answers necessarily in an as yet undetermined tension with the engineer's answer (and maybe that is good as it may urge some to investigate further toward verification, if this issue is indeed as important as it is represented to be for particular project(s)).
Additional bash solutions I have found:
1: Suggesting there is a separate gpu to measure.
#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 %$cpuTemp1))
echo "CPU temp=$cpuTemp1.$cpuTempM'C"
echo "GPU $(/opt/vc/bin/vcgencmd measure_temp)"
2: This was given as a solution in one post for cpu temp, and in another post for specifically the gpu temp. Which is it? Or is this an indicator that they are one and the same?
/opt/vc/bin/vcgencmd measure_temp
3: This was given as specifically for the cpu temp, and would then need to be divided by 1000 for celsius temperature.
echo $(cat /sys/class/thermal/thermal_zone0/temp)
4: This seems very similar to '2', except the vcgencmd is located in a different path. Does this mean it is measuring a different sensor, or the same one? Why the two occurences?
/usr/bin/vcgencmd measure_temp
Each of those 4 versions may have different issues of the format of the result, but most importantly to me, and other users who have asked similar question(s)... are there two separate sensors or only one?
Part 2 - I would like to capture these temperature(s) in a python3 script. How I do this will depend on whether there are two sensors or just the one for both cpu and gpu.
I have already found a solution for the cpu temperature in python3 (3.5.3+).
import gpiozero as gpz
cpu = gpz.CPUTemperature()
cpu_temp = cpu.temperature
print(cpu_temp)
46.251
If there is only one sensor, then I have my solution to Part 2. Or is there a better way with subprocess?
Edit:
I have included in my own answer, a function for reading the sensor by using subprocess instead.