Abdullah Al-SaadAhmad TASKIA
Published

Bionic Hand

Hexabitz ExG Module in it's EMG mode of operation is the core of this bionic hand.

IntermediateFull instructions provided2 hours225
Bionic Hand

Things used in this project

Hardware components

Single-Lead, EXG Monitor (H2BR0x)
Hexabitz Single-Lead, EXG Monitor (H2BR0x)
×1
STLINK-V3MODS Programmer (H40Rx)
Hexabitz STLINK-V3MODS Programmer (H40Rx)
×1
Dual H-Bridge Motor Driver (H18R1x)
Hexabitz Dual H-Bridge Motor Driver (H18R1x)
×1
4-Pin USB-Serial Prototype Cable
Hexabitz 4-Pin USB-Serial Prototype Cable
×1
Mounting Hole Module (T00R10)
Hexabitz Mounting Hole Module (T00R10)
×1
1S LiPo Charger w/ USB-C Module (H05R0x)
Hexabitz 1S LiPo Charger w/ USB-C Module (H05R0x)
×1
SparkFun Sensor Cable - Electrode Pads (3 Connector)
Any electrode cable or band could be used.
×1
Servo Motor MG945
×1
Lithium ion 3.7 V 3800mah rechargeable battery - 18650
×1
Boost Converter 3608
Optional
×1
Kwawu Arm 3.0 - Socket Version by JacquinBuchanan
×1

Software apps and online services

STM32CUBEPROG
STMicroelectronics STM32CUBEPROG
STMicroelectronics STM32CubeIDE

Story

Read more

Custom parts and enclosures

Kwawu Arm 3.0 - Socket Version

Schematics

circuit_diagram_gxki9KNoCa.jpg

Code

EMG

C/C++
we simply used one API from the fact sheet of ExG module, and used one pin from port 5 to be used out of the BOS messaging task.
/*
 BitzOS (BOS) V0.3.6 - Copyright (C) 2017-2024 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"

/* Private variables ---------------------------------------------------------*/
uint8_t emgDetectionFlag=0;
uint16_t emgDuration=0;


/* User Task */
void UserTask(void *argument) {
	EXG_Init(EMG);
	// put your code here, to run repeatedly.
	while (1) {

		EMG_CheckPulse(&emgDetectionFlag, &emgDuration);
		if (emgDetectionFlag==1)
		{
			if(emgDuration>200) //EMGDurMsec
				  {
				    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7, 1);// LED PB7
				 	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3, 1);// P5 TX
		     	 	HAL_Delay(500);
				 	  HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7, 0);// LED PB7
				 	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3, 0);// P5 TX
		 			  HAL_Delay(300);

			       }
				  else
				 	 {
				 	  HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7, 0);// LED PB7
				 	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3, 0);// P5 RX
				 	 }
		}
	}
}

/*-----------------------------------------------------------*/

Driver

C/C++
/*
 BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"

/* Private variables ---------------------------------------------------------*/
uint8_t state=0;
uint8_t Zposflag;
float ADC_Value=0;

/* Private function prototypes -----------------------------------------------*/
void PWMServoMotor(H_BridgeDirection direction,uint8_t angle){
	uint8_t pulsTime;
	MX_TIM3_Init();
	   HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
		if( direction== forward)
		{   HAL_GPIO_WritePin(IN1_GPIO_Port ,IN1_Pin ,GPIO_PIN_SET);
			HAL_GPIO_WritePin(IN2_GPIO_Port ,IN2_Pin ,GPIO_PIN_RESET);
        }
		else
		{
			HAL_GPIO_WritePin(IN1_GPIO_Port ,IN1_Pin ,GPIO_PIN_RESET);
						HAL_GPIO_WritePin(IN2_GPIO_Port ,IN2_Pin ,GPIO_PIN_SET);

		}
		pulsTime=(angle+45)/1.8;
	htim3.Instance->ARR = 500;//999
	htim3.Instance->CCR3 = pulsTime;

}
/* Main function ------------------------------------------------------------*/

int main(void){

	Module_Init();		//Initialize Module &  BitzOS



	//Don't place your code here.
	for(;;){}
}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void *argument){

	ADCSelectChannel(3, "top");
	Delay_ms(500);
	// put your code here, to run repeatedly.
	while(1){

		state= HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_3);
		if(state==1) // tension
	{	IND_ON();
		if(Zposflag==1)
			{PWMServoMotor(forward,180); //backward
			 Delay_ms(300);Zposflag=0;}
		else
		{
			PWMServoMotor(forward,0); //backward
			Delay_ms(300);Zposflag=1;
		}

	   }
		else // relax
	     {	IND_toggle();
	    Delay_ms(100);

	     }

	}
}

/*-----------------------------------------------------------*/

Exclude P5 pin from BOS messaging

C/C++
//    in H2BR0.c file: comment raw 435 & raw 566
void Module_Peripheral_Init(void){

	 __HAL_RCC_GPIOB_CLK_ENABLE();
	 __HAL_RCC_GPIOA_CLK_ENABLE();

	/* Array ports */
	MX_USART1_UART_Init();
	MX_USART2_UART_Init();
	MX_USART3_UART_Init();
//	MX_USART5_UART_Init();
	MX_USART6_UART_Init();
	MX_TIM2_Init();
	MX_ADC1_Init();
	.
	.
	.
	// raw 566:
	
	uint8_t GetPort(UART_HandleTypeDef *huart){

	if(huart->Instance == USART6)
		return P1;
	else if(huart->Instance == USART2)
		return P2;
	else if(huart->Instance == USART3)
		return P3;
	else if(huart->Instance == USART1)
		return P4;
//	else if(huart->Instance == USART5)
//		return P5;
	
	return 0;
}

// in H2BR0.h file: comment related raws


/* Port-related definitions */
#define	NumOfPorts			4//5

#define P_PROG 				P2						/* ST factory bootloader UART */

/* Define available ports */
#define _P1 
#define _P2 
#define _P3 
#define _P4
//#define _P5

/* Define available USARTs */
#define _Usart1 1
#define _Usart2 1
#define _Usart3 1
//#define _Usart5 1
#define _Usart6	1


/* Port-UART mapping */
#define P1uart &huart6
#define P2uart &huart2
#define P3uart &huart3
#define P4uart &huart1
//#define P5uart &huart5

// in H2BR0_gpio.c add the following definition to the end of void GPIO_Init(void) function:

	GPIO_InitStruct.Pin = GPIO_PIN_3;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

Credits

Abdullah Al-Saad
1 project • 1 follower
Mechatronics Engineer
Contact
Ahmad TASKIA
11 projects • 11 followers
MPhil. Bsc. ELECTRONICS Engineering
Contact

Comments

Please log in or sign up to comment.