Shop OBEX P1 Docs P2 Docs Learn Events
servo controlling with switches — Parallax Forums

servo controlling with switches

science_geekscience_geek Posts: 247
edited 2007-10-09 01:45 in Robotics
im working on interfacing an atari controller or a pair of dpdt switches that will control the servos, if you could please tell me how or send me a sample code i could modify it would be much appreciatedfreaked.gif

Comments

  • UncandayUncanday Posts: 28
    edited 2007-05-18 00:13
    do you mean code to read the switches?

    Regards
    Duncan
  • science_geekscience_geek Posts: 247
    edited 2007-05-18 01:56
    yes like how to make the chip read that the switch is on or off thats all i need, but i cant figure out how to do (i'll probably slap myself when someone tells me how easy it is)
  • DgswanerDgswaner Posts: 795
    edited 2007-05-18 04:05
    If I remember right.. and if your talking about the old Atari joysticks then they are essentially digital. when you move the joystick a direction it just pushes a button. and so it just reads as off or on. and does not read a value controlled by pots. So if that is true then here is what I would do....

    Get some code to read the switches... up, down, left, right.
    Have your code center the servos at start up.
    Have 2 variables one for each axis. lets say X and Y
    the X and Y variables would need to be initialized to center the servos
    Then enter a loop that watches for the joystick directions (buttons)
    if Left is detected then subtract 200 from X, if right is detected then add 200.
    so by repeating the loop it will continue to increase\lower the freq. thus moving the servo.
    Have the same thing for the Y axis.

    The numbers above would need to be adjusted depending on the servo you have and other aspects. you would also want to add in a pause in the main loop so you have some control over the speed of the servo movement.

    If the joystick does have pots in it then you would need to use the RCtime command to read the value of the joystick in each axis and then come up with a formula that would change the resistance values to proportionally match the freq that you servo needs.

    good luck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A complex design is the sign of an inferior designer. - Jamie Hyneman

    Post Edited (Dgswaner) : 5/18/2007 4:19:18 AM GMT
  • UncandayUncanday Posts: 28
    edited 2007-05-18 04:11
    ok. First thing you need to do is figure out the configuration of switches. For instance, is it four single pole switches which short each of four outputs to a common ground, or is it double-throw switches that short a common wire for each of the axes to one of two outputs...

    Not knowing the model number I don't know the answer, but if you have it sitting in front of you Google should be able to help...

    HTH

    Regards
    Duncan
  • science_geekscience_geek Posts: 247
    edited 2007-05-18 13:53
    i know that its just an on off like a light switch, but i mean how do i right a code to make the chip say "servon on"
  • science_geekscience_geek Posts: 247
    edited 2007-05-18 20:10
    or better yet how do i write a code to make it say that a variable is true or false(off or on)
  • DgswanerDgswaner Posts: 795
    edited 2007-05-18 21:03
    I would review the BS2 Manual page 294 talks about the INput statement.
    here is some sample code :

    This is code from the Roaming with Ping. This is the part of the code to move the BoeBot (servos) Forward. you can find the entire code here
    www.parallax.com/detail.asp?product_id=28015 look near the bottom

    Forward_Pulse: ' Send A Single Forward Pulse
    PULSOUT PingServo, 2000 ' Ping Servo Forward Pulse Value
    PULSOUT LeftServo, 850 ' Left Servo Forward Pulse Value
    PULSOUT RightServo, 650 ' Right Servo Forward Pulse Value
    PAUSE 20 ' Refresh Delay
    RETURN

    attached is some code I used to test an IRPD sensor. the concept is the same as what you would need to detect the joystick. take a look at the code and if you still need help I'll see if I can't whip up some demo code tonight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A complex design is the sign of an inferior designer. - Jamie Hyneman
  • science_geekscience_geek Posts: 247
    edited 2007-05-19 02:32
    dont worry i figured it out
  • Zero CoolZero Cool Posts: 2
    edited 2007-10-08 20:56
    I ran across this post and I don't know if anyone is still watching or responding but... I have an old Atari game controller an I want use it to control couple of servos. However I run into a problem hooking the five wires up to my Stamp. The controller has it's own chip on it that should output a serial data unless I'm mistaken. I'm just not sure what to do with the data latch wire and clock wire. Any thing that would help or point me in the right direction would be greatly appreciated. Thanks
  • D FaustD Faust Posts: 608
    edited 2007-10-08 21:50
    I'm not sure but you ight need to use the shiftin command to read the controller.· Look at the command in the PBASIC help file.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • ZootZoot Posts: 2,227
    edited 2007-10-08 22:05
    I found this page: www.epanorama.net/documents/joystick/tvgames.html which discusses the Atari 2600 and 7800 joystick pinouts and protocols. The 2600 uses one wire per switch, so if that's what you have it would be as simple as hooking up each output pin from the joystick to a pin of the Stamp MAKING SURE TO LIMIT CURRENT AND/OR VOLTAGE if necessary.

    The 7800 uses a serial protocol, so SERIN would be the command to use in your Pbasic program. See the page above for serial specs and wiring suggestions.

    Once you've got your Stamp successfully reading and/or storing the "read" values from the joystick, then it will be time to attack the code to make it all do something useful. One thing I would consider if you have the hard-wired 2600 joysticks -- see if the output from the joystick is already "debounced" -- if not, you'll need to account for that in your code. See the BUTTON command in the Pbasic Manual for info about debounce and methods for dealing with it.

    P.S. -- I checked out the page again in more detail -- the 2600 joystick uses 5v at 50ma, so you would only need to limit current on the Stamp input pin(s) -- so you don't short things out if you make that pin an output or if the Stamp would otherwise be forced to sink or source too much current from the joystick. A 220ohm resistor would probably be fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Zero CoolZero Cool Posts: 2
    edited 2007-10-08 23:33
    OK... thanks for all the advice guy's but it turns out I steered you wrong... Now that I have the joystick in front of me I realize it is a NES controller. I'm going to go ahead and do some more research on the SHIFTIN and SERIN commands. Any other thoughts will still be appreciated. Thanks
  • ZootZoot Posts: 2,227
    edited 2007-10-09 01:45
    Bit of a difference, there, yep.

    This doc is for the Propeller, but it shows the NES controller setup, pinout, SPI protocol, etc. so it should be easy enough to hookup to a Stamp and use SHIFTIN to clock and read data.

    If you have more questions in general about the NES controller, you might want to try over in the Hydra forum as that board uses NES connectors and the Hyrdra folks seem to be pretty up on these joysticks.

    www.parallax.com/dl/docs/prod/prop/Hydra-Ch6All-v1.0.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.