-
Notifications
You must be signed in to change notification settings - Fork 71
Project 4: MCP3008
The Raspberry Pi does not feature any analog inputs, so the aid of an analog to digital convertor (ADC) is necessary when you'd like to take readings from the physical world. Luckily ADCs such as the MCP3008 are quick and easily to interact with. Adafruit walks through the basics of getting it setup and running in Python in this tutorial, and in our sample project we will port their example to Ruby.
Our schematic:
The basic idea behind this project is to "bit bang" the MCP3008 to read the temperature from a Taylor TruTemp thermometer. These thermometers have a probe that attaches with a 2.5mm "headphone" jack, so incorporating their probe into our circuit is as simple as purchasing a 2.5mm female jack.
Readings from the ADC are measurements of millivolts, and since our temperature probe is a temperature variable resistor, we are able to infer the temperature from the voltage readings. To calibrate our thermometer, simply taking readings at 0 degrees Celsius, and another at a much higher temperature. From this you'll be able to know the degrees per millivolt:
temp = (mvolts - 380.0) / (2320.0 / 84.0)
In the above example, my second reading was at 84 degrees Celsius. With this equation I was able to check the readings from my own circuit versus those of the actual thermometer, and they lined up pretty well.
However, one thing I did notice is that both my circuit and the actual thermometer started to record low after the temperature exceeded approximately 120 degrees Celsius. To compensate for this, I used the following logic:
if mvolts < 2700
temp = (mvolts - 380.0) / (2320.0 / 84.0)
else
temp = (mvolts - 2700.0) / (390.0 / 92.0) + 84.0
end
With the above modification I was able to accurately read temperates from 0 degrees Celsius all the way up to 180. Perhaps even higher, but I didn't take the time to double check those temperatures as there should be no reason for cooking food to that high of an internal temperature.
The full code, like always, can be found here.