Driving vex motors from an arduino???

Its been a while since I posted here but I’m back now:D

I am trying to build a simple robot that will be controlled over a bluetooth link to my computer running my software. I will be building more complicated ones later but this is just a test.

I chose the arduino as the brains but I have hit a bit of a snag, the vex motors are being extremely stupid. The pwm driver goes nuts when the arduino try’s to drive it. If I am correct 0 goes left, 127 stops it, and 255 goes right. These are the values I have used but the problem is that if I connect it to the micro controller power supply (5v), 127 will stop it but 0 and 255 go the same direction. If I power it via an external power source (12v for example I know its high but I want extra rpm) the pwm driver is unresponsive and randomly jitters. But if I connect it to the vex micro controller everything is ok and the motor driver works perfectly.

Does anyone have any idea what the problem is or may be???

I had this same problem making a robot with a basic stamp. For some reason you need to give the servos a separate power supply than that from the arduino. If you look in the vex controller there will probably be a separate offshoot of the battery to the vcc and gnd of the servos and actual microcontroller.

Also try to put the voltage down to 5 and add a couple capacitors to the power supply of the servo. uC’s make lots of switching noise and the caps will even it out.

I am driving vex motors not servos sorry if there was any confusion.

The motors have 3 wires, (Black(GND), Orange(VCC), White(PWM)). I have connected the black wire and orange wire to a separate power supply a 9v battery to be exact. The white pwm wire is connected to a pwm port on my arduino where I can send out pwm 5v signals. This setup does not work and the motor driver is unresponsive with random jitters. But when it is connected to the vex micro controller it works just fine.

I have been thinking and I came up with 2 possible explanations, one the motor driver expects a pwm signal voltage equal to that of the input voltage (VCC), or two the pwm signal does not have enough power to trigger the driver(unlikely though).

You also need to connect the black wire of the motor to ground on the Arduino.
So: White & Black from the Arduino to the motor, and Red & Black from the battery to the motor

The VEX does not use the same voltage for signal and power, so I don’t think that’s it. The VEX sends the battery voltage (6V-9V) directly to the red wire on the motor ports. The white wire is driven by the PIC micro which is generating 5V logic signals. This is essentially what you are doing, so that should be OK.

Cheers,

  • Dean

Thanks a lot man!!!

I knew I was missing some little tiny detail… :smiley:

I will post some pictures of my new robot when it is completed.

Features of the robot

Bluetooth serial connection to the computer
Wireless video (pan/tilt)
Sensor feedback

The control center of my robot is going to be sick as well I plan on having a joystick control movement of the robot as well as (pan/tilt). The only problem is getting the dang joystick to work in vb.net ERRRRRR.

Well I thought I would update this post so other people can find it.

I didn’t post back before but even with the above posts the vex motors still didn’t work, connecting the micro controller ground to the motor ground did cause a reaction but it was very weird. What happened when I tried to drive the motor with raw pwm signals from the arduino (analogWrite()) was very odd, as I said the motor was very weird(unresponsive sometimes, wrong direction, wrong speeds ect…). I thought the motors were just incompatible but today I stumbled upon the solution. You must declare the motor pwm port as a servo motor in arduino. This drives the motor flawlessly with correct speeds and directions!!! And as was previously said you must connect the ground of the motor or servo to the ground of the arduino or it won’t work.

So that super cool robot I was talking about before is going to become a reality soon, my spring break starts Saturday (midterms tomorrow :mad:). I have since learned some new tricks on my computer programming in vb.net. So I plan on using the wii remote, wii nunchuck, and wii classic controller for the robot control!!! (No computer joystick though, I couldn’t find a single code snippet for joystick interface go figure!)

Part of the reason is that when we say PWM with regard to servos, it’s not the same as PWM when trying to create an brightness level for an LED. Since I lack Dean’s drawing skills let me refer you to this PWM vs PPS waveform article.

BTW - for those of you thinking about using an Arduino controller for a robot, you might want to check out the Roboduino.

I haven’t personally used one, but it looks interesting. If you get it in kit form, you could solder in female header connectors instead of the male ones it comes with. That way it should be plug-in compatible with VEX accessories.

It appears to have six PWM (motor/servo) ports, six analog inputs, six digital I/O pins, and one serial (Rx/Tx) port. You’ll have to be careful that you plug things into the right ports, though - they have the motor ports (unregulated power) intermixed with the digital ports (regulated power).

Cheers,

  • Dean

I would like to point out that you can produce servo signals on ANY of the I/O pins on the Arduino with the standard Servo library. You can control up to 12 servos per hardware timer (the regular old Arduino using ATmega168 or ATmega328 has 1 timer that can control 12 servos, the Arduino Mega, sporting the ATmega1280 has 4 that can control up to 48 servos). You are not limited to the PWM capable pins. I’ve even used the analog ports as digital outputs to control the servo-based claw on my VEX robot.

Now there are a couple of differences in performance between the Arduino servo control system and the VEX one. In VEX, you send a range of values between 0 and 255 (or -127 to 127 in RobotC), with 127 as center (0 for RobotC). However in the Arduino library, there are two possible ways to control a servo interface/motor. The first, and probably most user-friendly is based off of actual servos (not the continuous-rotation servos like the VEX motors). You send the servo/motor a value between 0 and 180, based off of degrees, with 90 as center. This reduces resolution a bit, but generally works just fine, since adding one or two points on the 0-255 scale doesn’t make a noticeable difference anyway. When using a servo, this comes with a nice little surprise. Whereas with VEX and most other servo controllers, you get 120 degrees of travel, with the Arduino controlling it, you actually get a full 180 degrees! I think it adds a bit in both directions, but I’m not sure. I have no idea if this amounts to an increase in speed of VEX motors, but I would assume not.

The second way to control a servo in Arduino is to feed the servo function the raw pulse duration in microseconds. For your average servo, it’s looking for a value between 1 and 2 milliseconds, or 1000 and 2000 uS (microseconds). However, with the increased range of travel for the Arduino servo driver, valid values are actually from 544 to 2400 uS. Again, I don’t know how the extended range impacts the VEX motors.

If you want to control VEX motors with minimal modification of code written for the VEX, I would use the byte values (0-255) from the code and the map() function in Arduino to transform the byte range directly to the microsecond range from 1000 to 2000 uS, since the 0-180 range is mapped to microseconds anyway. The fastest way to write microsecond values to servo outputs is to use the Servo.writeMicroseconds() function, although Servo.write() will also work, it just takes a couple more steps to check to see if the value is in the degrees range or the microseconds range.

As for circuitry, I’ve used one 7.2v power supply, and it worked fine. Plug the 7.2v into a breadboard or PCB or perfboard, run ground to the ground on the Arduino, and the +7.2v power line to Vin on the Arduino (NOT +3.3v or +5v, those come off of regulators on the Arduino board). Then just run ground to the black line of the VEX motor, power to the orange line, and a signal line from a digital output on the Arduino to the white wire on the motor. But yes, if you do want to use two separate power supplies for whatever reason, connect the grounds. As long as you don’t have any power lines going between the two systems, there won’t be a problem.

If you need any more help, you can e-mail me here: ajosmer@gmail.com

Good luck, and I hope you can use some of this information.

I’ve been resurrecting the Geo-Crawler using the Arduino Duemilanov (Very heavily thinking I might want to go with the Mega) as a replacement to the VEX 0.5 controller.

You’re probably experiencing the same I did with the VEX motors & servos with the Parallax Basic Stamp-2… The frequency of the PWM input to the motors & servos is slightly off, from standard RC servos. While the standard servo may have a bandwidth from 200 to 850Hz, I’m finding the VEX servos and motors have a bandwidth of closer to 120 to 1000Hz. from one direction to the other.

I tried this quite a few years back, so I’m not 100% on the above frequencies, but the VEX devices are indeed a different bandwidth… Which might explain the odd behavior. Also, they need to be fed the full battery voltage (5V to 9V) on the power wires (orange (+Bat) & Black (GND)) The signal (White) wire is the only thing the MCU should be driving… Never use the on-chip (Arduino, Basicstamp, etc.) +5V regulator, or you’ll burn it out. Add a external regulator (a 7805) if needed, driven off the battery, then provide a +5V rail for your motor or servo power.

With the arduino, the problem of frequency goes to the servo.h library, which gives the frequency-out for a standard servo, and this may need to be tinkered with, and renamed to vexservo.h, before adding it to the arduino sketch.

Besides the Geo-Crawler, I had a square-bot that I put a Parallax HomeWork board (BasicStamp-2 mounted on the board itself.) using a TV remote to control it, and it had all kinds of power problems, til I added the 1-amp 7805 regulator to handle the motor voltage. I also had to alter the freqout values to handle the bandwidth requirements for the VEX motors, because it was always creeping backwards when I told it to rotate one motor, but hold the other in place. (the middle value from the Parallax program was off just enough, the VEX motor was rotating, or chattering that it was trying to move.)

Hi, I know this is an old post, but I’m wondering if someone can post pictures of the way to wire the arduino to the motor with an external power supply. Also if someone could help me with the code because right now my motor is just making a faint clicking sound when I supply a 1000uS value. Here is the code I am using right now:

#include <Servo.h>

Servo myservo;

void setup()
{
myservo.attach(9);
myservo.writeMicroseconds(1000);
}

void loop() {}

Well with the code the issue is that the write command isn’t being looped it is only being ran once when the Ardunio actually turns on. Move it the void loop part and it should work.

I would use a different H-Bridge meant for Arduino and hook the motor up to that. No PWM differences then and power is supplied how you want it to.

Depending upon your arduino, the shield can matter a ton for fit and the size of the motors you can run. What do we have with the 393 motor? Just the + and - wires! Let the arduino do the signal stuff, off the h-bridge comes the motor.

I have used this nano but with smaller hobby motors. Never tried the Vex ones. You run the Vex power through the main supply on the board. Arduino is powered how you normally do it.
http://www.gravitech.us/2mwfecoadfor.html

Motors are the top of picture terminals, battery hooks to the bottom ones.

This is for a different Arduino board

When I did that nothing happened.

How exactly would you hook it up. Also I don’t think I have time to get new parts I just need a way to control the direction of a vex motor with an arduino.

If you want to power the motor not of 5 volts then you run the red of the battery to the red of the motor controller and the black of the battery to the black of the motor controller you also run the black from the motor controller to a gnd pin on the Ardunio and then the white wire of the motor control is run to one of the DIO pins that support pwm and then power the Ardunio how you normally would.