Example Code for Arduino-Read 8*8 Matrix Data via I2C

This article is a detailed guide for reading 8x8 matrix data using Arduino via I2C. It covers necessary hardware, wiring diagrams, and includes example code for effective data retrieval and setup.

Hardware Preparation

  • DFR0654: FireBeetle ESP32-E main board *1
  • SEN0628: Matrix Laser Ranging Sensor *1
  • PH2.0-4P data cable *1
  • USB TYPE-C data cable *1
  • Arduino library download link: https://github.com/DFRobot/DFRobot_MatrixLidar

Software Preparation

  • Arduino IDE

Wiring Diagram

Toggle the switch to the position as shown in the figure:

  • At this time, the communication mode is set to I2C mode. It can be known from the table that the I2C address at this time is 0x33.
  • Each time the I2C address is switched or the I2C/UART function is changed, the power supply must be disconnected and restarted for the change to take effect.

Wiring diagram:

Other Preparation Work

  • Ensure the I2C address is set to 0x33
  • Restart the sensor after switching modes

Sample Code

#include "DFRobot_MatrixLidar.h"
    
DFRobot_MatrixLidar_I2C tof(0x33); //Default I2C address 0x33
uint16_t buf[64]; //Data from a total of 64 points
    
void setup(void){
  Serial.begin(115200); //Set the serial communication baud rate to 115200
  while(tof.begin() != 0){
    Serial.println("begin error !!!!!");
  }
  Serial.println("begin success");
  //config matrix mode
  while(tof.setRangingMode(eMatrix_8x8) != 0){ //Set to 8*8 mode
    Serial.println("init error !!!!!");
    delay(1000);
  }
  Serial.println("init success");
}
    
void loop(void){
  tof.getAllData(buf);
  for(uint8_t i = 0; i < 8; i++){
    Serial.print("Y");
    Serial.print(i);
    Serial.print(": ");
    for(uint8_t j = 0; j < 8; j++){
      Serial.print(buf[i * 8 + j]);
      Serial.print(",");
    }
    Serial.println("");
  }
  Serial.println("------------------------------");
  delay(100);//Setting this time allows adjustment of the interval for reading distances.
}

Result

Click the button in the upper right corner of the IDE to open the serial monitor, as shown in the figure:

The output data is as shown in the figure below.

The horizontal direction from left to right is the X-axis, with the unit being mm. The vertical direction from top to bottom is the Y-axis.

For example, the data "322" in the second row and second column in the figure represents the distance value of 322 at the x1, y1 point, with the unit being mm.

Additional Information

  • This example code can also be found in ArduinoIDE under File > Examples > DFRobot_MatrixLidar > I2C > get8*8data

Was this article helpful?

TOP