May 06

Arduino and TMP100

As you can see from my previous articles, I’m a big fan of I2C. There are many components and full devices that can connect through I2C, today we’ll be looking at the TMP100. This is one in a family of digital I2C temperature sensors from Texas Instruments; they all function in a similar way but have slightly different features. Sensing temperature is a useful function to incorporate in your projects. Whether you are creating a thermostat, monitoring computer temperatures or building a beer brewing system, you need to know the temperature (and sometimes it helps to know the temperature from several different spots).

The TMP100 has 2 features that made me choose it over the other versions:
1) It supports input voltages of 2.7v to 5.5; as opposed to the 102 which needs to be between 1.4v and 3.6v
2) It has 2 address pins which allows for up to 8 of these sensors on a single I2C bus

One Tiny Chip

The TMP100 comes in the very tiny SOT23 package. This is a surface mount device (SMD), because of its size you’ll need a breakout board to work with it on a breadboard. This brings up the issue of soldering SMD components. Sparkfun offers both the breakout board and some great tutorials on soldering SMDs. I ended up soldering it with a 3rd hand, magnifying glass, tweezers and patience.

TMP100 Soldered on Breakout Board

TMP100 Addresses

The I2C address of the TMP100/101 is determined by the ADD0 and ADD1 pins.

ADD1ADD0I2C ADDRESS
001001000
0Float1001001
011001010
101001100
1Float1001101
111001110
Float01001011
Float11001111

This means you can include up to 8 of these chips into a project.

TMP100 Accuracy

The accuracy or resolution with which the TMP100 reads the current temperature is able to be configured by the user. By default it reads the temperate in 0.5 degrees Celsius increments but can be as accurate at 0.0625 degrees Celsius. This feature is set by writing the desired value to the configuration bit. This accuracy comes at a price which is the speed it can calculate the temperature. More accuracy means slower chip. See the table below for the exact trade off.

BitsResolutionConversion Time
9Bits(0.5°C)40ms
10Bits(0.25°C)80ms
11Bits(0.125°C)160ms
12Bits(0.0625°C)320ms

Wiring

In this example I’ve connected the chip to an Arduino and grounded ADD0 to set the address to “1001011”

TMP100 to Arduino Wiring

Sample Sketch

This code has 2 configurable settings at the top, the TMP100 address (as defined in the table above) and the temperature resolution.

// Display TMP100 readout to serial
// Fork Robotics 2012
//

// Set the TMP Address and Resolution here
int tmpAddress = B1001011;
int ResolutionBits = 10;

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  SetResolution();
}

void loop(){
  getTemperature();
  delay(200);
}

float getTemperature(){
  Wire.requestFrom(tmpAddress,2);
  byte MSB = Wire.read();
  byte LSB = Wire.read();

  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  float fahrenheit = (1.8 * celsius) + 32;

  Serial.print("Celsius: ");
  Serial.println(celsius);
  Serial.print("Fahrenheit: ");
  Serial.println(fahrenheit);
}

void SetResolution(){
  if (ResolutionBits < 9 || ResolutionBits > 12) exit;
  Wire.beginTransmission(tmpAddress);
  Wire.write(B00000001); //addresses the configuration register
  Wire.write((ResolutionBits-9) << 5); //writes the resolution bits
  Wire.endTransmission();

  Wire.beginTransmission(tmpAddress); //resets to reading the temperature
  Wire.write((byte)0x00);
  Wire.endTransmission();
}

I have to give credit to the guys at bildr for the getTemperature function. They have an article about the TMP102 which is very similar. See their write up here: http://bildr.org/2011/01/tmp102-arduino/

Summary

The TMP101 is a simple, easy to implement component that can be integrated into many projects. In addition to this direct, continuous way of reading temperatures it’s also possible to do more with this chip. It has a shutdown mode that can save power and allow you to get a single temperature on demand instead of the chip reading it constantly; a great feature for a battery powered device. If you don’t need as many devices in your project you can check out the TMP101 and TMP102 which can function in Thermostat mode where the Alert Pin will go high when a certain temperature threshold is passed.

Mar 03

Recognizing Over-Engineering

I’ve been working on a small pet project to control my garage doors through my Arduino. This is my first step in a home automation project which will eventually be web based. Because this is going to be a distributed system to control things throughout the house I decided to use i2c as the platform. The chip I decided on for the remote locations was a PCF8574A. It’s called an I/O extender because it gives you 8 digital pins that can be used for input or output and since it hooks into I2C it only takes up the 2 analog pins on the Arduino. I was pretty excited about this and my mind filled with possibilities… then I got the chip.

I ran into several problems using the chip for this project:

1. It is only capable of sourcing .3 mA per pin which isn’t really enough to even power an LED. It can however sink up to 25ma per pin. This means designing the whole circuit in reverse as this forum post pointed out: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1173047782/5

2. If you want to use any of the pins as inputs they need to be set to on (HIGH), if they are off(low) then they will not read anything.

3. This chip is not only made by TI, the same chip is also made by NXP (Philips). One thing to note about the TI chip as opposed to the NXP version is that the TI lacks pull up resistors on each of the pins. Depending on how you use the chip this may cause issues. For me, this resulted in days of inconsistent behavior until I found this post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1233786313/2

4. To properly control each individual pins on the PCF8574A I ended up spending hours coding a serial based menu with the bitwise math to back it up.

5. The relays I purchased for this project may require too much current to switch because I could only switch 1 relay at a time.

6. Other people didn’t need transistors to switch relays with this chip but I decided to try it anyway and still no luck.

At this point I looked down at the circuit I had built and it hit me that I had wandered into the all too common mistake of over engineering a solution. In this case I was trying to shoehorn this chip into my project regardless that several of these factors above should have tipped me off that this was not the right chip for the job.

So I went back to the drawing board and started looking for other I2C options. I found the Arduino-Tiny project that provides everything you need to run a modified version of the Arduino platform on ATtiny family of chips. And they have a library to make it addressable over I2C! Not only does this fit the need of switching the 2 relays but also opens up a lot of options for imbedding ATtiny chips in projects instead of a whole Arduino!

Feb 06

I2C – Hundreds of Components on 2 Pins

There are several ways to communicate with components using an Arduino. When you want to go beyond basic individual input like buttons and potentiometers or single outputs like an LED, new methods need to be adopted. One of the options to communicate with additional inputs and outputs is I2C. Philips developed I2C to communicate with peripherals. It is a serial computer bus protocol which means that many devices can be hooked up to the bus and communicates via 2 wires. The Arduino is able to naively communicate with I2C using the wire library.

This opens up a lot of possibilities for projects; one notable example is the Wii Nunchuck. The Nunchuck is an I2C peripheral and communicates over I2C. This means that using I2C and the Wii Nunchuck you can add a joystick, acceleratorometer and 2 buttons to any Arduino project for a very reasonable price. For more information check out the WiiChuck, a simple adapter that breaks the necessary connections to 4 pins; you can also find the required code at the same page.

In addition to the Wii Nunchuck, there are many other I2C components that can be used in projects including temperature sensors, RGB LEDs, LCDs, RFID readers, and a host of other components. All you will ever need is the same 2 analog pins on the Arduino to communicate with all of them.