Reading Data from TMP75 Temperature sensor on I2C

365 views
Skip to first unread message

Brad E

unread,
Apr 17, 2014, 4:29:20 PM4/17/14
to ioio-...@googlegroups.com
Pretty lost on reading data from a temperature sensor (Texas Instruments TMP75) through an I2C. Could really use some help. |=(

I'm 99.9% sure this is the datasheet I should be using for the sensor chip. Only not 100% because I searched online for it as the chip was removed from an apple device.

The sensor is connected to the SDA & SCL 2 pins located @ pin #s: 25 & 26. Therefore my TWI interface is opened as such: 

twi = ioio_.openTwiMaster(2, TwiMaster.Rate.RATE_100KHz, false);

It is also connected to a 5v pin and a ground pin. 

Testing with a multimeter, I've seen that all the address pins (A2, A1, A0) are all grounded. Therefore, according to the datasheet, I should be addressing the slave as such:

address = 1001011;
if(twi.writeRead(address, false, request, request.length, response, response.length)) 
/*...Write Success...*/ 
else 
/*...Write Fail...*/ 

However, something must be wrong because every time I run the activity(with slight variations) I'm receiving a Fail, the code is skipped over entirely, stops right then & there at the write/read line, or (as it is doing right now) breaking the connection with the IOIO board and restarting the entire Looper class repeatedly.

Any advice, guidance, or help whatsoever would be greatly greatly appreciated. Much thanks. (=]]
All my best,
Brad E

p.s. total code in case relevant: 

package ioio.examples.hello;

public class Temperature extends IOIOActivity {
private static TextView tempReadOutView;
byte[] request;
byte[] response;
int address;
TwiMaster twi;
int runs = 0;
int duration;
Context context;
String decoded = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.templayout);
}

class Looper extends BaseIOIOLooper {
@Override
protected void setup() throws ConnectionLostException, InterruptedException {
displayTemp("IOIO Connected");
twi = ioio_.openTwiMaster(2, TwiMaster.Rate.RATE_100KHz, false);
request = new byte[] {0x01, 0x02};
response = new byte[1];
address = 1001011; //or 1001000
displayTemp("Set up Done");
if(twi.writeRead(address, false, request, request.length, response, response.length)) 
displayTemp("True");
else 
displayTemp("False");
}

public void loop() throws ConnectionLostException, InterruptedException {

}
}
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
public void displayTemp(final String str) throws InterruptedException {
Thread.sleep(1200);
runOnUiThread(new Runnable() {
@Override
public void run() {
context = getApplicationContext();
duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, str, duration);
toast.show();
}
});
}
}


Message has been deleted

Brad E

unread,
Apr 17, 2014, 4:50:45 PM4/17/14
to ioio-...@googlegroups.com
Slight variations including {0x49} or {0x01, 0x02, 0x03, 0x04} being inserted instead for request byte[] and response byte varying in size from 0 to 80. 

Always giving me an output of 0's or a scrambled String, however when that happens its possible I'm just not performing the proper conversion from a byte array to a readable string of binary digits?

Brad E

unread,
Apr 17, 2014, 5:29:57 PM4/17/14
to ioio-...@googlegroups.com
I have been using Firmware version 3.30 on the IOIO0323 IOIO platform.

I also have in possession this chip from sparkfun, am now changing boards to the most recent IOIO OTG board.

Brad E

unread,
Apr 17, 2014, 6:22:26 PM4/17/14
to ioio-...@googlegroups.com
Correction - this sparkfun chip.

Ytai Ben-Tsvi

unread,
Apr 17, 2014, 10:33:42 PM4/17/14
to ioio-...@googlegroups.com
The address in the datasheet is binary. 1001000 = 0x48.
Also, in order to read a register, you need to write one byte (value 0-3, where 0=temperature, etc according to table 2) and read back 2 bytes, whose formats are described following table 2.


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages