5

I am following this tutorial: http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/.

The problem is I don't have that specific temperature sensor on me. Since I don't have that specific sensor on me currently, would I be connect a potentiometer to an ADC and get similar results (obviously not getting temperature, but some kind of data I can play around with)? If I can't do that, what other possibilities are available?

5

The DS18B20 is a digital sensor using the Dallas 1-wire protocol.

If you just want to get figures to play with you could, as you say, connect an ADC and twiddle a pot.

However a simpler, and perhaps more useful, source of data is the SOC (System on a Chip) temperature.

The following C snippet will print the SOC temperature.

void get_SOC_temp()
{
   FILE *f;
   float cpu_temp;

   f = fopen("/sys/class/thermal/thermal_zone0/temp", "r");

   if (f != NULL)
   {
      fscanf(f, "%f", &cpu_temp);
      cpu_temp /= 1000.0;
      fclose(f);

      printf("%.1f\n",cpu_temp);
   }
}

From the command line you can just

cat /sys/class/thermal/thermal_zone0/temp
  • Thank you, what does "FILE *f;" mean? – Clers Dec 24 '15 at 17:23
  • It's declaring a variable called f which points to a FILE object. man FILE from the command line if you like reading gory details. – joan Dec 24 '15 at 22:11
3

No, you would not get similar responses.

The DS18B20 produces a digital signal, using a specific protocol. If you connected a potentiometer over that you would get nothing like usable data.

If you want to experiment with arbitrary electronics, I would strongly suggest that you don't need a pi involved to do this. Far, far to much chance of damaging your pi with voltages outside it's acceptable range. It's possible an arduino might be more suitable?

Alternatively, for just straight temperature, I'd take Joan's answer - use the built in sensor. (I didn't know the pi had one, and I'm considering uses....)

  • Remember the SOC temperature is the temperature of the silicon wafer, not the external air temperature. – joan Dec 24 '15 at 22:13
  • The purpose of this post was when I was working a book I found at the library for raspberry pi. The point of using a ADC would be to convert the potentiometer signal (Analog) into something the Raspberry Pi can read (Digital). For this project I ended up reading the datasheet wrong and produced the wrong signal (A lot of smoke, a burning sensor, and some shame). – Clers Oct 20 '16 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.