Need help driving 393 motors with Arduino

#1

I have 4 motor Vex 393. Can this sketch be manipulated?

#include <Servo.h>

Servo right_motor; // create servo object to control a servo
Servo left_motor;
Servo up_motor;
Servo roll_motor;

int right_pot = 0; // analog pin used to connect the potentiometer
int left_pot = 1;
int up_pot = 2;
int roll_pot = 3;

int right_var; // varying values of the potentiometer
int left_var;
int up_var;
int roll_var;
int right; // variables for servo
int left;
int up;
int roll;

void setup() {
right_motor.attach(8); // attaches the servo
left_motor.attach(9);
up_motor.attach(10);
roll_motor.attach(11);

}

void loop() {
right_var = analogRead(right_pot); // reads the value of the potentiometer (value between 0 and 1023)
right = map(right_var, 0, 1020, 1180, 1800); // scale it to use it with the servo (value
// between 1200 and 1800)
right_motor.writeMicroseconds(right); // sets the servo position according
// to the scaled value}

left_var = analogRead(left_pot);
left = map(left_var, 0, 1023, 1227, 1800);
left_motor.writeMicroseconds(left);

up_var = analogRead(up_pot);
up = map(up_var, 0, 1023, 1229, 1800);
up_motor.writeMicroseconds(up);

roll_var = analogRead(roll_pot);
roll = map(roll_var, 0, 1023, 1190, 1800);
roll_motor.writeMicroseconds(roll);
}

0 Likes

#2

You’ll have to be more specific if you want help.
What is the problem?
What are you trying to accomplish?

1 Like

#3

Are you looking to connect 393 motors to an Arduino?

0 Likes

#4

Arduino servo library takes input from 0 to 180 (deg) to Servo.write(): https://www.arduino.cc/en/Tutorial/Knob

Then this mapping should work: Servo.write( map(pot,0,1023,0,180) );

With MC29 you, probably, couldn’t get enough resolution to justify using writeMicroseconds() anyways.

Also, in my experience running 393 motors via MC29 controllers connected to a cheap Arduino board, the mid point turned out to be around 93-95 (instead of expected 90 deg) control input, even when using hardware PWM pins. This was most likely due to an imprecise timer, so you would need to calibrate it for the specific board. Using an ESP8266 board was working much better in that respect.

2 Likes