Home        Store        Docs        Blog

4 T100 2 Potentiometer Control with Arduino- Code issues

(Spruha Vashi) #1

Hello,
I have been working with @jjabraham on this motor setup for some time now. I am using 4 T100s, blue robotics ESCs, and 2 Analog Potentiometer Joysticks with the Arduino. I created some code just to test if I can connect the joysticks with the motors, and it should move this way:
Horz 1 motor = Y signal on first joystick
Horz 2 motor = X signal on first joystick
Vert 1 motor = Y signal on second joystick
Vert 2 motor = X signal on second joystick

#include <Servo.h>//Using servo library to control ESC

Servo escH1; //Creating a servo class with name as esc
Servo escH2; //Creating a servo class with name as esc
Servo escV1; //Creating a servo class with name as esc
Servo escV2; //Creating a servo class with name as esc

void setup()
{

escH1.attach(9); //Specify the esc signal pin,Here as D8
escH2.attach(10); //Specify the esc signal pin,Here as D8
escV1.attach(11); //Specify the esc signal pin,Here as D8
escV2.attach(12); //Specify the esc signal pin,Here as D8

escH1.writeMicroseconds(1490); //initialize the signal to 1000
escH2.writeMicroseconds(1490); //initialize the signal to 1000
escV1.writeMicroseconds(1490); //initialize the signal to 1000
escV2.writeMicroseconds(1490); //initialize the signal to 1000

Serial.begin(9600);
}

void loop()

{

int valH1; //Creating a variable val
int valH2; //Creating a variable val
int valV1; //Creating a variable val
int valV2; //Creating a variable val

valH1= analogRead(A0); //Read input from analog pin a0 and store in val
valH2= analogRead(A1); //Read input from analog pin a0 and store in val
valV1= analogRead(A2); //Read input from analog pin a0 and store in val
valV2= analogRead(A3); //Read input from analog pin a0 and store in val

//map(value, fromLow, fromHigh, toLow, toHigh)
valH1= map(valH1, 0, 1023,1100,1900);//mapping val to minimum and maximum(Change if needed)
valH2= map(valH2, 0, 1023,1100,1900);//mapping val to minimum and maximum(Change if needed)
valV1= map(valV1, 0, 1023,1100,1900);//mapping val to minimum and maximum(Change if needed)
valV2= map(valV2, 0, 1023,1100,1900);//mapping val to minimum and maximum(Change if needed)

escH1.writeMicroseconds(valH1); //using val as the signal to esc
escH2.writeMicroseconds(valH2); //using val as the signal to esc
escV1.writeMicroseconds(valV1); //using val as the signal to esc
escV2.writeMicroseconds(valV2); //using val as the signal to esc

Serial.println(valH1);
//Serial.println(valH2);
//Serial.println(valV1);
//Serial.println(valV2);

}
I want to be able to adjust the map values so that I can actually move forwards and backwards later, which I need help with, but my main issue right now is my Vert 1 motor. I have tested it individually and together, but the motor beeps like normal, but does not move at all. I’ve checked my connections multiple times, and it seems like there is nothing wrong with the code. Can someone please help me out? I am somewhat new to this and am getting confused.
Thank you so much!

(john mccue) #2

What does the serial monitor show for the values? I would double check your analog pin for that motor to make sure you are getting a good reading. Also try switching out the motor and the ESC with the others. If the problem remains with the motor position you will know it’s a problem with the Arduino, code, or joystick and not the motor or ESC.