TWI TMP102 Sensor Help Please

190 views
Skip to first unread message

Marius Vosylius

unread,
Mar 21, 2014, 4:59:40 PM3/21/14
to ioio-...@googlegroups.com
I'm struggling to get my TWI reading out, Im not sure where Im going wrong?

TMP102 DataSheet

Any help or example would me really appreciated. 

Main Class:

// IOIO pin 26 = SDA, pin 25 = SCL

private final int twiNum = 26;

// TextView Display Temperature

private TextView tmpTextView;

private TwiMaster twi;

int address;

byte[] request = new byte[] { 0x00, 0x48};

byte[] response = new byte[4];

Setup:

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

Loop:

address = 0x48;

try {

twi.writeRead(address, false, request, request.length, response, response.length);

/* Update UI */

updateViews();

} catch (InterruptedException e) {

ioio_.disconnect();

} catch (ConnectionLostException e) {

throw e;

}

private void updateViews() {

runOnUiThread(new Runnable() {

@Override

public void run() {

tmpTextView.setText(String.valueOf(response));

}

});

}    

Ytai Ben-Tsvi

unread,
Mar 21, 2014, 5:09:39 PM3/21/14
to ioio-...@googlegroups.com
One thing that pops immediately is that twiNum should be either 0, 1 or 2, not 26.
Another thing is that the address probably doesn't need to be inside the request buffer.
Yet another thing is that you probably want to only read back 2 bytes and not 4.

In the future, it would help a lot if you look at logcat before posting your code - you should have an exception there with the current code.


--
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.

Marius Vosylius

unread,
Mar 21, 2014, 5:13:11 PM3/21/14
to ioio-...@googlegroups.com
Thanks Ytai, Im using Pin 25, & 26 on board, so can i use twiNum 0?

Ytai Ben-Tsvi

unread,
Mar 21, 2014, 5:15:52 PM3/21/14
to ioio-...@googlegroups.com
See https://github.com/ytai/ioio/wiki/Getting-To-Know-The-IOIO-OTG-Board, or the legend on the back of your board. Pins 25, 26 are associated with TWI 2.

Marius Vosylius

unread,
Mar 21, 2014, 5:20:31 PM3/21/14
to ioio-...@googlegroups.com
So its means that TMP102 SDA goes to IOIO Pin1 & SCL to Pin 2? 

Marius Vosylius

unread,
Mar 21, 2014, 5:30:09 PM3/21/14
to ioio-...@googlegroups.com
Updated:

Main CLass:

private TextView tmpTextView;

private TwiMaster twi;

int address = 0x48;

byte[] request = new byte[] { 0x00, 0x48};

byte[] response = new byte[2];

Looper Class:

public void setup() throws ConnectionLostException {

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

}


public void loop() throws ConnectionLostException {   

try {

twi.writeRead(address, false, request, request.length, response, response.length);

/* Update UI */

updateViews();

} catch (InterruptedException e) {

ioio_.disconnect();

} catch (ConnectionLostException e) {

throw e; }


Still Nothing.

Ytai Ben-Tsvi

unread,
Mar 21, 2014, 6:06:26 PM3/21/14
to ioio-...@googlegroups.com
"Nothing" is not very informative...

TWI 1 that you're using indeed uses pins 1, 2 (assuming IOIO-OTG).
Please add a check for the return value of writeRead(): true means success and false means failure (which typically means that the device is improperly connected, improperly powered or using a different address than you're using).


--

Marius Vosylius

unread,
Mar 21, 2014, 6:37:43 PM3/21/14
to ioio-...@googlegroups.com
Where to find address on DataSheet?

1001010 SDA?
1001011 SCL?

Is this is right? Thanks.

Ytai Ben-Tsvi

unread,
Mar 21, 2014, 8:10:27 PM3/21/14
to ioio-...@googlegroups.com
According to the table on page 10 of the datasheet, the address depends on where you're connecting the A0 pin to. You have to connect it to either GND, V+, SDA or SCL, resulting in address 0x48, 0x49, 0x4A, ox4B, respectively.
Also note that if you're using the SparkFun breakout board for the TMP102, you don't need external pull-ups, as they are included on the breakout board, so your connections needs to be:
VCC <-> IOIO 3.3V
GND <-> IOIO GND
SDA <-> IOIO SDA
SCL <-> IOIO SCL
ADD0 <-> either one of the 4 pins mentioned above.

BTW, I dug up some old project I have that uses the IOIO with a TMP102. Here's the code:

public class TMP102 {
  private static final byte[] TEMP_REQUEST = {0x00};

  private final TwiMaster twi_;
  private final byte address_;
  private final byte[] responseBuffer_ = new byte[2];

  public TMP102(TwiMaster twi, byte address) {
    twi_ = twi;
    address_ = address;
  }

  public float getTemperatureKelvin()
      throws ConnectionLostException, InterruptedException, CommunicationException {
    if (!twi_.writeRead(address_, false, TEMP_REQUEST, 1, responseBuffer_, 2)) {
      throw new CommunicationException("I2C transaction with TMP102 failed.");
    }
    int temp = Unsigned.from(responseBuffer_[0]) << 8 | Unsigned.from(responseBuffer_[1]);
    temp >>= 4;
    return temp / 16.f + 273.15f;
  }
}

And:

public class Unsigned {
  public static int from(byte b) {
    return b & 0xFF;
  }

  public static int from(short s) {
    return s & 0xFFFF;
  }
}


Marius Vosylius

unread,
Mar 24, 2014, 7:29:43 AM3/24/14
to ioio-...@googlegroups.com
Thats what I needed Ytai, I really appreciate your help on this. I really owe you. I will let you know as soon as possible what do I have done.

Marius Vosylius

unread,
Mar 24, 2014, 9:23:01 AM3/24/14
to ioio-...@googlegroups.com
Dear Ytai,

Here's what I have so far: 

  1. My A0 pin Connected to GND, in this case it means my address is 0x48 (Please correct me if Im wrong).
  2. TMP102 connections to IOIO-OTG:
    • VCC <-> IOIO 3.3V
    • GND <-> IOIO GND
    • SCL <-> IOIO SCL (Pin2)
    • SDA <-> IOIO SDA (Pin1)
    • ADD0<->IOIO GND
    I have created new Class in my project called Temp and added as follows:

    public class Temp {
      public static int from(byte b) {
        return b & 0xFF;
      }

      public static int from(short s) {
        return s & 0xFFFF;
      }
    }

    Please advise me if Im following as required. I will post the rest once I have it.

    Thank You.




    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 11:52:27 AM3/24/14
    to ioio-...@googlegroups.com
    Other than your weird choice of naming, everything sounds fine.


    Marius Vosylius

    unread,
    Mar 24, 2014, 1:26:28 PM3/24/14
    to ioio-...@googlegroups.com
    Main Class:

    private TwiMaster twi;

    private static final byte address = 0x48;

    private static final byte[] request = {0x00};

    private final byte[] response = new byte[2];


    Looper Class:

    class Looper extends BaseIOIOLooper {

    public void setup() throws ConnectionLostException {

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

    runOnUiThread(new Runnable() { 

                public void run() { 

                    Toast.makeText(getApplicationContext(), 

                            "TMP102 Connected!", Toast.LENGTH_SHORT).show(); 

                    }        

                });

    }


    public float getTemperature() throws Exception {

       

    if (!twi.writeRead(address, false, request, 1, response, 2)) {

      throw new Exception("I2C transaction with TMP102 failed.");

    }

    int temp = Temp.from(response[0]) << 8 | Temp.from(response[1]);

    temp >>= 4;

    return temp / 16.f + 273.15f;    

    }

    }

    Is this what I have is Correct?  I don't get any error. 


    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 1:34:58 PM3/24/14
    to ioio-...@googlegroups.com
    That seems OK. If I were you I would probably leave the INA226 as a class and use it from the Looper, but that's mostly a stylistic matter.


    Marius Vosylius

    unread,
    Mar 24, 2014, 1:42:36 PM3/24/14
    to ioio-...@googlegroups.com
    So how I can Output the reading Please?

    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 1:57:26 PM3/24/14
    to ioio-...@googlegroups.com
    See IOIOSimpleApp as an example that reads a value from an analog input. Simply replace the analog voltage reading with a call to your getTemperature() method.

    Marius Vosylius

    unread,
    Mar 24, 2014, 2:57:43 PM3/24/14
    to ioio-...@googlegroups.com
    Still can't figure it out, can you please help Ytai. 

    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 3:27:17 PM3/24/14
    to ioio-...@googlegroups.com

    Can you send your latest code as well as a more elaborate explanation on what's not working?

    Marius Vosylius

    unread,
    Mar 24, 2014, 3:32:16 PM3/24/14
    to ioio-...@googlegroups.com

    class Looper extends BaseIOIOLooper {

    public void setup() throws ConnectionLostException {

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

    runOnUiThread(new Runnable() { 

                public void run() { 

                    Toast.makeText(getApplicationContext(), 

                            "TMP102 Connected!", Toast.LENGTH_SHORT).show(); 

                    }        

                });

    }


    public float getTemperature() throws Exception {

    if (!twi.writeRead(address, false, request, 1, response, 2)) {

      throw new Exception("I2C transaction with TMP102 failed.");

    }

    int temp = Temp.from(response[0]) << 8 | Temp.from(response[1]);

    temp >>= 4;

    return temp / 16.f + 273.15f;

    }

    }

    protected IOIOLooper createIOIOLooper() {

            return new Looper();

    }

    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 4:27:40 PM3/24/14
    to ioio-...@googlegroups.com
    Where's your loop() method? The getTemperature() method doesn't seem to be called from anywhere...


    --

    Marius Vosylius

    unread,
    Mar 24, 2014, 4:33:29 PM3/24/14
    to ioio-...@googlegroups.com
    what do In need to have in a loop?

    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 4:35:57 PM3/24/14
    to ioio-...@googlegroups.com
    Read my previous post please (about IOIOSimpleApp)

    Marius Vosylius

    unread,
    Mar 24, 2014, 4:45:56 PM3/24/14
    to ioio-...@googlegroups.com
    getTemperature should be outside Looper class?

    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 4:50:42 PM3/24/14
    to ioio-...@googlegroups.com

    It should be periodically called from loop() and the result sent to the UI widget (TextView).

    Message has been deleted

    Marius Vosylius

    unread,
    Mar 24, 2014, 5:11:07 PM3/24/14
    to ioio-...@googlegroups.com
    Sorry Ytai, but I just don't understand it. Im only new in Java and android, so I need some example to understand. 
    Message has been deleted

    Marius Vosylius

    unread,
    Mar 24, 2014, 6:15:33 PM3/24/14
    to ioio-...@googlegroups.com
    Ytai, Could you have a look what is wrong as Im still cant get output:

    class Looper extends BaseIOIOLooper {

    public void setup() throws ConnectionLostException {

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

    runOnUiThread(new Runnable() { 

                public void run() { 

                    Toast.makeText(getApplicationContext(), 

                            "TMP102 Connected!", Toast.LENGTH_SHORT).show(); 

                    }        

                });

    }

    public void loop() throws ConnectionLostException, InterruptedException {

    try {

    twi.writeRead(address, false, request, request.length, response, response.length);

    /* Update UI */

    updateViews(getTemperature());

    } catch (InterruptedException e) {

    ioio_.disconnect();

    } catch (ConnectionLostException e) {

    throw e;

    } catch (Exception e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    public float getTemperature() throws Exception {

    if (!twi.writeRead(address, false, request, 1, response, 2)) {

      throw new Exception("I2C transaction with TMP102 failed.");

    }

    int temp = Temp.from(response[0]) << 8 | Temp.from(response[1]);

    temp >>= 4;

    return temp / 16.f + 273.15f;

    }

    }

    private void updateViews(float f) {

    final String str = String.format("%.2f", f);

    runOnUiThread(new Runnable() {

    @Override

    public void run() {

    tmpTextView.setText(str);

    }

    });

    }



    Ytai Ben-Tsvi

    unread,
    Mar 24, 2014, 6:21:06 PM3/24/14
    to ioio-...@googlegroups.com

    The code seems OK. What are you seeing in the logs?
    Also, did you intentionally change the TWI number back to 0?

    Marius Vosylius

    unread,
    Mar 25, 2014, 2:21:32 AM3/25/14
    to ioio-...@googlegroups.com
    Ytai, Finally I got some output now on my app. But readings does it look correct I get 288.65 288.71. 

    Ytai Ben-Tsvi

    unread,
    Mar 25, 2014, 3:48:07 AM3/25/14
    to ioio-...@googlegroups.com

    Looks OK. Those are in degrees Kelvin.

    Marius Vosylius

    unread,
    Mar 25, 2014, 5:39:18 AM3/25/14
    to ioio-...@googlegroups.com
    How would I get C?

    Another Question Ytai, Can I connect another Sensor which uses same SLA DLA? And which pins would I need to use this time. Thanks.

    Ytai Ben-Tsvi

    unread,
    Mar 25, 2014, 12:57:46 PM3/25/14
    to ioio-...@googlegroups.com
    To get Celsius, get rid of the +273.15.

    You can connect as many devices as you want on the same I2C bus, as long as they have distinct addresses. With the SparkFun TMP102, there's a slight problem that the breakout board has pull-ups on it, so if you connect too many of those in parallel you'd end up with excessively strong pull-ups.

    Alternatively, the IOIO has 3 I2C busses that you can use.

    Marius Vosylius

    unread,
    Mar 25, 2014, 2:02:31 PM3/25/14
    to ioio-...@googlegroups.com
    Thank You A Lot! 

    Marius Vosylius

    unread,
    Mar 25, 2014, 2:30:47 PM3/25/14
    to ioio-...@googlegroups.com
    Its means for my Humidity Sensor HH10D I can use Pin 4 & 5. 

    https://www.sparkfun.com/datasheets/Sensors/Temperature/HH10D.pdf

    And what would be an address for this sensor, I can see here 10 11 12 & 13, so do I need to use them all? Or just one specific?


    On Tuesday, March 25, 2014 4:57:46 PM UTC, Ytai wrote:

    Ytai Ben-Tsvi

    unread,
    Mar 25, 2014, 3:58:37 PM3/25/14
    to ioio-...@googlegroups.com
    The way I'm interpreting the datasheet is the following:
    There's an I2C EEPROM at address 0x01, from which you need to read back 4 bytes (addresses 10:13). These bytes translate into two 2-byte calibration values that you'll need to convert the output signal to actual humidity values.
    The output signal ("fout") is a periodic digital signal whose frequency is related to the humidity. You probably want to use a PulseInput on the IOIO to measure the frequency, then use the two calibration values and the measured frequency to convert it to humidity using the formula given in the datasheet:
    RH(%) = (offset-Soh)*sens/2^12,
    where offset and sens are the two EEPROM values and Soh is the measured frequency (probably in Hz units).

    Message has been deleted

    Ytai Ben-Tsvi

    unread,
    Mar 31, 2014, 11:41:12 AM3/31/14
    to ioio-...@googlegroups.com
    This approach seems OK (assuming that you want the full scale to go between 0-100).
    As a stylistic matter, I would probably move the progress bar setting inside updateViews(), using the same Runnable.


    On Mon, Mar 31, 2014 at 5:24 AM, Marius Vosylius <marius....@gmail.com> wrote:
    Dear Ytai, Im trying to set Progress Bar for my Temperature Value Im not sure how its done, heres my code:

    class Looper extends BaseIOIOLooper {

    public void setup() throws ConnectionLostException {

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

    runOnUiThread(new Runnable() { 

                public void run() { 

                    Toast.makeText(getApplicationContext(), 

                            "TMP102 Connected!", Toast.LENGTH_SHORT).show(); 

                    }        

                });

    }

    public void loop() throws ConnectionLostException, InterruptedException {

    try {

    twi.writeRead(address, false, request, request.length, response, response.length);

    /* Update UI */

    updateViews(getTemperature());

    setProgressBar(); ???

    } catch (InterruptedException e) {

    ioio_.disconnect();

    } catch (ConnectionLostException e) {

    throw e;

    } catch (Exception e) {

    e.printStackTrace();

    }

    }

    // Get Temperature in C Method

    public float getTemperature() throws Exception {

    celcius = Temp.from(response[0]) << 8 | Temp.from(response[1]);

    celcius >>=4;

    return celcius / 16.f;

    }

    }

    // Update TextView with Temperature Reading

    private void updateViews(float f) {

    final String str = String.format(Locale.UK, "%.1f", f);


    runOnUiThread(new Runnable() {

    @Override

    public void run() {

    tmpTextView.setText(str);

    }

    });

    }

    // Set Value to ProgressBar

    private void setProgressBar(final int value) {

    runOnUiThread(new Runnable() {

    @Override

    public void run() {

    progressBarTemp.setProgress(value);

    }

    });

    }


    My XML File for ProgressBar:

    <ProgressBar

            android:id="@+id/progressBarTemp"

            style="?android:attr/progressBarStyleHorizontal"

            android:layout_width="250dp"

            android:layout_height="273dp"

            android:layout_centerHorizontal="true"

            android:layout_centerVertical="true"

            android:indeterminate="false"

            android:max="100"

            android:progress="0"

            android:progressDrawable="@drawable/circular_progressbar" />


    And my Circular progress Bar in Drawable Folder:

    <?xml version="1.0" encoding="utf-8"?>

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/progress">


    <shape android:shape="ring"

                  android:innerRadiusRatio="4"

                  android:thicknessRatio="8.0">

      <gradient

                android:startColor="#287AA9"

                android:centerColor="#FFCC00"

                android:endColor="#ff0000"

                android:type="sweep" />   

    </shape>

    </item>

    </layer-list>

    Marius Vosylius

    unread,
    Apr 1, 2014, 4:39:06 PM4/1/14
    to ioio-...@googlegroups.com
    I was able to competed this successfully, Thank you Very Much for your Help with this Sensor Ytai!

    bourd...@gmail.com

    unread,
    Jan 20, 2015, 4:07:42 AM1/20/15
    to ioio-...@googlegroups.com, marius....@gmail.com
    Hello,

    I'm having a hard time with TMP102 sensor.

    Thanks to Ytai code snippet conversion and register reading is correct.

    What is incorrect seems to be the sensor itself.

    Analog thermometer is used as a reference, and I get errors from 6° to 1,5° in excess on the tmp102, In "ambient temperature" area (from 10°c to 25°c)
    I tested with another TMP102 sensor (also purchased from sparkfun, thus with a different pin layout), the same weird behavior.
    The error seems to be changing over time (As if the sensor needed 30+ minutes to stabilize) but never disappears. At the time being I have set a "-1.5" correction.

    The sensor is read every 5 seconds.


    I tested the same tmp102 sensor on a arduino board (with a very fast loop), and the readings are correct (well, within 0.2°c of the reference thermometer).



    I wonder If the arduino fast loop helps the sensor reaching operational conditions (let's call that warming up ?), and the 5 sec loop on the android does not allow tmp102 to work properly. Or maybe my ioio power supply is interfering (8 volts, 1000mah) with the tmp102 (sensor VCC is plugged to 3v on the board itself).


    I'm working on a thermostat, temperature reading reliability is rather important.


    I ordered an MCP9808 sensor to compare readings.

    Any idea, testing pattern or any "reliable" sensor to recommend ?


    (BTW Ytai : Many, many thanks for your great work. )

    Ytai Ben-Tsvi

    unread,
    Jan 21, 2015, 1:05:44 AM1/21/15
    to ioio-...@googlegroups.com, marius....@gmail.com
    1. The 3.3V rail on the IOIO should be very stable, I don't think this is a likely problem.
    2. Can you share your electrical diagram as well as a minimal app with which you're seeing the problem?
    3. Is it possible that for some reason the sensor is actually indeed warmer than the reference with this setup?
    Since you're actually able to talk to the sensor, I find it hard to imagine what sort of conditions may cause reading an incorrect temperature. I've used this sensor pretty extensively in the past (both with and without the IOIO) and tend to trust it a lot.

    --

    bourd...@gmail.com

    unread,
    Jan 21, 2015, 2:07:17 PM1/21/15
    to ioio-...@googlegroups.com, marius....@gmail.com
    Thanks for your prompt reply;

    So I'm going to pretend i did NOT swap ADD0 and ALT pins on the sensor.

    After much, pain - (I broke my whole dev environment updating sdk and my low cost android cellphone do not seem to like the latest adb, reinstall everything from scratch -  while I was finalizing the fritzing pictures for this post I had an horrible doubt, searched for multiple internet sources  and I wired my tmp102 the wrong way : after grounding pin ADD0 instead of pin ALT all readings seem to be more in my acceptable range. 0.5°c




    bourd...@gmail.com

    unread,
    Jan 21, 2015, 2:12:51 PM1/21/15
    to ioio-...@googlegroups.com, marius....@gmail.com
    The code is set this way (may seem familiar...)

    I'll have to check behavior in the morning, to see if the 0.5°c difference is a reliable constant value.



    Class for unsigned

    ----------------------------------------------------------

     

    public class Unsigned {

      public static int from(byte b) {

        return b & 0xFF;

      }

     

      public static int from(short s) {

        return s & 0xFFFF;

      }

    }

      ----------------------------------------------------------

     

     

     

     

     

     

     I used helloIOio as a canvas, added tmp102 reading

     

      ----------------------------------------------------------

     

     public float Readtmp102(int address, TwiMaster port) {

     

     

    float returnval = 0;

                                        byte[] request = new byte[] { 0x00 };

                byte[] tempdata = new byte[2];

                   try {

                           port.writeRead(address, false, request,request.length,tempdata,tempdata.length);

                           

                           //This code good, comes from Ytai

    int temp = Unsigned.from(tempdata[0]) << 8 | Unsigned.from(tempdata[1]);

    temp >>= 4;

    Float Celsiustemp =  temp / 16.f;

     

     

    return         Celsiustemp;                  

                  

    } catch (ConnectionLostException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    Log.e("tmp102test","ConnectionLost Exception in Readtmp102 : "+e);

    } catch (InterruptedException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    Log.e("tmp102test","InterruptedException Exception in Readtmp102 : "+e);                

    } finally {}

      

       return returnval;

    }

     

     

    private void setTemperatureSensor(final String str) {

    runOnUiThread(new Runnable() {

    @Override

    public void run() {

    textView1_.setText(str+" °c");

    }

    });

    }

     

     

    /**

     * Called every time a connection with IOIO has been established.

     * Typically used to open pins.

     *

     * @throws ConnectionLostException

     *             When IOIO connection is lost.

     *

     * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()

     */

    @Override

    protected void setup() throws ConnectionLostException {

    led_ = ioio_.openDigitalOutput(0, true);

     

    //tmp102

    twi_temperature = ioio_.openTwiMaster(0, TwiMaster.Rate.RATE_100KHz, false);

    }

     

    /**

     * Called repetitively while the IOIO is connected.

     *

     * @throws ConnectionLostException

     *             When IOIO connection is lost.

     *

     * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()

     */

    @Override

    public void loop() throws ConnectionLostException {

     

     

    //read tmp102

    Float SensorTemperature = Readtmp102(0x48, twi_temperature);

    Log.v("tmp102test"," Readtmp102 : "+SensorTemperature);        

     

    setTemperatureSensor(String.valueOf(SensorTemperature));

     

    led_.write(!button_.isChecked());

    try {

    Thread.sleep(1000);

    } catch (InterruptedException e) {

    }

     

     

     

    }


    ----------------------------------------------------------


    (I would like to apologise for the clumsy post layout, i'm not used to groups.google)



    On Friday, March 21, 2014 at 9:59:40 PM UTC+1, Marius Vosylius wrote:
    I'm struggling to get my TWI reading out, Im not sure where Im going wrong?

    TMP102 DataSheet

    Any help or example would me really appreciated. 

    Main Class:

    // IOIO pin 26 = SDA, pin 25 = SCL

    private final int twiNum = 26;

    // TextView Display Temperature

    private TextView tmpTextView;

    private TwiMaster twi;

    int address;

    byte[] request = new byte[] { 0x00, 0x48};

    byte[] response = new byte[4];

    Setup:

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

    Loop:

    address = 0x48;

    try {

    twi.writeRead(address, false, request, request.length, response, response.length);

    /* Update UI */

    updateViews();

    } catch (InterruptedException e) {

    ioio_.disconnect();

    } catch (ConnectionLostException e) {

    throw e;

    }

    private void updateViews() {

    runOnUiThread(new Runnable() {

    @Override

    public void run() {

    tmpTextView.setText(String.valueOf(response));

    }

    });

    }    

    Ytai Ben-Tsvi

    unread,
    Jan 21, 2015, 4:21:35 PM1/21/15
    to ioio-...@googlegroups.com, Marius Vosylius

    OK, great! Let me know if there's anything else I can help with.

    Javier Soriano

    unread,
    Jan 22, 2015, 6:35:06 PM1/22/15
    to ioio-...@googlegroups.com
    Hi Ytai,

    I'm working now in this project. I have read all the examples that other users and you post here and I tried to implement it. However, I don't know why the app doesn't show the temperature. I append the MainActivity.java in this message.

    Thanks in advance!!


    MainActivity.java

    Ytai Ben-Tsvi

    unread,
    Jan 25, 2015, 5:46:53 PM1/25/15
    to ioio-...@googlegroups.com
    Doesn't seem like you're checking the return value of writeRead(). Any chance it is returning false? If so, common problems are bad connections (loose), wrong pins, forgetting pull-ups, forgetting common ground, not configuring the TMP102 address correctly, using the wrong address from code.
    For debugging I would encourage you to Log.d(...) your readings to get GUI-related problems out of the possible things that can go wrong.

    bourdonnais

    unread,
    Feb 23, 2015, 8:38:29 AM2/23/15
    to ioio-...@googlegroups.com
    Hello,

    I wanted to share an update.

    My ioio system has been somewhat in production for 3 weeks. 

    I did apply a correction to the values read by tmp102 sensor yesterday.
    I currently run with -3.5° celsius correction to get a credible value.

    I expect the cause to be somehow hardware related (a slow creep, a variable error)

    Maybe the very variable humidity (between 30% and 70%, temp between 5°c and 20°c) is the cause of the readings I get.

    I have now two more ioio boards to discover the origin of that gremlin. As the ioiothingy is a temperature controlling magic wand, temp reading accuracy is somehow... vital.

    I will wire tmp102 & MCP9008, and maybe a couple of other sensors (combined humidity & temperature) as a "lab".
    And I'll hook a dht22 on an arduino too.


    pogono

    unread,
    Feb 24, 2015, 2:35:30 PM2/24/15
    to ioio-...@googlegroups.com
    hello,

    I just need to connect humidity & temperature sensor to ioio for logging purpose. I could not decide which sensor I should select because of my poor knowledge of electronics. Your shares are a very valuable source for me, thank you bourdonnais.

    I searched & read in forum that Ytai says "in general, if you use I2C, SPI or analog interface sensors you should be good. 1-wire is not currently supported."

    Today, actually I searched and noted which sensors I guess can use: (in the order of cost) 
    DHT22 - https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf (already has a box and mentioned to support up to 20m cable) Which type output does this have from above Ytai definition?
    Texas Instruments HDC100x -

    My aim is to have nonstop continuous logging of a sensor that connected to ioio via cable which will be used in close area with roughly range of temp: -20 to 80 C & humidity: 5 to 95%. I would be appreciated if you comment any suggestion to select a sensor for my purpose.

    Thanks in advance,

    23 Şubat 2015 Pazartesi 15:38:29 UTC+2 tarihinde bourdonnais yazdı:

    Ytai Ben-Tsvi

    unread,
    Feb 24, 2015, 11:26:16 PM2/24/15
    to ioio-...@googlegroups.com
    I haven't checked the sensor specs as far as sensing - I'll let you read the datasheet and meet your application-specific requirements.
    As far as compatibility with the IOIO, the DHT22 is not (easily) compatible, the Sensirion lists most of the sensors of this family as having an I2C interface (compatible with the IOIO), as well as the TI sensor and all the Honeywell ones (either I2C or SPI should work).
    Reply all
    Reply to author
    Forward
    0 new messages