Example Code for Arduino-Get single line data
Last revision 2026/02/05
This article guides you through configuring Arduino with a 64x8DTOF LiDAR sensor to acquire single line data, including hardware and software preparation, wiring, and sample code execution.
Hardware Preparation
- 64×8 Matrix DTOF LiDAR (SKU: SEN0682) × 1
- FireBeetle 2 ESP32-E (SKU: DFR0654) ×1
- Gravity-4P Connection Cable ×1
- USB-C Data Cable ×1
Software Preparation
- Download Arduino IDE: Click here to download Arduino IDE
- Download Arduino library: Click here to download DFRobot_64x8DTOF library.
- For Arduino IDE V1.8.19 (or earlier), install the library manually: How to Add a Library?
Wiring Diagram

Pin Connection Description
- Sensor: 5V Pin --- (Connect to) --- Controller: VIN(5V)
- Sensor: GND Pin --- (Connect to) --- Controller: GND
- Sensor: RX Pin --- (Connect to) --- Controller: 26/TX
- Sensor: TX Pin --- (Connect to) --- Controller: 25/RX
Sample Code
Configures the 64x8DTOF sensor to single-line mode, acquires Line 4 data (X/Y/Z/I) and outputs via serial with error prompts.
#include "DFRobot_64x8DTOF.h"
DFRobot_64x8DTOF dtof64x8(Serial1, SERIAL_8N1, 25, 26);
#define LINE_NUM 4
void setup()
{
Serial.begin(115200);
while (!Serial);
while (!dtof64x8.begin());
Serial.println("Configuring frame mode: Single Frame...");
while (!dtof64x8.configFrameMode(DFRobot_64x8DTOF::eFrameSingle)) {
Serial.println("configFrameMode failed, retrying...");
delay(200);
}
Serial.println("Configuration Single Frame Successful!");
// Configure single line mode (retry until success)
Serial.print("Configured multi-point mode: line=");
Serial.print(LINE_NUM);
Serial.println(")");
while (!dtof64x8.configMeasureMode(LINE_NUM)) {
Serial.println("Configuration failed, retrying...");
delay(200);
}
Serial.println("Configuration successful.");
delay(300);
}
void loop()
{
Serial.println("12345");
int cnt = dtof64x8.getData(300);
Serial.print("Got points: ");
Serial.println(cnt);
if (cnt > 0) {
for (int i = 0; i < cnt; i++) {
char numbuf[16];
Serial.print(1 + i);
Serial.print(": X="); sprintf(numbuf, "%04d", dtof64x8.point.xBuf[i]); Serial.print(numbuf); Serial.print(" mm ");
Serial.print("Y="); sprintf(numbuf, "%04d", dtof64x8.point.yBuf[i]); Serial.print(numbuf); Serial.print(" mm ");
Serial.print("Z="); sprintf(numbuf, "%04d", dtof64x8.point.zBuf[i]); Serial.print(numbuf); Serial.print(" mm ");
Serial.print("I="); Serial.println(dtof64x8.point.iBuf[i]);
}
}else {
Serial.println("getData timeout or error");
}
delay(500);
}
Result
The serial port continuously outputs data of 64 measured points in Line 4.

Was this article helpful?
