About I2C multi devices address init problem

Hi all.

The sketch below works well for dfrobot voice recognition module, with library:

Question is when I try to add another I2C device SSD1306, and respectively init them:

oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);

while (!(asr.begin(0x64)));

got compiling error of: no matching function for call to 'DFRobot_DF2301Q_I2C::begin(int)'

how to fix please.

Thanks
Adam

/*!
 * @file  i2c.ino
 * @brief Control the voice recognition module via I2C
 * @n  Get the recognized command ID and play the corresponding reply audio according to the ID;
 * @n  Get and set the wake-up state duration
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence  The MIT License (MIT)
 * @author  [qsjhyy](yihuan.huang@dfrobot.com)
 * @version  V1.0
 * @date  2022-04-02
 * @url  https://github.com/DFRobot/DFRobot_DF2301Q
 */
#include "DFRobot_DF2301Q.h"

#define Led 8

//I2C communication
DFRobot_DF2301Q_I2C asr;

void setup() {
  Serial.begin(115200);

  pinMode(Led, OUTPUT);    //Init LED pin to output mode
  digitalWrite(Led, LOW);  //Set LED pin to low 

  // Init the sensor
  while (!(asr.begin())) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");

  /**
   * @brief Set voice volume
   * @param voc - Volume value(1~7)
   */
  asr.setVolume(4);

  /**
     @brief Set mute mode
     @param mode - Mute mode; set value 1: mute, 0: unmute
  */
  asr.setMuteMode(0);

  /**
     @brief Set wake-up duration
     @param wakeTime - Wake-up duration (0-255)
  */
  asr.setWakeTime(20);

  /**
     @brief Get wake-up duration
     @return The currently-set wake-up period
  */
  uint8_t wakeTime = 0;
  wakeTime = asr.getWakeTime();
  Serial.print("wakeTime = ");
  Serial.println(wakeTime);

  // asr.playByCMDID(1);   // Wake-up command

  /**
     @brief Play the corresponding reply audio according to the ID
     @param CMDID - command word ID
  */
  //asr.playByCMDID(23);  // Command word ID
}

void loop() {
  /**
     @brief Get the ID corresponding to the command word 
     @return Return the obtained command word ID, returning 0 means no valid ID is obtained
  */
  uint8_t CMDID = asr.getCMDID();
  switch (CMDID) {
    case 103:                                                  //If the command is “Turn on the light”
      digitalWrite(Led, HIGH);                                 //Turn on the LED
      Serial.println("received'Turn on the light',command flag'103'");  //Serial transmits "received"Turn on the light",command flag"103
      break;

    case 104:                                                  //If the command is “Turn off the light”
      digitalWrite(Led, LOW);                                  //Turn off the LED
      Serial.println("received'Turn off the light',command flag'104'");  //The serial transmits "received"Turn off the light",command flag"104""
      break;

    default:
      if (CMDID != 0) {
        Serial.print("CMDID = ");  //Printing command ID
        Serial.println(CMDID);
      }
  }
  delay(300);
}

ERROR:

Arduino: 1.8.19 (Windows 7), Board: "ESP32 Dev Module, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Enabled"

C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32_DFRobot_AA2\ESP32_DFRobot_AA2.ino: In function 'void setup()':

ESP32_DFRobot_AA2:39:27: error: no matching function for call to 'DFRobot_DF2301Q_I2C::begin(int)'

    while (!(asr.begin(0x64))) {   // add address

                           ^

In file included from C:\Users\HUA.DELLV-PC\Documents\Arduino\ESP32_DFRobot_AA2\ESP32_DFRobot_AA2.ino:21:

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\DFRobot_DF2301Q-master/DFRobot_DF2301Q.h:137:16: note: candidate: 'virtual bool DFRobot_DF2301Q_I2C::begin()'

   virtual bool begin(void);

                ^~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\DFRobot_DF2301Q-master/DFRobot_DF2301Q.h:137:16: note:   candidate expects 0 arguments, 1 provided

exit status 1

no matching function for call to 'DFRobot_DF2301Q_I2C::begin(int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

In your example code the function begin

called without parameter.

Why did you try to call the function with parameter?

1 Like

Thanks.
I try to add another I2C device OLED ssd1306, code doesn't run well without I2C address inserted.

The reason is something else.
Just because you don't explicitly indicate an address - doesn't mean the address doesn't exist. No i2c device can operate without an address, even if there is only one device on the bus. The library DFRobot_DF2301Q.h itself assigns the address to your module (and exactly 0x64, as you wanted to indicate)

1 Like

Thank you.
I'll test them more.
the OLED and DFRobot works well individually now. stopped in setup as long as combined their code together.

Do you have a pullup resistors on SDA and SCL lines?

1 Like

not yet, I'll set that and test.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.