Topic: How to Control a motor with BTS7960 with Remote XY joystick
Hello I'm trying to figure out how to get my 2 motors to work with the remote XY app, BLE HM-10, Arduino Uno and 2 BTS7960 (one for each motor). I will be honest I'm new to all of this and have tried to copy portions of sketches I've downloaded that people are using the same setup but a ps2 controller instead of Remote XY any help would be awesome. I keep getting an Error 1 when I try to verify the Code. I'm trying to run my ble controller using pins 11 and 12, pin 8 as an enable for both H bridges (BTS 7960), Pins 6 and 9 for my Left PWM on the BTS7960, and Pins 3 and 5 for my Right PWM on the BTS7960. I'm also trying to use an S and F button on the Remote XY app so when S is pressed the PWM is limited to 80 and when F is pressed it can go to max of 250. Any help would be amazing.
/*
-- New project --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.6 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.8.01 or later version;
- for iOS 1.5.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 12
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,4,0,0,0,47,0,13,8,1,
5,32,7,48,50,50,0,26,16,129,
0,10,11,42,10,31,71,111,100,100,
97,114,100,0,1,0,8,32,12,12,
0,31,83,0,1,0,44,32,12,12,
0,31,70,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
int8_t joystick_1_x; // =-100..100 x-coordinate joystick position
int8_t joystick_1_y; // =-100..100 y-coordinate joystick position
uint8_t Speed_1; // =1 if button pressed, else =0
uint8_t Speed_2; // =1 if button pressed, else =0
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define Speed_1 80
#define Speed_2 250
String inString = ""; // string to hold input
int motorPWM = 0;
int defaultSpeed = 80;
int leftAdd = 20;
const uint8_t EN = 8;
const uint8_t L1_PWM = 6;
const uint8_t L2_PWM = 9;
const uint8_t R1_PWM = 3;
const uint8_t R2_PWM = 5;
BTS7960 motorController_1(EN, L1_PWM, L2_PWM);
BTS7960 motorController_2(EN, R1_PWM, R2_PWM);
void setup()
{
RemoteXY_Init ();
Serial.begin(9600);
pinMode(R1PWM_Output, OUTPUT);
pinMode(R2PWM_Output, OUTPUT);
pinMode(L1PWM_Output, OUTPUT);
pinMode(L2PWM_Output, OUTPUT);
}
void loop()
{
RemoteXY_Handler ();
motorController.Enable();
for(int speed = 0 ; speed < 255; speed+=10)
{
motorController.TurnLeft(speed);
delay(100);
}
motorController.Stop();
for(int speed = 255 ; speed > 0; speed-=10)
{
motorController.TurnLeft(speed);
delay(100);
}
motorController.Stop();
motorController.Disable();
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()