TMP36 and MCP3008: bitbang vs. hardware SPI driver
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

TMP36 and MCP3008: bitbang vs. hardware SPI driver

by spbecker on Thu Jan 10, 2013 8:21 pm

So I have some future plans on setting up a homebrewing control+measurement system, but I'm very new at wiring up my own electronics so I'm starting small here to learn how things work. With this in mind, I recently acquired an MCP3008 and TMP36 to play around with reading an analog temperature sensor through a Raspberry Pi.

I started with the python code from http://learn.adafruit.com/send-raspberr ... m/overview to make things work initially. This gave me a temperature reading that matched both the house thermostat and a thermocouple reading through my multimeter. Great!

Now the confusing part...I liked the idea of using hardware SPI instead of bitbanging, and found http://jeremyblythe.blogspot.com/2012/0 ... nputs.html to be instructive. I installed the necessary python bits, replaced the bitbanging readadc function with the hardware spi one, and ran it. It seemed to be working great, except now the temperature didn't match room temperature at all. The voltage reading was about 20-25mV lower, and the resulting temperature was about 2-3C too low. I switched back and forth between hardware SPI and bitbanged SPI a couple times just to check, and sure enough I consistently see a higher temperature (that matches room temperature much more closely) when using the bitbanged SPI.

Just to make sure, I checked the voltage on the middle pin using my multimeter, and lo and behold it matches the voltage I get using hardware SPI on the money. I removed the sensor from my breadboard, hooked it to both 3.3v and 5v with my multimeter directly connected and confirmed that I got the same answer each time, and that this was consistent with the measurement from the hardware SPI driver. I'm now fairly certain that the close match to room temperature using the bitbanged SPI was serindipity. Does anyone have some insight as to what is going on here?


Posts: 5
Joined: Wed Oct 24, 2012 1:47 pm

Please be positive and constructive with your questions and comments.