Shop OBEX P1 Docs P2 Docs Learn Events
Considering the release a Joystick hack Object — Parallax Forums

Considering the release a Joystick hack Object

Keith YoungKeith Young Posts: 569
edited 2011-02-09 10:49 in Propeller 1
You guys have been very helpful with a project I have been doing so I would like to return the favor. My project is currently using a USB Logitech Joystick as linked:

http://www.amazon.com/Logitech-Extreme-Joystick-Silver-Black/dp/B00009OY9U/ref=sr_1_1?ie=UTF8&qid=1296361030&sr=8-1


414X2Z0A7TL._SL500_AA300_.jpg

When you take it apart, you can remove the internal USB board and either simply plug in your own breadboard wires or even find the correct connection to make a PCB if you wish. There is enough space in there for a Prop on a custom made PCB if you wish to do so.

The joystick operates strangely in that the buttons aren't connected to high or low, but instead are pulsed on phases so that fewer wires can be used for the manufacturer. In order to get best use of this I made an assembly program, which is my first assembly program and also the first thing done almost "prefessional" enough to release.

Could you guys look over this and see if you like the idea? And also comment on what I need to change to make this releaseable.

Obviously it will need some sort of schematic.
CON
  _clkmode  = xtal1 + pll16x
  _xinfreq  = 5_000_000                                                        
  ADC_dpin  = 1
  ADC_cpin  = 2
  ADC_spin  = 0
  rudderc   = 0
  aileronc  = 1
  elevatorc = 2
  throttlec = 3       
 
OBJ
 
  AD    : "MCP3208_fast_ADC"          
  DB    : "FullDuplexSerial"         
 
VAR
 
  long Shared
  word rudder, aileron, elevator, throttle
  long stack[256]
 
PUB Start 
 
  AD.Start(ADC_dpin, ADC_cpin, ADC_spin, 0) 'Start ADC
  DB.Start( 31, 30, 0, 57600)               'Start Parallax Serial Terminal communication
  cognew(@entry, @Shared)                   'Begin running Assembly code
  cognew(Check_Act, @stack[0])              'Check status of joystick and act
 
Pub Check_Act
  dira[27]~~
  outa[27]~
  dira[26]~~
  outa[26]~
 
  repeat                
    rudder   := AD.In(rudderc)        'Get ADC value of Rudder
    aileron  := AD.In(aileronc)       'Get ADC value of Aileron 
    elevator := AD.In(elevatorc)      'Get ADC value of Elevator
    throttle := AD.In(throttlec)      'Get ADC value of Throttle
 
    DB.Dec(Shared)                    'Display status of Buttons
    DB.Str(String(13))
    DB.Dec(rudder)                    'Display Rudder value
    DB.Str(String(13))
    DB.Dec(aileron)                   'Display Aileron value
    DB.Str(String(13))           
    DB.Dec(elevator)                  'Display Elevator value
    DB.Str(String(13))
    DB.Dec(throttle)                  'Display Throttle value
    DB.Str(String(13))
 
    if shared & butt1 == butt1        'Check if trigger is pulled. Trigger is Button 1
      outa[27]~~                      'Turn on light if trigger is pulled
    else
      outa[27]
    if shared & butt13 == butt13 and shared & butt14 == butt14
      outa[26]~~                      'If HAT switch is pushed forward and right
    else                              'turn on a light
      outa[26]~     
 
DAT         
           ORG      0
 
entry      mov Mem, PAR         
           or       dira,pinn21         
           or       outa,pinn21   
           or       dira,pinn25         
           or       outa,pinn25         
           or       dira,pinn24          
           or       outa,pinn24  
{{         or       dira,pinn10      Un comment this area in order to use            
           or       outa,pinn10      the 6 buttons on the base of the                
           or       dira,pinn15      joystick and the throttle                       
           or       outa,pinn15                                                      
           or       dira,pinn17      ALL AREAS OF CODE COMMENTED OUT BELOW CONTROL  
           and      outa,pinn17      JOYSTICK BASE. UNCOMMENT FOR THIS FUNCTION   }}
           or       dira,pinn27        
           and      outa,pinn27
           xor      outa,pinn21
           xor      outa,pinn25
           xor      outa,pinn24
           'xor      outa,pinn10                           
           'xor      outa,pinn15                                                        
           mov      time,cnt             'Current clock loaded into time
           add      time,delay           'delay added to time    
:Loop                                               
           xor      outa, pinn21         'Pin 21 PHASE 1
           waitcnt  time,delay
           mov      temp, ina              
           test     temp,   pinn23    wz '13 Hat Up     
    if_z   or       button, butt13         
    if_nz  andn     button, butt13         
           test     temp,   pinn22    wz '14 Hat Right    
    if_z   or       button, butt14       
    if_nz  andn     button, butt14
           test     temp,   pinn19    wz '15 Hat Down          
    if_z   or       button, butt15       
    if_nz  andn     button, butt15
           test     temp,   pinn20    wz '16 Hat Left      
    if_z   or       button, butt16       
    if_nz  andn     button, butt16      
           xor      outa, pinn21
'-------------------------------------------------------------------- 
           xor      outa, pinn25         'Pin 25 PHASE 2
           waitcnt  time,delay
           mov      temp, ina             
           test     temp,   pinn20    wz '1 Trigger      
    if_z   or       button, butt1       
    if_nz  andn     button, butt1          
           test     temp,   pinn19    wz '2 Secondary     
    if_z   or       button, butt2       
    if_nz  andn     button, butt2
           test     temp,   pinn22    wz '3 Bottom Left    
    if_z   or       button, butt3       
    if_nz  andn     button, butt3
           test     temp,   pinn23    wz '4 Bottom Right   
    if_z   or       button, butt4       
    if_nz  andn     button, butt4     
           xor      outa, pinn25
'----------------------------------------------------------------------------------
           xor      outa, pinn24         'Pin 24 PHASE 3       
           waitcnt  time,delay
           mov      temp, ina             
           test     temp,   pinn20    wz '5 Top Left            
    if_z   or       button, butt5        
    if_nz  andn     button, butt5        
           test     temp,   pinn19    wz '6 Top Right     
    if_z   or       button, butt6       
    if_nz  andn     button, butt6
           xor      outa, pinn24
'-------------------------------------------------------------------------------------   
{{           xor      outa, pinn10       'Pin 10 PHASE 4            
           waitcnt  time,delay                                                      
           mov      temp, ina                                                        
           test     temp,   pinn12    wz '7                                          
    if_z   or       button, butt7                                                    
    if_nz  andn     button, butt7                                                    
           test     temp,   pinn11    wz '8                                          
    if_z   or       button, butt8                                                    
    if_nz  andn     button, butt8                                                    
           xor      outa, pinn10                                                     
'------------------------------------------------------------------------------------ 
           xor      outa, pinn15         'Pin 15 PHASE 5                             
           waitcnt  time,delay                                                       
           mov      temp, ina                                                        
           test     temp,   pinn13    wz '9                                          
    if_z   or       button, butt9                                                    
    if_nz  andn     button, butt9                                                    
           test     temp,   pinn14    wz '10                                         
    if_z   or       button, butt10                                                   
    if_nz  andn     button, butt10                                                   
           test     temp,   pinn12    wz '11                                         
    if_z   or       button, butt11                                                   
    if_nz  andn     button, butt11                                                   
           test     temp,   pinn11    wz '12                                         
    if_z   or       button, butt12                                                   
    if_nz  andn     button, butt12                                                   
           xor      outa, pinn15      }}                                              
           wrlong   button, Mem            
           jmp      #:Loop               ' Check trigger again using :loop
 
  button                byte    %000000000000000
  shareds               long    %000000000000000
  rudders               long    %000000000000000
  ailerons              long    %000000000000000
  elevators             long    %000000000000000
  throttles             long    %000000000000000       
 
  delay     long    5000
  pinn21    long    |< 21
  'pinn10    long    |< 10     
  pinn25    long    |< 25
  pinn24    long    |< 24
  'pinn15    long    |< 15
  'pinn17    long    |< 17
  pinn27    long    |< 27     
  pinn20    long    |< 20
  pinn19    long    |< 19
  pinn22    long    |< 22
  pinn23    long    |< 23
  'pinn12    long    |< 12  
  'pinn11    long    |< 11  
  'pinn13    long    |< 13  
  'pinn14    long    |< 14
  butt1     long    |<  0
  butt2     long    |<  1
  butt3     long    |<  2
  butt4     long    |<  3
  butt5     long    |<  4
  butt6     long    |<  5
 ' butt7     long    |<  6
 ' butt8     long    |<  7
 ' butt9     long    |<  8
 ' butt10    long    |<  9
 ' butt11    long    |< 10
 ' butt12    long    |< 11
  butt13    long    |< 12 
  butt14    long    |< 13
  butt15    long    |< 14
  butt16    long    |< 15
  temp      long    0 
  time      Res     1    
  Mem       Res     1
300 x 300 - 14K

Comments

  • AndreLAndreL Posts: 1,004
    edited 2011-01-29 21:50
    If it works, just package it into a clean object, so someone can use it from another program. Looks like its commented, so that's good. Then write up a little doc, make a demo or 2, and put it all into a nice ZIP, so people can use it. You can ALWAYS do version 1.1, 2.0, etc. so don't worry about it being perfect.

    Andre'
  • Keith YoungKeith Young Posts: 569
    edited 2011-01-30 00:19
    My progress so far. Please let me know what you see wrong etc. I'll probably eventually make an official thread including the hardware for this item since it lends itself very nicely to being put in a custom box with sliders and you could even fit a Prop inside the unit as it is keeping the professional look. Plus with it being $30 I think just about everyone could use one.
    {{
    Keith Young
    Jan 30 2011
                    This assumes colors of wires are the same throughout the manufacturing
                    history of this product. You may wish to check this so as to be sure
                    you aren't connecting this bass ackwards.
              Joystick  -----------------------------------------------------------------
                    Red     &#9532;  Pin 19 and Pull Up  3.3V   (I use 10Kohm)
                    Green   &#9532;  Pin 20 and Pull Up  3.3V
                    White   &#9532;  Pin 21
                    Yellow  &#9532;  Pin 22 and Pull Up  3.3V
                    Pink    &#9532;  Pin 23 and Pull Up  3.3V
                    Orange  &#9532;  Pin 24
                    Grey    &#9532;  Pin 25
                    Brown   &#9532;  3.3V
      Rudder Pot    Black   &#9532;  1st Channel ADC
                    Blue    &#9532;  GND
                            
                    Red     &#9532;  3.3V
      Aileron Pot   Green   &#9532;  2nd Channel ADC
      Elevator Pot  White   &#9532;  3rd Channel ADC
                    Black   &#9532;  GND
              Joystick Base  ------------------------------------------------------------
                    Orange  &#9532;  Pin 15 
                    Black   &#9532;  Pin 14 and Pull Up  3.3V
                    Brown   &#9532;  Pin 13 and Pull Up  3.3V
                    Grey    &#9532;  Pin 12 and Pull Up  3.3V
                    Pink    &#9532;  Pin 11 and Pull Up  3.3V
                    Yellow  &#9532;  Pin 10 
                    White   &#9532;  GND
       Throttle Pot Green   &#9532;  4rth Channel ADC
                    Red     &#9532;  3.3V                          
    }}
    CON
      _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000                                                        
      ADC_dpin  = 1
      ADC_cpin  = 2
      ADC_spin  = 0
      rudderc   = 0
      aileronc  = 1
      elevatorc = 2
      throttlec = 3       
                                       
    OBJ
                                          
      AD    : "MCP3208_fast_ADC"          
      DB    : "FullDuplexSerial"         
                               
    VAR
              
      long Shared
      word rudder, aileron, elevator, throttle
      long stack[256]
                                                         
    PUB Start 
                                                  
      AD.Start(ADC_dpin, ADC_cpin, ADC_spin, 0) 'Start ADC
      DB.Start( 31, 30, 0, 57600)               'Start Parallax Serial Terminal communication
      cognew(@entry, @Shared)                   'Begin running Assembly code
      cognew(Check_Act, @stack[0])              'Check status of joystick and act
                                                      
    Pub Check_Act
      dira[27]~~
      outa[27]~
      dira[26]~~
      outa[26]~
                  
      repeat                
        rudder   := AD.In(rudderc)        'Get ADC value of Rudder
        aileron  := AD.In(aileronc)       'Get ADC value of Aileron 
        elevator := AD.In(elevatorc)      'Get ADC value of Elevator
        throttle := AD.In(throttlec)      'Get ADC value of Throttle
         
        DB.Dec(Shared)                    'Display status of Buttons
        DB.Str(String(13))
        DB.Dec(rudder)                    'Display Rudder value
        DB.Str(String(13))
        DB.Dec(aileron)                   'Display Aileron value
        DB.Str(String(13))           
        DB.Dec(elevator)                  'Display Elevator value
        DB.Str(String(13))
        DB.Dec(throttle)                  'Display Throttle value
        DB.Str(String(13))
                                                          
        if shared & butt1 == butt1        'Check if trigger is pulled. Trigger is Button 1
          outa[27]~~                      'Turn on light if trigger is pulled
        else
          outa[27]~
        if shared & butt13 == butt13 and shared & butt14 == butt14
          outa[26]~~                      'If HAT switch is pushed forward and right
        else                              'turn on a light
          outa[26]~     
                                                    
    DAT         
               ORG      0
                                             
    entry      mov Mem, PAR         
               or       dira,pinn21         
               or       outa,pinn21   
               or       dira,pinn25         
               or       outa,pinn25         
               or       dira,pinn24          
               or       outa,pinn24  
    {{         or       dira,pinn10      Un comment this area in order to use            
               or       outa,pinn10      the 6 buttons on the base of the                
               or       dira,pinn15      joystick and the throttle                       
               or       outa,pinn15                                                      
               or       dira,pinn17      ALL AREAS OF CODE COMMENTED OUT BELOW CONTROL  
               and      outa,pinn17      JOYSTICK BASE. UNCOMMENT FOR THIS FUNCTION   }}
               or       dira,pinn27        
               and      outa,pinn27
               xor      outa,pinn21
               xor      outa,pinn25
               xor      outa,pinn24
               'xor      outa,pinn10                           
               'xor      outa,pinn15                                                        
               mov      time,cnt             'Current clock loaded into time
               add      time,delay           'delay added to time    
    :Loop                                               
               xor      outa, pinn21         'Pin 21 PHASE 1
               waitcnt  time,delay
               mov      temp, ina              
               test     temp,   pinn23    wz '13 Hat Up     
        if_z   or       button, butt13         
        if_nz  andn     button, butt13         
               test     temp,   pinn22    wz '14 Hat Right    
        if_z   or       button, butt14       
        if_nz  andn     button, butt14
               test     temp,   pinn19    wz '15 Hat Down          
        if_z   or       button, butt15       
        if_nz  andn     button, butt15
               test     temp,   pinn20    wz '16 Hat Left      
        if_z   or       button, butt16       
        if_nz  andn     button, butt16      
               xor      outa, pinn21
    '-------------------------------------------------------------------- 
               xor      outa, pinn25         'Pin 25 PHASE 2
               waitcnt  time,delay
               mov      temp, ina             
               test     temp,   pinn20    wz '1 Trigger      
        if_z   or       button, butt1       
        if_nz  andn     button, butt1          
               test     temp,   pinn19    wz '2 Secondary     
        if_z   or       button, butt2       
        if_nz  andn     button, butt2
               test     temp,   pinn22    wz '3 Bottom Left    
        if_z   or       button, butt3       
        if_nz  andn     button, butt3
               test     temp,   pinn23    wz '4 Bottom Right   
        if_z   or       button, butt4       
        if_nz  andn     button, butt4     
               xor      outa, pinn25
    '----------------------------------------------------------------------------------
               xor      outa, pinn24         'Pin 24 PHASE 3       
               waitcnt  time,delay
               mov      temp, ina             
               test     temp,   pinn20    wz '5 Top Left            
        if_z   or       button, butt5        
        if_nz  andn     button, butt5        
               test     temp,   pinn19    wz '6 Top Right     
        if_z   or       button, butt6       
        if_nz  andn     button, butt6
               xor      outa, pinn24
    '-------------------------------------------------------------------------------------   
    {{           xor      outa, pinn10       'Pin 10 PHASE 4            
               waitcnt  time,delay                                                      
               mov      temp, ina                                                        
               test     temp,   pinn12    wz '7                                          
        if_z   or       button, butt7                                                    
        if_nz  andn     button, butt7                                                    
               test     temp,   pinn11    wz '8                                          
        if_z   or       button, butt8                                                    
        if_nz  andn     button, butt8                                                    
               xor      outa, pinn10                                                     
    '------------------------------------------------------------------------------------ 
               xor      outa, pinn15         'Pin 15 PHASE 5                             
               waitcnt  time,delay                                                       
               mov      temp, ina                                                        
               test     temp,   pinn13    wz '9                                          
        if_z   or       button, butt9                                                    
        if_nz  andn     button, butt9                                                    
               test     temp,   pinn14    wz '10                                         
        if_z   or       button, butt10                                                   
        if_nz  andn     button, butt10                                                   
               test     temp,   pinn12    wz '11                                         
        if_z   or       button, butt11                                                   
        if_nz  andn     button, butt11                                                   
               test     temp,   pinn11    wz '12                                         
        if_z   or       button, butt12                                                   
        if_nz  andn     button, butt12                                                   
               xor      outa, pinn15      }}                                              
               wrlong   button, Mem            
               jmp      #:Loop               ' Check trigger again using :loop
                                                               
      button                byte    %000000000000000      
                                                      
      delay     long    5000
      pinn21    long    |< 21
      'pinn10    long    |< 10     
      pinn25    long    |< 25
      pinn24    long    |< 24
      'pinn15    long    |< 15
      'pinn17    long    |< 17
      pinn27    long    |< 27     
      pinn20    long    |< 20
      pinn19    long    |< 19
      pinn22    long    |< 22
      pinn23    long    |< 23
      'pinn12    long    |< 12  
      'pinn11    long    |< 11  
      'pinn13    long    |< 13  
      'pinn14    long    |< 14
      butt1     long    |<  0
      butt2     long    |<  1
      butt3     long    |<  2
      butt4     long    |<  3
      butt5     long    |<  4
      butt6     long    |<  5
     ' butt7     long    |<  6
     ' butt8     long    |<  7
     ' butt9     long    |<  8
     ' butt10    long    |<  9
     ' butt11    long    |< 10
     ' butt12    long    |< 11
      butt13    long    |< 12 
      butt14    long    |< 13
      butt15    long    |< 14
      butt16    long    |< 15
      temp      long    0 
      time      Res     1    
      Mem       Res     1
    
  • Keith YoungKeith Young Posts: 569
    edited 2011-01-31 14:33
    This object has been released.

    http://obex.parallax.com/objects/706/

    I can assure you that this object can drive a servo location and it's speed, it can read any combination of its buttons, and read every axis when those functions are added. They just are not included in this demo at the moment. I don't want you to feel you may be paying $30.00 for a joystick that won't work.

    I will likely make a YouTube Video shortly.

    Please comment as this is my first OBEX upload, I'd like to be sure I'm not missing anything.

    Anyone who already owns this type of joystick please test this. See if the instructions are clear and if you can get it working easily your first attempt.

    Someone with more electronics experience may know for example if a different pull up resistor value is more optimal.
  • Keith YoungKeith Young Posts: 569
    edited 2011-01-31 15:18
  • RonPRonP Posts: 384
    edited 2011-02-01 01:19
    roughwood,

    Nice Project. My other Hobby the more expensive one is flying RC 3D Heli's. I was wondering are you planing on flying a RC plane or something with your rig. I think that would be neat to fly a RC plane with that set up. Just curious. Going to check out the new Object.

    -Ron
  • Keith YoungKeith Young Posts: 569
    edited 2011-02-01 01:35
    This is for an FPV aircraft for both fun and aerial photography which will help pay for the project. Search FPV in YouTube and you'll see what that part of the project will entail. The main thing will be operating the real camera and protecting it since it will be pretty expensive. Communication failsafes, autopilot return, things of that nature will take up the majority of my work.

    This joystick is fully hackable so you could use throttle for collective, and twist of the joystick for the tail collective. Plenty of buttons for all the channels on any plane. 16 buttons if I recall, plus I set it up so you can take any combination of those buttons.
  • RonPRonP Posts: 384
    edited 2011-02-01 02:05
    Sounds like you have your work cut out for you. At this point I don't have the skills to write a program for CCPM to use it for a Helicopter. Plus I don't see an advantage for 3D flying. But I think it would be a blast in a little electric plane. Nice work on the Object l think you explained it well compared to some of the Objects in the Exchange. I don't know PASM and i am just learning SPIN so take it for what its worth. 2 cents :smile:
  • Keith YoungKeith Young Posts: 569
    edited 2011-02-01 13:32
    It won't help for 3D flying no lol.

    But for general flight and motion control, even for Hydra games etc, this thing could be pretty cool. Plus with PWM etc it can be made to work on an Arduino or pretty much whatever someone happens to be using.
  • Keith YoungKeith Young Posts: 569
    edited 2011-02-09 10:49
    Can anyone say if they've gotten this to work or if they're having trouble? I am about to hit all my exams and won't have much time to fix any problems pretty soon here.
Sign In or Register to comment.