I2C Development

I'm planning to interface a honeywell I2C humidity sensor (HIH6130-021-001) to Metawear. I'm used to traditional development for embedded devices using C. What documentation should I refer to for interfacing with an arbitrary I2C peripheral device?

Thanks,
Jeremy

Comments

  • Jeremy,

    There are I2C examples in the android and ios docs, www.mbientlab.com/iosdocs
  • Hi Laura,

    Is there any way you can create a diagram similar to the one below, but replace the Arduino with the Metawear R:
    image

    Ideally, I would like to control the AD5171 digital potentiometer using the Metawear R.

    Thank you
  • edited August 2015
    Ok I did this really quick but it should work:

    POT - MW

    W - LED is hooked up with series res and then to ground
    VDD - 3V (pin 7 or pin 11)
    GND - GND (pin 4 or pin 3)
    SCL - I2C (SCL pin 6)

    A - 3V (pin 7 or pin 11)
    B - GND (pin 4 or pin 3)
    AD0 - GND (pin 4 or pin 3)
    SDA - I2C (SDA pin 5)

    You don't need to add the 4.7Kohm pull up resistors; they are already on the MW board.
    You can add the LED in the same way with a 1Kohm series res if it doesn't have an internal res.

    Then you can see the I2C section of the ios/android docs to get data from the pot. Please mind the address.
  • Another question regarding I2C: Is it possible to issue a read with no register address? My humidity sensor has no register map and only outputs a 2 byte humidity value.
  • Another question regarding I2C: I have a sensor that needs 3 registers to activate it. In arduino, I do wire.begintransmission(address); followed by wire.write(value) to write in subsequent registers. I am not able to reciprocate it with metawear, any additional documentation/example for I2C would be very helpful. 


  • Never mind. I created a new MBLI2CData object for each register I wanted to write and it worked. I don't like this idea of creating so many objects and sending instructions via bluetooth, it would be awesome if we can put all the I2C code into mbientwear just like in an arduino.
  • @Jeremy, it is a little unconventional to skip the register address in I2C so it is not presently supported in our firmware.  Have you tried passing an address of 0x00 in when doing the read and write to see that works with the sensor?  Often times the devices ignore commands that do not come in according to spec.  If it does not work, this can be fixed easily in the next firmware release.

    We are able to swap out the pressure sensor on the RPro with a humidity+pressure sensor, and in the near future we will make that available with a full API.
  • @veeru, MetaWear has in internal system for executing sequences of commands local to the device.  This can be used with multiple I2C operations to issue a start command followed by a read data command.  They can also be connected to a timer to perform periodic reads from the sensor device.  Want to log that data when the phone is not connected?  There is an offline logging API for that as well.

    Each function can be connected together quickly and easily through the API.  With just a couple lines of code, you could read the sensor every 2 seconds by issuing 3 I2C commands and log the result.  It would require a lot of code, time, and debugging to do this in Arduino.
  • Matt,

    Thanks for the response. I'm still waiting for the daughterboard I built to ship so that I can test the I2C interface. I'll let you know what I find -- it would be great to have more flexible I2C support in a subsequent firmware rev.

    Thanks,
    Jeremy
  • Matt,
    Sorry for getting back late but thanks for the info. Could you guide me on how to do offline logging ?
    I am still new to IOS development so finding the journey difficult, my background is C# and Arduino. Sorry for being silly in my questions.

    And any thoughts on adding UART to your platform in the near future ?

    thanks,
    Veeru
  • I think I found the guide/example : http://projects.mbientlab.com/persistent-events-and-filters/

    thanks,
    Veeru
  • UART is something we considered but it is not high on our priority list at this time.

    I'd also check out the iOS documentation regarding logging (https://mbientlab.com/iosdocs/#e-log).
  • I finally got around to testing my humidity sensor and it seems there are some issues getting the MetaWear to communicate with it.

    As we had discussed before, the humidity sensor is a bit unconventional in that it has no register addresses. Communication protocol is described here: http://sensing.honeywell.com/i2c-comms-humidicon-tn-009061-2-en-final-07jun12.pdf

    The code I am using to initiate a measurement is:
    i2cModule.writeData((byte)0x27, (byte)0x00, dummy_array);

    byte 0x27 corresponds to the device's address, byte 0x00 is a dummy value that corresponds to the address (device doesn't support addresses, which is why I use 0x00) and dummy_array is passed as either empty or a single byte array that contains 0x00.

    To read the measurement back (after a delay of 50 ms), I use the following command:
    i2cModule.readData((byte)0x27, (byte)0x00, (byte) 4).onComplete(new CompletionHandler<byte[]>() {
          @Override
          public void success(byte[] result) {
          Log.i("MainActivity", String.format("TRY_ONE= %x %x %x %x", result[0], result[1], result[2], result[3]));
          }
    });

    I know that communication is working on some level since if I include an invalid device ID (not 0x27), I get no response back at all. If I include the correct device ID (0x27), I get back my 4 byte array as {0x7f, 0xff, 0xff, 0xfd}. This corresponds to the status bits being set according to no measurement data being available, with all measurement bits set to 1.

    Long story short, my suspicion is that the write operation is not performed correctly and a measurement never starts. Is there any way to check the status of the write command in Android? I guess my next step will be to check with a logic analyzer to see what is happening on the data and clock lines.

    Thanks,
    Jeremy
  • edited December 2015
    There is not way to check the result of the write.  That information is not available to the API.
  • I verified that the write completes with a logic analyzer, but it seems the extra '0' bytes are causing the transactions to fail. Are there any plans to expand I2C API flexibility in future firmware releases?
  • After a bunch of debugging, I determined that I was dealing with a bad humidity sensor (it must have been damaged during board population). I can confirm that the Metawear API works fine when talking to an undamaged sensor :-)

    Cheers,
    Jeremy
  • That's good hear!  At this time, we don't have any plans to expand the I2C functionality.
This discussion has been closed.