Go Down

Topic: Interfacing Servo motors using USB gamepad (Read 695 times) previous topic - next topic

syd_xp

Hello everyone. I want to make a robotic arm which i can control it by a USB gamepad. I will give you the link how to communicate arduino using USB gamepad
http://teamprincipia.wordpress.com/2008/04/08/arduino-python-4-axis-servo-control/comment-page-4/#comment-537

I have a problem in controlling the servo motors. I want to do something like this, if i press a button on my usb gamepad the servo will rotate clockwise and if I press another button that same servo will rotate anticlockwise. What happens is that if I press a button ti goes from 0 to 180 degrees and 180 to 0 degrees. but i cant control them independently. Could anyone plz post a code how to control servos independently.

JimboZA

Seems like at the moment you have a variant of the standard sweep tutorial but with a button in the mix somewhere.

Why don't you post what you have so far... and what you've tried that incorporates the other button?
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

syd_xp

Here is my python code
https://github.com/aeropunk/Arduino-Python-4-Axis-Servo/blob/master/multijoystick.py

Here is a part of the whole code to show actually which one I am using
Code: [Select]
def handleJoyEvent(e):
    # Assign actions for Button DOWN events
    if e.type == pygame.JOYBUTTONDOWN:
        # Button 1 (trigger)
        if (e.dict['button'] == 0):
            print "Trriger Down"
            # Set pin 13 LED to HIGH for digital on/off demo
            servo.move(99, 180)
        # Button 2
        if (e.dict['button'] == 1):
            print "Button 2 Down"
            servo.move(5, 180) #This is used to select servo no. 5 and rotate it to 180 degrees
        # Button 4
        if (e.dict['button'] == 3):
            servo.move(5, 0) # #This is used to select servo no. 5 and rotate it back to 0 degrees
            print "Button 4 Down"

Here button == 1 will rotate the servo clockwise and button == 3 will rotate that servo anticlockwise . Also there is another file servo.py where there is move(servo, angle) function. here servo means number which sends data to switch statement below.
Here is my arduino code

https://raw.github.com/aeropunk/Arduino-Python-4-Axis-Servo/master/MultipleSerialServoControl.pde


Below is a part of my ardiono code
Code: [Select]

        case 5:
          if(pos == 180)
          {
            //What code should be written to rotate it clockwise as long as the button is pressed
          }
          if(pos == 0)
          {
            ////What code should be written to rotate it anti-clockwise as long as the button is pressed
          }
          servo5.write(fpos);
          delay(1000);
          break;

I have used the switch statement because its easier to communicate with usb gamepad through serial.read()

Go Up