How to read datas from 2 different I2C sensors connected to the 2 I2C output of the Wio Terminal?

Hello,

The question is in the title, I would like to connect both MAX30102 and MLX90614 to the Wio Terminal and display the values on the screen. How can I control the 2 I2C? Plus I have the problem that example code for MLX90614 is not working and I noticed there is no Wire library inclusion inside

I have tried to include the library and modify the code that way but it doesn’t work:

/***************************************************
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1747 3V version
  ----> https://www.adafruit.com/products/1748 5V version

  These sensors use I2C to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_MLX90614.h>
#include <Wire.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("Adafruit MLX90614 test");

  //if (!mlx.begin(Wire)) {
  if (!mlx.begin(Wire)) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };

  Serial.print("Emissivity = "); Serial.println(mlx.readEmissivity());
  Serial.println("================================================");
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}

I get this error : exit status 1
no matching function for call to 'Adafruit_MLX90614::begin(TwoWire&)'

Here is the code source

/**
 * @brief Begin the I2C connection
 * @param addr I2C address for the device.
 * @param wire Pointer to Wire instance
 * @return True if the device was successfully initialized, otherwise false.
 */
bool Adafruit_MLX90614::begin(uint8_t addr, TwoWire *wire) {
  _addr = addr; // needed for CRC
  if (i2c_dev)
    delete i2c_dev;
  i2c_dev = new Adafruit_I2CDevice(addr, wire);
  return i2c_dev->begin();
}

What adress should I use? I didn’t manage to run a I2C scan code I found Arduino Playground - I2cScanner

Thanks

The hardware of wio Terminal has only one IIC. If you need to use multiple IIC, you may need to buy expansion hardware.

1 Like

Thanks for the answer!

But why are there I2C0 and I2C1 pins then?

Sorry, I see it as another product. For Wio Terminal, if the IIC address is not changed by default, the output content is the same. If it needs to be used separately, the IIC address needs to be configured.

1 Like
#include <Wire.h>

void setup(){ 
  Serial.begin(9600);
  Wire.begin();
  for (int i = 0; i < 127; i++){  
    Wire.beginTransmission(i);
    int error = Wire.endTransmission();
    if (error == 0){
      Serial.println();   
      Serial.print("Device is found at : 0x");   
      Serial.println(i,HEX);  
    }
  }
}


void loop(){
  
}

You can use this code to query the available IIC address of the device

1 Like

Thank you very much for this !

What would be the code then to configure the I2C adress?

I am not able to try your program to identify the I2C next week but I will try as soon as I am back the week after!! Thanks again

The addresses I found are the two on the picture, you can try

Actually, I have tried your code but nothing happen when I try to open the serial monitor… Any idea what is the problem?
I have also tried the code

  // --------------------------------------
    // i2c_scanner
    //
    // Version 1
    //    This program (or code that looks like it)
    //    can be found in many places.
    //    For example on the Arduino.cc forum.
    //    The original author is not know.
    // Version 2, Juni 2012, Using Arduino 1.0.1
    //     Adapted to be as simple as possible by Arduino.cc user Krodal
    // Version 3, Feb 26  2013
    //    V3 by louarnold
    // Version 4, March 3, 2013, Using Arduino 1.0.3
    //    by Arduino.cc user Krodal.
    //    Changes by louarnold removed.
    //    Scanning addresses changed from 0...127 to 1...119,
    //    according to the i2c scanner by Nick Gammon
    //    https://www.gammon.com.au/forum/?id=10896
    // Version 5, March 28, 2013
    //    As version 4, but address scans now to 127.
    //    A sensor seems to use address 120.
    // Version 6, November 27, 2015.
    //    Added waiting for the Leonardo serial communication.
    //
    //
    // This sketch tests the standard 7-bit addresses
    // Devices with higher bit address might not be seen properly.
    //
     
    #include <Wire.h>
     
     
    void setup()
    {
      Wire.begin();
     
      Serial.begin(9600);
      while (!Serial);             // Leonardo: wait for serial monitor
      Serial.println("\nI2C Scanner");
    }
     
     
    void loop()
    {
      byte error, address;
      int nDevices;
     
      Serial.println("Scanning...");
     
      nDevices = 0;
      for(address = 1; address < 127; address++ )
      {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
     
        if (error == 0)
        {
          Serial.print("I2C device found at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.print(address,HEX);
          Serial.println("  !");
     
          nDevices++;
        }
        else if (error==4)
        {
          Serial.print("Unknown error at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.println(address,HEX);
        }    
      }
      if (nDevices == 0)
        Serial.println("No I2C devices found\n");
      else
        Serial.println("done\n");
     
      delay(5000);           // wait 5 seconds for next scan
    }

Ok actually your code has worked thanks a lot !!

And I get the same than you. Now I am able to read the value of the MAX30102 sensor connected to I2C1 (pins 3 and 5), how can I do to use I2C0?(pins 27 and 28)?