So I am trying to interface the Arduino Uno with the TMP100 from texas instruments. The tmp100 requires 1 bit (READ = 1. write = 0) after the 7 bit Address so it knows what I want to do with it. Now my problem is that the arduino Wire.beginTransmission() function only allows to send a 7 bit address, so how must I send the 8th bit that the TMP100 requires from me?
Can I just use Wire.write() after Wire.beginTransmission() to tell the tmp100 if I am going to write to it or read from it?
johnwasser:
Wire.beginTransmission() is for WRITE.
Wire.requestFrom() is for READ.
The library takes care of the write/read bit.
ok so if I want to read from the pointer register inside the TMP100 my I2C will go something like this?
void loop()
{
Wire.begin(); // start condition
Wire.requestFrom(Tmp_add,1);//I send the TMP its address, and tell it I am going to read from it
int ack_nack_addr = Wire.read(); //to check if TMP ack or NACK my command
Wire.write(pointer_register); //I write the address to the pointer register to access specific regster
int ack_nack_pointer = Wire.read(); //to check if TMP ack or NACK my command
Wire.requestFrom (Tmp_add,1); //Going to receive the information from the TMP100, and it is 1 byte
int register_value = Wire.read();
Wire.endTransmission();
}
// Request the data
Wire.requestFrom(Tmp_add,1);
int register_value = Wire.read();
}
Wow thanks alot that did the trick!!! So lets say I want to write to the particular register inside the TMP100 to change the resolution of the temperature readings, and then verify that the register actually changed the resultion by reading it again.
void setup()
{
Wire.begin();
}
void loop()
{
// Send the register address
Wire.startTransmission(Tmp_add);
Wire.write(pointer_register);
Wire.write(resolution_value);
Wire.endTransmission();
// Request the data
Wire.requestFrom(Tmp_add,1);
int register_value = Wire.read();
}
You probably have to set the register address again to get the same register:
void loop()
{
// Send the register address and new value
Wire.startTransmission(Tmp_add);
Wire.write(pointer_register);
Wire.write(resolution_value);
Wire.endTransmission();
// Send the register address
Wire.startTransmission(Tmp_add);
Wire.write(pointer_register);
Wire.endTransmission();
// Request the data
Wire.requestFrom(Tmp_add,1);
int register_value = Wire.read();
}
Thanks alot for the help! I got it working perfectly as I wanted to, Is there a specific place where I can post my code as example code , so that other people that might be struggling will at least have a reference to work from?
You could write an easy-to-use TMP100 library and post that somewhere. The "Playground" section of the Arduino site (see link at the top of the page) is a place where people publish libraries and examples.
johnwasser:
You could write an easy-to-use TMP100 library and post that somewhere. The "Playground" section of the Arduino site (see link at the top of the page) is a place where people publish libraries and examples.
Thanks, how do i make my post solved status?
Final Code Working!:
/* Dudley Tolken
Temp Sensor
06-03-2012
Thanks to the following person(s):
1. John Wasser, on the Aruindo Forums
Description:
This project interfaces at Arduino Uno (SMD) with a TMP100 (Texas Instruments).
Temperature Reading:
The TMP100 sends 2 bytes of data for the current sampled temperature. The first byte containts the MSB(Integer) and the second
byte contains the LSB(Decimal).Although the decimal value is only 4 bits long, the decimal value is stored from bit 4 to bit 7
in the LSB, while bit 0 to bit 3 is 0.
To read temperature from the TMP100 the folllowing algorithm is used.
(1).Wire.beginTransmission(Slave_Address) <-Initiate transmision
(2).Wire.write(ponter_address_temp) <-Access temp register in Pointer Register
(3).Wire.endTransmission() <-End transmission
(4).Wire.requestFrom(Slave_Address,2); <-Request 2 bytes(MSB, LSB) from the TMP100 address
Convert the MSB and LSB to the actual temperature.
(1).temp_MSB = Wire.read() <--Store the MSB value into a integer variable(temp_MSB)
(2).temp_LSB = Wire.read() <--Store the LSB value into a integer variable(temp_LSB)
Note:
The MSB is the actual integer value of the current temperature that the sensors measures.
The LSB will look something like this (Remember the actual measurement of the LSB is ONLY 4 bits!!):
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
1/0 1/0 1/0 1/0 0 0 0 0
(3).int temp_deci = map(temp_LSB >> 4, 0, 15,0,99); <- temp_LSB >> 4, it shifts the decimal value of the measured temperature right by 4, so that it sits now between Bit 3 to Bit 0, so conversion to integer is easy
<- 4 Bits goes from 0 to 15 Decimal, so to get an accurate reading, just scale it to be from 0 to 999
Write to Configuration Register.
(1).Wire.beginTransmission(temp_address) <-Initiate transmision
(2).Wire.write(pointer_address_config) <-Access config register in Pointer Register
(3).Wire.write(config); <-Write data to configuration register
(4).Wire.endTransmission(); <-End transmission
Arduino UNO (SMD) -> Master
TMP100 -> Slave
MASTER SLAVE
|----------------------------|
|--------------| | |--------------| |
| Arduino Uno | | | TMP100 | |
| GND|----------------|GND(2) (5)ADD0|---------|
| Vcc(5V)|----------------|Vcc(4) (3)ADD1|---------|
| (SDA)A4|----------------|SDA(6) |
| (SCL)A5|------------|---|SCL(1) |
| | | | |--------------|
|--------------| | |
(pull up) 10K 10K (pull up)
| |
VCC VCC
*/
#include <Wire.h> //Include I2C library
int ponter_address_temp = 0; //Pointer address 0 = Temperature output.
int temp_address = 72; //slave address of TMP100
int pointer_address_config = 1; //Pointer address 1 = Configuration Register
byte temp_MSB, temp_LSB; // Because the TMP100 sends 2 bytes
int config = 224; //Configuration Register - To have 12 bit resolution. Refer to TMP100 for the Configuration Register
void setup()
{
Serial.begin(9600); //serial baud rate
Wire.begin(); //Start I2C
Wire.beginTransmission(temp_address); //Sends slave address with Rwite
Wire.write(pointer_address_config);//Access config register in Pointer Register
Wire.write(config); //Write data to configuration register
Wire.endTransmission(); //End Transmission
}
void loop()
{
Wire.beginTransmission(temp_address); //Sends slave address with Rwite
Wire.write(ponter_address_temp); //Access temp register in Pointer Register
Wire.endTransmission();//End Transmission
Wire.requestFrom(temp_address,2); //Request 2 bytes(MSB, LSB) from the TMP100 address
temp_MSB = Wire.read(); //Store first byte from TMP100 (MSB) into a variable
temp_LSB = Wire.read(); //Store seconds byte from TMP100 (LSB) into a variable
int temp_deci = map(temp_LSB >> 4, 0, 15,0,999); // Shift LSB 4 bits to the rightm and scale it to range from 0 to 999
//Prints to the serial window.
Serial.print("Temp: ");
Serial.print(temp_MSB);
Serial.print(".");
Serial.println(temp_deci);
delay(1000);
}