SparkFun Forums 

Where electronics enthusiasts find answers.

#204236
Problem: When I have 2 TMP102's connected to the same I2C bus, I cannot get both modules initialize in the void setup. I know this because my serial monitor prints:

"Init Complete 1
Init Complete 0
Sensor 0 Begin"

It does not print out Sensor 0 Set Fault as it should next. I have tried initializing both TMP102 modules I have independently of one another, by removing one of the TMP102 modules completely from my breadboard. In this case, both TMP102 modules are able to initialize and output the temperature correctly.


Background: I have the circuit wired up on a breadboard. Both TMP modules have their I2C pull-up and address connecting traces cut on the back-side of the module (as indicated in the tutorial online). I am using a 4.7kOhm resistor on each of the SDA and SCL lines coming from my Arduino Uno. I am using the open-source SparkFunTMP102 library and example code. This is how my code looks like in the void setup:
___________________________________________________________________________
Moderator edit to add code tags.
Code: Select all
void setup(void) {
    Serial.begin(9600);
    analogReference(EXTERNAL);
    pinMode(TempLED, OUTPUT);

    pinMode(ALERT0_PIN,INPUT);
    pinMode(ALERT1_PIN,INPUT);
  
    TMP102 sensor1(0x49); // Initialize sensor 1 at I2C address 0x49 (VCC)
    Serial.print("Init Complete 1\n");
    
    TMP102 sensor0(0x48); // Initialize sensor 0 at I2C address 0x48 (GND)
    Serial.print("Init Complete 0\n");   
  
    // Initialize sensor0 settings
    // These settings are saved in the sensor, even if it loses power
    sensor0.begin(); Serial.println("Sensor 0 Begin"); 
  
    // set the number of consecutive fMaults before triggering alarm.
    // 0-3: 0:1 fault, 1:2 faults, 2:4 faults, 3:6 faults.
    sensor0.setFault(1); Serial.println("Sensor 0 set Fault");
  
    // set the polarity of the Alarm. (0:Active LOW, 1:Active HIGH).
    sensor0.setAlertPolarity(1); Serial.println("Sensor 0 set Alert Polarity");
  
    // set the sensor in Comparator Mode (0) or Interrupt Mode (1).
    sensor0.setAlertMode(0); Serial.println("Sensor 0 set Alert Mode");
  
    // set the Conversion Rate (how quickly the sensor gets a new reading)
    //0-3: 0:0.25Hz, 1:1Hz, 2:4Hz, 3:8Hz
    sensor0.setConversionRate(2);
  
    //set Extended Mode.
    //0:12-bit Temperature(-55C to +128C) 1:13-bit Temperature(-55C to +150C)
    sensor0.setExtendedMode(0);
  
    //set T_HIGH, the upper limit to trigger the alert on
    //sensor0.setHighTempF(85.0);  // set T_HIGH in F
    sensor0.setHighTempC(50);
  
    //set T_LOW, the lower limit to shut turn off the alert
    //sensor0.setLowTempF(84.0);  // set T_LOW in F
    sensor0.setLowTempC(49); 
  
    Serial.print("Setup Complete 0\n");
  
    //Set all same parameters for sensor 1
    sensor1.begin();
    sensor1.setFault(1);
    sensor1.setAlertPolarity(1);
    sensor1.setAlertMode(0);
    sensor1.setConversionRate(2);
    sensor1.setExtendedMode(0);
    sensor1.setHighTempC(50);
    sensor1.setLowTempC(49);
  
    Serial.print("Setup Complete 1\n");
}
____________________________________________________________________________

I have also tried putting the " TMP102 sensor1(0x49);" line right above the "sensor1.begin();" line, as I understand that this function declares the "_address" variable. However, it does not change the outcome.

I appreciate the help!
#204303
Hi ChipKick,

This is a bit beyond the scope of our support here and we cannot really help debug your code. There also may be more going on with your circuit or code that is causing the issue.

That said, I was able to get two TMP102 Breakouts working on the same bus with a modified version of the example sketch printing temperature values from each sensor. Here is that code:
Code: Select all
/******************************************************************************
TMP102_example.ino
Example for the TMP102 I2C Temperature Sensor
Alex Wende @ SparkFun Electronics
April 29th 2016
~

This sketch configures the TMP102 temperature sensor and prints the
temperature and alert state (both from the physical pin, as well as by
reading from the configuration register.

Resources:
Wire.h (included with Arduino IDE)
SparkFunTMP102.h

Development environment specifics:
Arduino 1.0+
Hardware Version 13

This code is beerware; if you see me (or any other SparkFun employee) at
the local, and you've found our code helpful, please buy us a round!

Distributed as-is; no warranty is given.   
******************************************************************************/

#include <Wire.h> // Used to establied serial communication on the I2C bus
#include "SparkFunTMP102.h" // Used to send and recieve specific information from our sensor

// Connections
// VCC = 3.3V
// GND = GND
// SDA = A4
// SCL = A5
//const int ALERT_PIN = A3;

TMP102 sensor0(0x48); // Initialize sensor at I2C address 0x48
TMP102 sensor1(0x49);
// Sensor address can be changed with an external jumper to:
// ADD0 - Address
//  VCC - 0x49
//  SDA - 0x4A
//  SCL - 0x4B

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud
  //pinMode(ALERT_PIN,INPUT);  // Declare alertPin as an input
  sensor0.begin();
  Serial.println("Sensor0 here!");// Join I2C bus
  sensor1.begin();
  Serial.println("Sensor1 here!");
  
}
 
void loop()
{
  float temperature0;
  float temperature1;
  //boolean alertPinState, alertRegisterState;
  
  // Turn sensor on to start temperature measurement.
  // Current consumtion typically ~10uA.
  //sensor0.wakeup();
  //sensor1.wakeup();
  // read temperature data
  temperature0 = sensor0.readTempF();
  temperature1 = sensor1.readTempF();
  //temperature = sensor0.readTempC();

  // Check for Alert
  //alertPinState = digitalRead(ALERT_PIN); // read the Alert from pin
  //alertRegisterState = sensor0.alert();   // read the Alert from register
  
  // Place sensor in sleep mode to save power.
  // Current consumtion typically <0.5uA.
  //sensor0.sleep();

  // Print temperature and alarm state
  Serial.print("Temperature: ");
  Serial.println(temperature0);
  Serial.print("Temperature1: ");
  Serial.println(temperature1);
  //Serial.print("\tAlert Pin: ");
  //Serial.print(alertPinState);
  
  //Serial.print("\tAlert Register: ");
  //Serial.println(alertRegisterState);
  
  delay(1000);  // Wait 1000ms
}
I commented out the alert calls just to simplify things to make sure everything is working to just print temperatures. All of those settings will get saved through a power cycle so if you want to set each sensor up differently, just use the stock example to set each TMP102 up how you want it and it will save those settings. Give this example shot and if it does not work, double check you have the AD0 pin jumped to the correct pin(s) to set the addresses. If it still does not work after all that, please take a few photos of your circuit and attach them to your response.

I hope this helps you get this project up and running!