H-Bridge engines are not running

Hello everyone
Dear friends, I am a complete layman when it comes to electronics.
I would like to make a vehicle remotely controlled by Radio Flsyky using the H Bridge, identical to the picture below.
I found a sketch, changed the pins, put the program into stm32f411 but unfortunately the engines do not work.

Sorry for my picture, but only Paint was on hand :wink:
http://212.59.240.9/1.PNG

Could I please help get this up and running?

Flysky_Two_Motors-1.ino (1.1 KB)

Better use Paint to draw a schematic circuit diagram. Simple black boxes with labeld connectors and straight wires in between.

Hi, @PYJTER
Please post your code as instructed below;

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Forget Paint and draw your circuit with pen(cil) and paper and post an image of it.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

Ok Friends
I use this code

And works
And I found a problem, I did not mark the pins like in STM32, but I left it, as in arduino they were changed and it works;)

double ch1=PB3; // flysky ch 1
int IN1=PB5; //
int IN2=PB6; //
 
double ch2=PB4;  // flysky ch 2
int IN3=PB7;  //
int IN4=PB8; //

const int ENA = PA3;
const int ENB = PA4;


void setup()
{
  Serial.begin(9600);
  
  pinMode(PB3,INPUT);
  pinMode(PB5,OUTPUT); pinMode(PB6,OUTPUT);
  
  pinMode(PB4,INPUT);
  pinMode(PB7,OUTPUT); pinMode(PB8,OUTPUT);

  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);
  
}

void loop()
{

//control speed 
 analogWrite(ENA, 255);
 analogWrite(ENB, 255); 
 
ch1 = pulseIn(PB3,HIGH);
ch2 = pulseIn(PB4,HIGH);

if((ch1==0)&&(ch2==0))
{     
 digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
}

else if((ch1>1530)&&(ch2>1530))
{     
digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);    
}

else if((ch1>1530)&&(ch2<1460))
{   digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
 digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);    

}

else if((ch1<1460)&&(ch2>1530))
{     
  digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
 digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);
}

else if((ch1<1460)&&(ch2<1460))
{  digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
 digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);
  

}

else
{     
 digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
}

}

The second question now the engines are running at full power, forward, reverse, left, right. How do I make it respond to JOY traffic in Flysky?

EDIT:
Sorry for my errors in placing the code

You will get more and faster help if you will post the code here in code tags like is instructed in the post linked in reply #3. Making members download your code will not make friends.

1 Like

Ok what do you think about this ??

double ch1=PB3; // flysky ch 1
int IN1=PB5; //
int IN2=PB6; //
 
double ch2=PB4;  // flysky ch 2
int IN3=PB7;  //
int IN4=PB8; //

const int ENA = PA3;
const int ENB = PA4;


void setup()
{
  Serial.begin(9600);
  
  pinMode(PB3,INPUT);
  pinMode(PB5,OUTPUT); pinMode(PB6,OUTPUT);
  
  pinMode(PB4,INPUT);
  pinMode(PB7,OUTPUT); pinMode(PB8,OUTPUT);

  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);
  
}

void loop()
{
  int pwm1 = 0;
  int pwm2 = 0;
  ch1 = pulseIn(PB3,HIGH, 25000);
  ch2 = pulseIn(PB4,HIGH, 25000);


//control speed 
//  analogWrite(ENA, 255);
//  analogWrite(ENB, 255); 
 
//ch1 = pulseIn(PB3,HIGH);
//ch2 = pulseIn(PB4,HIGH);

if((ch1==0)&&(ch2==0))
{     
 digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
 analogWrite(ENA, 0);analogWrite(ENB, 0);
}
//Przód
else if((ch1>1520)&&(ch2>1520))
{     
  pwm1 = map(ch1, 1520, 2000, 0, 255); 
  pwm2 = map(ch2, 1520, 2000, 0, 255); 
digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);    
  analogWrite(ENA, pwm1);analogWrite(ENB, pwm2);
}

else if((ch1>1520)&&(ch2<1500))

//PRAWO
{
    pwm1 = map(ch1, 1495, 2000, 0, 255); 
  pwm2 = map(ch2, 1502, 2000, 0, 255); 
  digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
 digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);    
   analogWrite(ENA, pwm1);analogWrite(ENB, 0);

}
//LEWO
else if((ch1<1480)&&(ch2>1500))
{     
   pwm1 = map(ch1, 1493, 2000, 0, 255); 
  pwm2 = map(ch2, 1504, 2000, 0, 255); 
  digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
 digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);
   analogWrite(ENA, 0);analogWrite(ENB, pwm2);
}

//Tył
else if((ch1<1490)&&(ch2<1490))

{ 
  pwm1 = map(ch1, 1490, 2000, 0, 255); 
  pwm2 = map(ch2, 1490, 2000, 0, 255); 
  digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
 digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);
   analogWrite(ENA, pwm1);analogWrite(ENB, pwm2);
  

}

else
{     
 digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
 digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);
  analogWrite(ENA, 0);analogWrite(ENB, 0);
}

}

But not work good only one channel works good ;(

Ok I Read value from channel1 and ch2 but not work:


//FRONT
Ch1: 1724 Ch2: 1743
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1741 Ch2: 1749
Ch1: 1740 Ch2: 1750
Ch1: 1740 Ch2: 1750
Ch1: 1741 Ch2: 1751


//BACK

Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1252
Ch1: 1245 Ch2: 1254
Ch1: 1244 Ch2: 1253
Ch1: 1245 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1244 Ch2: 1253
Ch1: 1241 Ch2: 1253



//LEFT
Ch1: 1009 Ch2: 1503
Ch1: 1009 Ch2: 1503
Ch1: 1009 Ch2: 1503
Ch1: 1006 Ch2: 1501
Ch1: 1009 Ch2: 1503
Ch1: 1008 Ch2: 1503
Ch1: 1010 Ch2: 1502
Ch1: 1008 Ch2: 1503
Ch1: 1008 Ch2: 1503

//RIGHT
Ch1: 1994 Ch2: 1505
Ch1: 1994 Ch2: 1504
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1508
Ch1: 1997 Ch2: 1507
Ch1: 1997 Ch2: 1507
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1507
Ch1: 1997 Ch2: 1507
Ch1: 1998 Ch2: 1507
Ch1: 1996 Ch2: 1505
Ch1: 1997 Ch2: 1507
Ch1: 1996 Ch2: 1506
Ch1: 1995 Ch2: 1505
Ch1: 1994 Ch2: 1504
Ch1: 1995 Ch2: 1505

//ZERO

Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1504
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1503
Ch1: 1495 Ch2: 1504
Ch1: 1494 Ch2: 1503

I mis-defined the values

map()

All works OK :wink: