Make A Digital Distance Meter With Hexabitz
About the project
Hello, in this project I will show you how to build your own distance meter box with Hexabitz modules.
Project info
Difficulty: Moderate
Platforms: STMicroelectronics
Estimated time: 1 hour
License: MIT license (MIT)
Items used in this project
Hardware components
View all
Software apps and online services
Story
Hello, in this project I will show you how to build your own distance meter box with Hexabitz modules.
Hexabitz IR ToF (Lidar) sensors are great tools to measure distance without actual contact and used at several places like Robots, distance measurement etc.
This is an efficient way to measure small distances precisely.
In this project, we have used a Hexabitz IR Sensor to determine the distance of an obstacle from the sensor and showing the distance with display module.
IR sensors are, for the most part, completely insensitive to hindering factors like: Light, Dust, Smoke, Mist, Vapor, and Lint.
The project is also about designing a real product by yourself, this product is similar to another on the market as the search engines showed.
The project is stand-alone device, distance measurement tool and display built into the same product.
1 / 2 • The product is found on search engines
The product is found on search engines
Laser Distance Meter
In this tutorial, I will take you through the steps that I followed to make this awesome project. I hope you will like it.
🛠️ Tools:1) STLINK-V3MODS Programmer (H40Rx):
H40Rx is a programmer module which contains STLINK-V3MODS stand-alone debugging and programming mini probe for STM32 micro-controllers (Hexabitz modules and other MCUs).
It supports the SWD (Serial Wire Debugging) interface for the communication with any STM32 micro-controller located on an application board.
It also provides bridge interfaces to several communication protocols, allowing for instance the programming of the target through boot-loader.
STLINK-V3MODS Programmer (H40Rx)
STLINK-V3MODS Programmer (H40Rx)
STLINK-V3MODS Programmer (H40Rx) Test
STLINK-V3MODS Programmer (H40Rx) Test
2) 6 Digit Seven Segment (H3BR6x):
H3BR6x is a 6 digit seven segment interface module based on STM32G0 MCU.
- Features 0.36 inches, 6 digits, RED, 8-segment display LED, common anode.
- Use this module as an output display device. Connect it to other Hexabitz modules to display information in text or decimal form.
6 digit seven segment interface module
6 digit seven segment interface module
3)3.3V/1A DC-DC Power Supply (H03R0x):
H03R0x is a compact DC-DC buck power supply with a 3.3V/1A DC output and 5-40V DC input. The output voltage is provided through Hexabitz SMD edge-pad connectors (3.3V on top and GND on bottom). The -T module version comes with a 5.08 mm terminal block connector for input voltage, while the -J comes with a DC power jack. Use this module to power all your Hexabitz creations (and other hardware) from a DC source (battery, AC/DC wall adapter, etc.)
DC-DC Buck Power Supply Module
DC-DC Buck Power Supply Module
4) 5V DC-DC Boost Power Supply (H32R1x):
H32R1x is a compact DC-DC boost power supply module that takes 3.3V from module array ports and boosts it up to 5V/0.5A output voltage on the terminal block connector. You can use this module to generate 5V from your Hexabitz array 3.3V backbone voltage.
1 / 2 • DC-DC Boost Power Supply Module
DC-DC Boost Power Supply Module
5) 1D LiDAR IR Sensor (H08R6x):
H08R6x is an infrared (IR) time-of-flight (ToF) ranging sensor module based on ST VL53L0X sensor and STM32F0 MCU. This sensor is immune to surface reflectance or varying lighting conditions and can function as a 1D LiDAR or gesture-detection interface. It can measure distance accurately up to 2 m.
H08R6x Module
H08R6x Module
H08R6x Module6)Laser Emitter Module:
The Laser Emitter Module incorporates a small red laser diode similar to what you find in a laser pen.
Laser Emitter Module
Laser Emitter Module
KEY FEATURES OF LASER EMITTER MODULE:
- 650nm Red Output
- Brass construction with acrylic lens
- Built-in current limiting resistor
- 5V Operation
You can use this laser emitter to put red dots on the ceiling or combine with a light sensitive receiver to create an optical intrusion alarm or communication link. Remember to never look straight at any laser diode while it is operating or point it at someone’s eyes, as eye damage is possible even with relatively wimpy type like this one.
To test, simply connect up to 5V and ground. The device includes a built-in 91 ohm current limiting resistor and draws about 30mA. It can be powered directly off some MCU pins or an additional series current limiting resistor can be added to reduce the drive current.
1 / 2 • Laser Emitter Module
Laser Emitter Module
Laser Emitter Module Technical Specification
The output has some focus capability by turning the brass lens holder.
Laser Emitter Module Test
Laser Emitter Module Test
7)6-Pin GH Connector (T00RA):
T00RA is a 6-Pin GH connector module based on SM06B-GHS-TB(LF)(SN) connector, is used for PDP, LCD or small electronics equipments. This low insertion force type connector realizes easier mating operation.
1 / 2 • T00RA Module
T00RA Module
T00RA Module
Port Buttons/Switches API:You can connect any mechanical button or switch to any of the array ports at the modules using Hexabitz APIs.
Check out this article for Port Buttons/Switches
Port Buttons/Switches APISteps 📝1) Plan the array and assemble the hardware:We prepare the project components and plan our array design by aligning modules side-by-side. Then we solder the modules together using Hexabitz Fixture.
1 / 2 • Array 1
Array 1
Array 2
Array 2
2) Writing codes with STM32CubeIDE software:Check out this article for writing code with STM32CubeIDE.
· Fixed topology file: Inter-array communication in Hexabitz is done using a routing table stored in a special header (.h) file. This header file describes the number of modules and how they are connected to each other as well as other important information for the array; hence, it is called a topology header file. Currently, you need to make a topology file manually.
After creating the topology for the two modules (H08R6x, H3BR6x) and determining their configurations, we add the topology for each module. See this link for help in creating a topology file.
/*
BitzOS (BOS) V0.2.7 - Copyright (C) 2017-2022 Hexabitz
All rights reserved
File Name : topology.h
Description : Array topology definition.
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __topology_H
#define __topology_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_hal.h"
#define __N 2 // Number of array modules
// Array modules
#define _mod1 1<<3
#define _mod2 2<<3
// Topology
static uint16_t array[__N ][7] ={
{_H08R6,0, 0, 0, _mod2 | P4, 0, 0}, // Module 1
{_H3BR6,0, 0, 0, _mod1 | P4, 0, 0}, // Module 2
};
// Configurations for duplex serial ports
#if ( _module == 1 )
#define H08R6 1
#define _P1pol_normal 1
#define _P2pol_normal 1
#define _P3pol_normal 1
#define _P4pol_normal 1
#define _P5pol_normal 1
#define _P6pol_normal 1
#endif
#if ( _module == 2 )
#define H3BR6 1
#define _P1pol_normal 1
#define _P2pol_normal 1
#define _P3pol_normal 1
#define _P4pol_reversed 1
#define _P5pol_normal 1
#define _P6pol_normal 1
#endif
#ifdef __cplusplus
}
#endif
#endif /*__ topology_H */
/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/
Then go to project.h as shown in the photo below and UN-comment the header.
project.h file
project.h file
Press on main.c and define sensor variable and button state variable in the main.c file of the module IR (H08R6x):
float x;
int button1 = 0;
Define the button and link it to its callbacks in the UserTask function like this:
AddPortButton(MOMENTARY_NO,P3); // Define a button connected to port P1
SetButtonEvents(P3, 1, 1, 0, 0, 0, 0, 0, 0, 0); // Activate a click events
These events can be linked to user callbacks to execute some tasks. Add the following callback to your code in main.c to make use of button events:
void buttonClickedCallback(uint8_t port)
{
if(port == P3) {
button1 = 1; IND_blink(200);
}
Delay_ms(10);
}
void buttonDblClickedCallback(uint8_t port)
{
if(port == P3) {
button1 = 0; IND_blink(200);
}
Delay_ms(10);
}
Then we obtain the filtered and calibrated value of the IR in units of cm or inch using the following API from the IR factsheet:
Sample IR API
Sample IR API
In the UserTask function, we now write our repeated code that checks by the state of the button variable.
while(1){
if (button1 == 0){
SetRangeUnit (UNIT_MEASUREMENT_CM);
x = Sample_ToF ( );
x = x- 4.0;
memcpy(&messageParams[0], &x, 4);
messageParams[4] = 2;
messageParams[5] = 'c';
messageParams[6]=0;
SendMessageToModule(2,CODE_H3BR6_SevenDisplayQuantities,7); }
if (button1 == 1){
SetRangeUnit (UNIT_MEASUREMENT_INCH);
x = Sample_ToF ( );
x = x- 2.0;
memcpy(&messageParams[0], &x, 4);
messageParams[4] = 2;
messageParams[5] = 'i';
messageParams[6]=0;
SendMessageToModule(2,CODE_H3BR6_SevenDisplayQuantities,7); }
}
If the button is not pressed, the distance appears in cm unit where a message is sent to the Seven Segment (H3BR6x) module. If the button is pressed, the distance is shown in inch unit where a message is sent to the Seven Segment (H3BR6x) module too.
Show a float value on the display Message. The parameter unit refers to the value unit
Show a float value on the display Message. The parameter unit refers to the value unit
3) Test the System 🧐 🤓 ☑️Laser Test
Laser Test
I recycled a plastic box to enclosure the distance meter, Because I care to the UN's Sustainable Development Goals (SDGs).
1 / 4
Inch/Cm button
1 / 4
You can use DC-DC power module (H03R0) with 9V battery to power your project. Note that it's better to write the code using power from USB cable connection without DC-DC power module (to avoid power confusion and reset states). Once done, you can insert the batteries and then remove the USB cable.
Happy Doing It Yourself 😊
References:
[1] https://hexabitz.com/modules/
[2] https://hexabitz.com/wiki/
[3] https://hexabitz.com/product-category/accy/
[4] https://www.hackster.io/aula-jazmati/hexabitz-distance-measurement-system-da4971
Leave your feedback...