Example Code for Arduino-I2C Recording

This guide details the process of setting up an Arduino-I2C voice recorder, outlining the necessary hardware and software preparations, and providing sample code to facilitate the recording process.

Hardware Preparation

Software Preparation

Wiring Diagram

  1. Connect the Gravity-4P I2C interface to the main control board I2C interface. If you don’t need I2C control, leave the blue and green wires unconnected.
    • Red: 3.3~5V +
    • Black: GND -
    • Blue: I2C SCL
    • Green: I2C SDA
  2. Connect the 3.5mm headphone jack or the PH2.0 speaker port, the two cannot be connected at the same time, otherwise the audio will not be played normally.

Other Preparation Work

  1. Connect according to the wiring instructions
  2. Install the library file as per the link provided.

Sample Code

#include "DFRobot_VoiceRecorder.h"

#define I2C_ADDRESS  0x30 // default I2C address 0x30
DFRobot_VoiceRecorder_I2C voicerecorder(&Wire, I2C_ADDRESS);

void setup()
{
  Serial.begin(115200);
  while (voicerecorder.begin() != 0) {
    Serial.println("i2c device number error!");
    delay(1000);
  } Serial.println("i2c connect success!");

  Serial.println("Delect Voice 0");
  voicerecorder.setVoiceNumber(VOICE_NUMBER_0);

  Serial.println("Delete Voice");
  voicerecorder.deleteVoice();

  for (int8_t n = 3; n > 0; n--)
  {
    Serial.println(n);
    delay(1000);
  }

  Serial.println("Recode Start");
  voicerecorder.recordvoiceStart();

  for (int8_t n = 20; n > 0; n--)
  {
    Serial.println(n);
    delay(1000);
  }

  voicerecorder.recordVoiceEnd();
  Serial.println("Recode End");
}

void loop()
{
}

Result

Expected behavior: The serial monitor will display the connection status, countdown, recording start, and recording end. The module will record for 20 seconds, with the digital tube showing the remaining recording time.

Additional Information

The default I2C address of the module is 0x30. To change the address, refer to the I2C Address Settings in the Communication Protocol Description section.

Was this article helpful?

TOP