Shop OBEX P1 Docs P2 Docs Learn Events
Joystick Control — Parallax Forums

Joystick Control

BIG BIG ALBIG BIG AL Posts: 7
edited 2010-12-30 21:00 in BASIC Stamp
I'm a rookie trying to program a BASIC stamp so I can control an Underwater ROV with an old PC joystick. I have a Basic Stamp 2 Version C, a PWM Pal, a 1uF capacitor, a 220 Ohm resistor, and a PC Raider joystick (from waaaaay back in the day). This is all I have so far:


' ROV - TestRcToPulse

' {$STAMP BS2}
' {$PBASIC 2.5}

timeCounter VAR Word
counter VAR Byte
pulse VAR Byte


DEBUG CLS

HIGH 7
DEBUG "Charging...", CR

PAUSE 1000

DEBUG CR, CR, "Measuring decay time.", CR, CR
INPUT 7

DO
PAUSE 100 'Originally PAUSE 1
timeCounter = timeCounter + 1
LOOP UNTIL IN7 = 0

DEBUG "Decay time: ", DEC timeCounter, CR

IF timeCounter < 63 THEN jargon
timeCounter = 63
jargon:
pulse = timeCounter * 4

DEBUG "Pulse: ", DEC pulse

DO
FOR counter = 0 TO pulse
HIGH 1 'Originally 14
NEXT
FOR counter = pulse TO 252
LOW 1 'Originally 14
NEXT
LOOP


Before I can add motors and a motor driver, I need to get this program to work. Sometimes, the timeCounter value is outrageously high in all joystick positions, so the pulse value is always 252. If I change the rate at which the Stamp counts to get a lower timeCounter value, pulse gets outrageously low. And in any case, the numbers steadily rise the longer I keep the stamp plugged in. I'm pretty lost right now. Any words of guidance?

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-12-29 18:47
  • Grumpy_SmurfGrumpy_Smurf Posts: 6
    edited 2010-12-30 00:49
    A good tutorial on using an old analog joystick with a stamp here:
    http://www.yourwarrantyisvoid.com/2010/02/03/basic-stamp-a-quick-guide-on-using-a-legacy-joystick/

    Pictures and BS2 code for down-load
    I used this to make my joystick mod and made a mini board for holding the capacitors and resistors (see photos).
    I am using the joystick output to control 2 stepper motors (using 2 Little Step-U stepper motor controllers), a bit excessive, but these are spare parts I had around.

    just getting the joystick to work using the RCTime process is easy and cheap ($2 max)
    If I was going to do it again I would go straight to a multi channel ADC like the one on the Parallax store site (Item code 604-00062).
    Also, if you can, rewire the joystick so that the pots are differential (3 wires for each axis) as the resistance for each pot in the joystick is bound to be different, if you use single ended (1 common wire and 1 wire for the wiper of each axis you will need to spend a lot of time on calibration.

    I have modified the code and components recommended by the tutorial in the link to speed up the response and reduce the range to use a Byte rather than Word, happy to send details if you want, but really, go with the ADC - Sooooo much easier in the long run.
    1024 x 768 - 136K
    1024 x 768 - 106K
    1024 x 768 - 95K
  • BIG BIG ALBIG BIG AL Posts: 7
    edited 2010-12-30 21:00
    Thanks for your replies! It really helps!
Sign In or Register to comment.