Introduction
Due to the presence of dangerous places for humans, and sometimes narrow places such as caves, and the human desire to discover everything, and with the wide spread of technology today, it has become possible to get rid of these problems by using some techniques and smooth work.
This system allows you to control a car using your smartphone, which, using an application, sends a signal to the Bluetooth unit, including unit machine, which in turn directs the engines as required.
Tools used in this project
We'll list the tools and modules used in this project.
1) Serial Bluetooth Module (HC-05)
HC-05 Bluetooth module [1].
2) A compact coin-cell lithium battery holder that fits two CR2032 batteries in series(H04R2x):
The output voltage is provided through Hexabitz SMD edge-pad connectors (3.3V on top and GND on bottom)[3].
3)Dual H-Bridge Motor Driver (H18R1x):
The H-bridge motor driver module[5].
4) 2 AA Battery Box
2 AA battery box with contact points connected in series.
5) lithium Batteries:
lithium battery 3.7v 1000mah.
6) User Tools Kit:
This kit includes the tools that are essential for programming, debugging, and powering Hexabitz modules.
- FTDI USB to UART Serial cable:
The 4-pin USB 2.0 to UART serial cable is an indispensable tool for Hexabitz development! It incorporates FTDI’s USB to UART interface[9].
- Hexabitz BitzClamp:
Hexabitz BitzClamp is a modified Kelvin current clamp soldered to two 2.56 mm-pitch male jumper wires [10].
- STLINK-V3MODS Programmer (H40Rx):
H40Rx is a programmer module which contains STLINK-V3MODS stand-alone debugging and programming mini probe for STM32 microcontrollers (Hexabitz modules and other MCUs) [11].
- E-Z-Hook Programming Kit:
Instead of soldering SMD connectors there, you could use a nice off-the-shelf E-Z-Hook kit that we assembled for you [12].
We'll mention step by step instructions from designing to implementing of the project.
1. Planning the array and assembling the hardware:
First, we prepare the parts of the project and layout our matrix design by aligning the two modules side by side. Then we weld the modules together using Hexabitz Fixture.
2. Writing codes with STM32CubeIDE software:
This project uses a technology based on the principle of receiving commands from a smartphone and transmitting the signal to the H-bridge unit to control the movement of the vehicle.
After creating the cli commands for the five directions (forward, backward, right, and lift) and specifying their configurations, see this link for help creating cli commands.
/*
BitzOS (BOS) V0.2.7 - Copyright (C) 2017-2022 Hexabitz
All rights reserved
File Name : main.c
Description : Main program body.
*/
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"
/* Private variables ---------------------------------------------------------*/
static portBASE_TYPE fw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE bw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE off( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE r( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE l( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
/* Private function prototypes -----------------------------------------------*/
/* Main function ------------------------------------------------------------*/
/* CLI command structure : user-command */
const CLI_Command_Definition_t fw_Definition =
{
( const int8_t * ) "fw", /* The command string to type. */
( const int8_t * ) "fw:\r\n Execute command to forward direction\r\n\r\n",
fw, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t bw_Definition =
{
( const int8_t * ) "bw", /* The command string to type. */
( const int8_t * ) "bw:\r\n Execute command to backward direction\r\n\r\n",
bw, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t off_Definition =
{
( const int8_t * ) "off", /* The command string to type. */
( const int8_t * ) "off:\r\n Execute command to off\r\n\r\n",
off, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t r_Definition =
{
( const int8_t * ) "r", /* The command string to type. */
( const int8_t * ) "r:\r\n Execute command to right direction\r\n\r\n",
r, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t l_Definition =
{
( const int8_t * ) "l", /* The command string to type. */
( const int8_t * ) "l:\r\n Execute command to lift direction\r\n\r\n",
l, /* The function to run. */
0 /* No parameters are expected. */
};
int main(void){
Module_Init(); //Initialize Module & BitzOS
//Don't place your code here.
for(;;){}
}
/*-----------------------------------------------------------*/
/* User Task */
void UserTask(void *argument){
// put your code here, to run repeatedly.
while(1){
}
}
static portBASE_TYPE fw( int8_t *pcWriteBuffer , size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to forward\n");
Turn_ON(forward,MotorA);
Turn_ON(forward, MotorB);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE bw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to backward\n");
Turn_ON(backward,MotorB);
Turn_ON(backward, MotorA);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE off ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to off\n");
Turn_OFF(MotorA);
Turn_OFF(MotorB);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE r ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to right\n");
{
Turn_OFF(MotorA);
Turn_ON(forward,MotorB);
}
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE l ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to lift\n");
{
Turn_OFF(MotorB);
Turn_ON(forward, MotorA);
}
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
/* --- Register user CLI Commands */
void RegisterUserCLICommands(void)
{
FreeRTOS_CLIRegisterCommand(&fw_Definition );
FreeRTOS_CLIRegisterCommand(&bw_Definition );
FreeRTOS_CLIRegisterCommand(&off_Definition );
FreeRTOS_CLIRegisterCommand(&r_Definition );
FreeRTOS_CLIRegisterCommand(&l_Definition );
}
/*-----------------------------------------------------------*/
First, we define our variables in the main.c file of (H18R1):
/* Private variables ---------------------------------------------------------*/
static portBASE_TYPE fw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE bw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE off( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE r( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
static portBASE_TYPE l( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
secondly in the Main function we now write our functions code and know the names of the functions used.
/* CLI command structure : user-command */
const CLI_Command_Definition_t fw_Definition =
{
( const int8_t * ) "fw", /* The command string to type. */
( const int8_t * ) "fw:\r\n Execute command to forward direction\r\n\r\n",
fw, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t bw_Definition =
{
( const int8_t * ) "bw", /* The command string to type. */
( const int8_t * ) "bw:\r\n Execute command to backward direction\r\n\r\n",
bw, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t off_Definition =
{
( const int8_t * ) "off", /* The command string to type. */
( const int8_t * ) "off:\r\n Execute command to off\r\n\r\n",
off, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t r_Definition =
{
( const int8_t * ) "r", /* The command string to type. */
( const int8_t * ) "r:\r\n Execute command to right direction\r\n\r\n",
r, /* The function to run. */
0 /* No parameters are expected. */
};
const CLI_Command_Definition_t l_Definition =
{
( const int8_t * ) "l", /* The command string to type. */
( const int8_t * ) "l:\r\n Execute command to lift direction\r\n\r\n",
l, /* The function to run. */
0 /* No parameters are expected. */
};
thirdly, in the UserTask function, which checks the action command. which receives the command from the bluetooth module (HC05), commands, processes it and triggers the appropriate actuators for the desired direction.
We write our code:
static portBASE_TYPE fw( int8_t *pcWriteBuffer , size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to forward\n");
Turn_ON(forward,MotorA);
Turn_ON(forward, MotorB);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE bw( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to backward\n");
Turn_ON(backward,MotorB);
Turn_ON(backward, MotorA);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE off ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to off\n");
Turn_OFF(MotorA);
Turn_OFF(MotorB);
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE r ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to right\n");
{
Turn_OFF(MotorA);
Turn_ON(forward,MotorB);
}
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
static portBASE_TYPE l ( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
{
IND_blink(100);
strcpy( ( char * ) pcWriteBuffer, "This is command to lift\n");
{
Turn_OFF(MotorB);
Turn_ON(forward, MotorA);
}
/* There is no more data to return after this single string, so return pdFALSE. */
return pdFALSE;
}
When a command is sent from the phone, the bluetooth module (HC05) receives a message and transmits it in turn to the module (h18R1), which triggers, switches the voltage, the motor works and the movement starts
References[1]: Serial Bluetooth Module (HC-05).
[2]: HC05 datasheet.
[3]: Dual Coin Cell Battery Holders In-series (H04R2x) – Hexabitz.
[4]: H04R2x Factsheet_Hexabitz.
[5]: Dual H-Bridge Motor Driver (H18R1x) _ Hexabitz.
[6]: H18R1x factsheet_Hexabitz.
[7]: Box Of Battery.
[8]: lithium Battery.
[9]: 4-Pin USB-Serial Prototype Cable – Hexabitz.
[10]: Hexabitz BitzClamp – Hexabitz.
Comments
Please log in or sign up to comment.