Pages: [1] 2 3   Go Down
Author Topic: Gamepad connected to computer controls servos connected to Arduino board?  (Read 2696 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have PS2 gamepad. I have XBOX 360 gamepad.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, there is a library that allows you to use a Xbox controller with an arduino, check this out.


and maybe this.

http://forums.makezine.com/comments.php?DiscussionID=7799
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yea that would work.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

post both codes
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3400
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 3
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
      }
    }
  }
}

Logged

Pages: [1] 2 3   Go Up
Jump to: