Build a Low-Cost Depth Camera With UNIHIKER K10 and an 8×8 ToF Sensor
by Jaychouu in Circuits > Sensors
84 Views, 0 Favorites, 0 Comments
Build a Low-Cost Depth Camera With UNIHIKER K10 and an 8×8 ToF Sensor
This project combines the UNIHIKER K10's built-in camera with a Gravity 8×8 Matrix ToF sensor to create a compact depth-vision device. The camera supplies the RGB image while the sensor measures distance in 64 zones. The software maps those readings to colors and overlays the grid on the live camera feed:
- Red: near
- Green: medium distance
- Blue: far
- Dark gray: invalid data
The result appears on the K10 and in a browser over Wi-Fi. The browser interface can save a camera frame together with its 8×8 depth data and export saved readings as CSV.
The ToF sensor has a 60° field of view and a rated detection range of up to 3.5 meters. Its 8×8 grid is useful for obstacle awareness, spatial interaction, and experimental RGB-D projects, but it is not a replacement for a calibrated high-resolution depth camera.
Supplies
Hardware
- 1 × UNIHIKER K10
- 1 × Gravity: 8×8 64-Pixel Matrix Time-of-Flight Sensor (SEN0628)
- 1 × PH2.0 4-pin I2C cable
- 1 × USB Type-C data cable
- 1 × 3D-printed mounting bracket from the project's 3D-Model folder
- 1 × computer
- Access to a Wi-Fi network shared by the K10 and the device used to open the web interface
Software
- Visual Studio Code
- PlatformIO IDE extension for Visual Studio Code
- Project source files
- A modern web browser
Configure and Connect the ToF Sensor
Before connecting the hardware, set the sensor's communication-mode DIP switch to the I2C side and set its address to 0x31.
With the K10 powered off, use the PH2.0 4-pin cable to connect the sensor to the K10's I2C port.
The project expects the MatrixLidar sensor at I2C address 0x31 and uses a 400 kHz I2C bus.
Print and Install the Mounting Bracket
Download the bracket files from the repository's 3D-Model folder. Both STL and STEP files are provided.
Install the printed bracket on top of the UNIHIKER K10, then mount the ToF sensor on the bracket. Keep the sensor and the K10 camera facing in the same direction. Finally, connect the USB Type-C cable to the K10.
The bracket fixes the relative position of the two sensors, but you will still calibrate the on-screen overlay after the software is running.
Download the Project Files
Open the project repository, click Code, and select Download ZIP. Extract the archive to a convenient folder.
The extracted project root should contain platformio.ini along with the include, src, tof-camera-overlay, and 3D-Model folders.
Install PlatformIO IDE
Install Visual Studio Code, open the Extensions panel, search for PlatformIO IDE, and click Install.
The first PlatformIO setup can take a while because it downloads and caches the toolchain, board framework, and project libraries. When installation is complete, the PlatformIO icon will appear in the left sidebar.
Open the Project
In Visual Studio Code, choose File > Open Folder and select the extracted project folder containing platformio.ini.
Wait until the Loading Project message in the lower-right corner disappears.
Click the PlatformIO icon. The project controls include Build, Upload, and Monitor. You will use all three in the following steps.
Configure Wi-Fi
Open a terminal in the project root and copy the Wi-Fi configuration template:
Open include/wifi_secrets.h, then replace the placeholder values with your network name and password:
The project ignores wifi_secrets.h in Git, which helps prevent the password from being committed to the repository. Do not share this file with screenshots, source archives, or public attachments.
Build and Upload the Firmware
Connect the K10 to the computer with a USB data cable. In PlatformIO, click Build and wait for the terminal to display SUCCESS. Then click Upload to transfer the firmware to the K10.
The supplied platformio.ini pins the UNIHIKER board platform and MatrixLidar library revisions used by this project. Its serial-monitor speed is 115200, and its upload speed is 460800.
Find the IP Address and Open the Web Interface
Click Monitor in PlatformIO. When the serial terminal displays WIFI OK, note the IP address shown below it.
The same address appears on the second line of the K10 display.
On a phone or computer connected to the same network, open:
Replace <K10-IP> with the address shown on your board. The page will display the live camera image with the 8×8 depth grid and individual distance values.
The status bar reports the local display rate, browser camera rate, and ToF sampling rate. Actual performance depends on Wi-Fi throughput, JPEG encoding speed, and sensor sampling.
Save Frames and Export Depth Data
The web interface provides four main actions:
- Save the current frame: Saves the current 8×8 depth readings and a camera image in memory.
- Download CSV: Exports all saved depth frames as a CSV file.
- Clear the records: Deletes the saved frames and photos.
- Open a saved image: Click a thumbnail to view its corresponding camera photo at full size.
Saved data uses a 50-frame ring buffer. It is stored in RAM, camera photos use PSRAM, and all saved records are cleared when the board loses power.
Calibrate and Verify the Overlay
Because the camera lens and ToF sensor are physically separated, their fields of view will not align perfectly without adjustment. Use the K10 buttons to move the depth grid:
- Button A, short press: Increase the X offset by 2.
- Button A, hold for more than 500 ms: Repeatedly decrease the X offset by 2.
- Button B, short press: Increase the Y offset by 2.
- Button B, hold for more than 500 ms: Repeatedly decrease the Y offset by 2.
The default offset is X:0, Y:40, and each grid cell is 28×28 pixels. Place a flat object at a known distance, move it across the camera view, and adjust the offsets until the colored depth zones follow the object as closely as possible.
The grid remains an approximate overlay because the camera and ToF sensor have different viewpoints and optics. For obstacle alerts or spatial interaction, allow a margin around zone boundaries instead of treating each overlaid cell as a pixel-accurate measurement.
Once the system is working, you can extend it with a near-distance alarm, a buzzer, robot obstacle avoidance, gesture experiments, or periodic depth-data uploads to an IoT service.