1 (edited by Vin1 2024-02-19 00:36:33)

Topic: Using BTS7960 driver module with gyro but it doesn't move in -x ofgyro

#include <dht.h>
dht DHT;
int dhtSensorPin = 12;
int temperature;
int humidity;
//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID ""
#define REMOTEXY_WIFI_PASSWORD ""
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =   // 45 bytes
  { 255,3,0,22,0,38,0,16,137,1,5,16,18,55,30,30,30,190,64,4,
  64,28,16,8,30,2,8,67,5,4,29,20,5,3,26,11,67,5,39,29,
  20,5,5,26,11 };
 
// this structure defines all the variables and events of your control interface
struct {

    // input variables
  int8_t joystick_1_x; // from -100 to 100 
  int8_t joystick_1_y; // from -100 to 100 
  int8_t slider_1; // =0..100 slider position

    // output variables
  char text_temp[11];  // string UTF8 end zero
  char text_hum[11];  // string UTF8 end zero

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)
// Left motor
const uint8_t LEFT_R_PWM_PIN = 6;
const uint8_t LEFT_L_PWM_PIN = 7;
const uint8_t LEFT_R_EN_PIN = 4;
const uint8_t LEFT_L_EN_PIN = 5;

// Right motor
const uint8_t RIGHT_R_PWM_PIN = 2;
const uint8_t RIGHT_L_PWM_PIN = 3;
const uint8_t RIGHT_R_EN_PIN = 8;
const uint8_t RIGHT_L_EN_PIN = 9;
#include <BTS7960.h>
// Control motor
BTS7960 motorController_1(RIGHT_R_EN_PIN, RIGHT_L_EN_PIN, RIGHT_R_PWM_PIN, RIGHT_L_PWM_PIN);
BTS7960 motorController_2 (LEFT_R_EN_PIN, LEFT_L_EN_PIN, LEFT_R_PWM_PIN, LEFT_L_PWM_PIN );
void Wheel(int joystickX, int joystickY) {
  int speedRight = map(joystickX, -100, 100, -255, 255); // Map joystick X-axis to right motor speed range
  int speedLeft = map(joystickY, -100, 100, -255, 255); // Map joystick Y-axis to left motor speed range

  if (speedRight > 0) {
    motorController_1.pwm = speedRight;
    motorController_1.front();
  } else if (speedRight < 0) {
    motorController_1.pwm = -speedRight;
    motorController_1.back();
  } else {
    motorController_1.stop();
  }

  if (speedLeft > 0) {
    motorController_2.pwm = speedLeft;
    motorController_2.front();
  } else if (speedLeft < 0) {
    motorController_2.pwm = -speedLeft;
    motorController_2.back();
  } else {
    motorController_2.stop();
  }
}
void setup() {
  RemoteXY_Init();
Serial.begin(115200);                       //begin the serial monitor for output
  motorController_1.begin();                           //This method will set the motor driver pins as output
  motorController_1.enable();
  motorController_2.begin();                           //This method will set the motor driver pins as output
  motorController_2.enable();
  /*
  // Initialization pins for left motor
  pinMode(LEFT_R_PWM_PIN, OUTPUT);
  pinMode(LEFT_L_PWM_PIN, OUTPUT);
  pinMode(LEFT_R_EN_PIN, OUTPUT);
  pinMode(LEFT_L_EN_PIN, OUTPUT);

  // Initialization pins for right motor
  pinMode(RIGHT_R_PWM_PIN, OUTPUT);
  pinMode(RIGHT_L_PWM_PIN, OUTPUT);
  pinMode(RIGHT_R_EN_PIN, OUTPUT);
  pinMode(RIGHT_L_EN_PIN, OUTPUT);
  */
}
void loop() {
RemoteXY_Handler();

/*
  Wheel(RemoteXY.joystick_1_x, RemoteXY.joystick_1_y);
*/
  int dhtCheck = DHT.read11(dhtSensorPin);
  temperature = DHT.temperature;
  humidity = DHT.humidity;

  dtostrf(temperature, 0, 1, RemoteXY.text_temp);
  dtostrf(humidity, 0, 1, RemoteXY.text_hum);

  // Manage the motors
Wheel(RemoteXY.joystick_1_x, RemoteXY.joystick_1_y);
}

2

Re: Using BTS7960 driver module with gyro but it doesn't move in -x ofgyro

Maybe pins 2 and 7 do not support PWM ?

3

Re: Using BTS7960 driver module with gyro but it doesn't move in -x ofgyro

I tried to change the 2 and 7 pins to PWM pins and i works thank you.