Go Down

Topic: Gamepad connected to computer controls servos connected to Arduino board? (Read 3 times) previous topic - next topic

jeffmorris

Is it possible to have a gamepad connected to computer control servos connected to Arduino board?

gamepad > computer > Arduino board > servos

gamepad > computer > Xbee > Xbee > Arduino board > servos


HazardsMind

If it is a PS2 gamepad then you can just connect it directly to the arduino. I've done this before and it worked perfectly.

jeffmorris


HazardsMind


jeffmorris

I am hearing-impaired and the video doesn't have captioning.

zoomkat

Quote
I am hearing-impaired and the video doesn't have captioning.


There are links below the video when the below is viewed at the youtube site. click the youtube icon on the bottom right of the video frame.

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

jeffmorris

I tried the links below the video but the person who created the video made his own motor controller. I don't know if he uses XBee modems or not.

HazardsMind

That xbox controller is either USB or Bluetooth, so you will need either a BT module or USB module, to communicate between it and the arduino.

jeffmorris

There are wired and wireless XBOX 360 gamepads. The person in the video was using a wired XBOX 360 gamepad. Do I need an USB Host Shield like this: https://www.sparkfun.com/products/9947 ?

HazardsMind


jeffmorris

Am I supposed to run the Gamepad Processing code on my computer and the Motor Arduino code on the Arduino board? Running the Gamepad Processing code opens the Gamepad window where I see the sliders move when I move the thumbsticks on the gamepad. After uploading the Motor code to the Arduino, I open the Serial Monitor and the X-CTU window but nothing is happening on either terminal window. The person in the video uses motors controlled by H-Bridge circuit. My robot uses continuous servos. Any suggestions?

HazardsMind


jeffmorris

http://www.mediafire.com/?s8xawz38e3sy0t1#!

I didn't write the code. Someone else wrote the code. Gamepad V2.0 seems to work but Motor V2.0 doesn't work because he uses motors connected to H-Bridge circuit and I have servos. He made his own H-Bridge circuit. I have Pololu Simple Motor Controller, Sparkfun Serial Controlled Dual Motor Driver, Seeed Studio Motor Shield, and Tamiya Twin Motor Gearbox. I'm not sure which motor controller work.

HazardsMind

Ok, are you using the servo library to control your servos? His code will obviously need to be altered to work with your servos.

jeffmorris

I tried to modify the code to control two DC motors connected to Seeed Studio Motor Shield. 0 to 127 runs the motor forward. 0 to -127 runs the motor backward.

Link to Seeed Studio Motor Shield Wiki: http://www.seeedstudio.com/wiki/Motor_Shield

Code: [Select]

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int speedpinB=10;//enable motor B
int spead =127;//define the spead of motor
byte checkByte = 0;         // incoming serial byte
byte lMotorSpeed = 0;
byte rMotorSpeed = 0;
byte lMotorDir = 0;
byte rMotorDir = 0;
int ledPin = 4;
int counter = 0;
int timeout = 15; // about half a second
int second = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}
void loop()

  if(Serial.available())
  {
    if (Serial.available() > 2)
    {
      checkByte = Serial.read();
      if(checkByte == '#')
      {
        counter = 0;
        digitalWrite(ledPin, HIGH);
        lMotorSpeed = Serial.read();
        rMotorSpeed = Serial.read();
        //Serial.println("checkByte OK!");
        lMotorSpeed = (Serial.read()-'0')*100;
        lMotorSpeed += (Serial.read()-'0')*10;
        lMotorSpeed += (Serial.read()-'0');
        //Serial.print("L Value Read: ");
        //Serial.println(lMotorSpeed, BIN);
        rMotorSpeed = (Serial.read()-'0')*100;
        rMotorSpeed += (Serial.read()-'0')*10;
        rMotorSpeed += (Serial.read()-'0');
        //Serial.print("R Value Read: ");
        //Serial.println(rMotorSpeed, BIN);
        lMotorDir = bitRead(lMotorSpeed, 7);
        rMotorDir = bitRead(rMotorSpeed, 7);
        //Serial.print("L Motor Dir: ");
        //Serial.println(lMotorDir, BIN);
        //Serial.print("R Motor Dir: ");
        //Serial.println(rMotorDir, BIN);
        if(lMotorDir)
        {
          //Serial.println("L Motor Dir: Backwards");
          digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
          digitalWrite(pinI3,HIGH);
        } 
        else
        {
          //Serial.println("L Motor Dir: Forwards");
          digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
          digitalWrite(pinI3,LOW);
        }
        if(rMotorDir)
        {
          //Serial.println("R Motor Dir: Backwards");
          digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
          digitalWrite(pinI1,LOW);
        } 
        else
        {
          //Serial.println("R Motor Dir: Forwards");
          digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
          digitalWrite(pinI1,HIGH);
        }
        lMotorSpeed = map(lMotorSpeed, 0, 127, 0, 127);
        rMotorSpeed = map(rMotorSpeed, 0, 127, 0, 127);
        analogWrite(speedpinA,lMotorSpeed);//input a simulation value to set the speed
        analogWrite(speedpinB,rMotorSpeed);
      }
    }
  }
}


Go Up