Example Code for Arduino-Get single point data

Last revision 2026/02/05

This article guides you through setting up the 64x8 DTOF sensor with Arduino, providing sample code for reading XYZ coordinates and intensity from a specified point.

Hardware Preparation

Software Preparation

Wiring Diagram

SEN0682-ESP32 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

Configure 64x8 DTOF sensor to read XYZ coordinates & intensity of specified point and output via serial.

#include "DFRobot_64x8DTOF.h"
#define LINE_NUM  4
#define POINT_NUM 32

// Instantiate the sensor object
// Use Serial1 for communication, change pins 25/26 to your actual RX/TX pins
DFRobot_64x8DTOF dtof64x8(Serial1, SERIAL_8N1, 25, 26);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  while (!dtof64x8.begin());
  Serial.println("DFRobot 64x8DTOF Single Point Demo");

  // Retry configuring frame mode until success
  Serial.println("Configuring frame mode: Single Frame...");
  while (!dtof64x8.configFrameMode(DFRobot_64x8DTOF::eFrameSingle)) {
    Serial.println("Error: configFrameMode failed, retrying...");
    delay(200);
  }
  Serial.println("Configuration Single Frame Successful!");
  // 2. Configure Single Point Mode (retry until success)
  // Example: Line 4, Point 32 (Center of the sensor roughly)
  // Line range: 1-8
  // Point range: 1-64
  Serial.print("Configuring Single Point Mode (Line ");
  Serial.print(LINE_NUM);
  Serial.print(", Point ");
  Serial.print(POINT_NUM);
  Serial.println(")...");
  while (!dtof64x8.configMeasureMode(LINE_NUM, POINT_NUM)) {
    Serial.println("Configuration Failed, retrying...");
    delay(200);
  }
  Serial.println("Configuration Successful!");
  delay(300);
}

void loop()
{
  int parsed = dtof64x8.getData(300);
  if (parsed > 0) {
    char numbuf[16];
    Serial.print("Point Data -> ");
    Serial.print("X: "); sprintf(numbuf, "%04d", dtof64x8.point.xBuf[0]); Serial.print(numbuf); Serial.print(" mm, ");
    Serial.print("Y: "); sprintf(numbuf, "%04d", dtof64x8.point.yBuf[0]); Serial.print(numbuf); Serial.print(" mm, ");
    Serial.print("Z: "); sprintf(numbuf, "%04d", dtof64x8.point.zBuf[0]); Serial.print(numbuf); Serial.print(" mm, ");
    Serial.print("I: "); Serial.println(dtof64x8.point.iBuf[0]); 
  } else {
    Serial.println("getData timeout or error");
  }

  delay(500);
}

Result

Serial port cyclically outputs X/Y/Z 3D coordinates (mm) and intensity of the specified point.

SEN0682-Single point data result

  1. I represents the intensity of reflected light received by the sensor, with a typical value range of 0-255.
  2. A higher value indicates better reflectivity of the target surface, and the ranging result is usually more stable.
  3. A value of 0 may mean the target is beyond the detection range or has excessively poor reflectivity.

Was this article helpful?

TOP