Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 22 of 22
  1. #1
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257

    Default USB HID Joystick for Dummies

    Hi Guys,

    Want to make a USB HID (Human Interface Device) joystick? It's so easy!

    Attached is my dummies guide that will help you get the killer joystick you've always wanted.

    Cheers
    Squib
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2009
    Posts
    609

    Default

    Thanks. I'll try it next week.

  3. #3
    Join Date
    Jun 2009
    Posts
    3

    Default descriptor tool?

    Hi thanks for this info squibcakes!

    i think this is exactly what I need to move forward.
    I have EasyHid and have created the generic files but now need to understand the descriptor files.

    one question...don't know where to find 'Descriptor tool'. is it a text editor? where do I find it?

    cheers.
    gogsmack01

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    ...don't know where to find 'Descriptor tool'.
    Ahhh yes, one of my favorite programs.

    DT.exe

    Right side of the page ...
    http://www.usb.org/developers/hidpage/

    DT

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    617

    Default

    Gogsmack01,

    Writing descriptors is a headacke. I have managed to modify a few descriptors to do what I want, but always after many hours of banging my head against the walls.

    Robert

  6. #6
    Join Date
    Sep 2009
    Posts
    609

    Default

    I can't getg it work. can someone upload descriptor file?
    Thanks

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    617

    Default

    Pedja089,

    Look at the link that Darrel provided above. In there you will find a document about HID descriptors. In one of the appendixes at the end of the document they have descriptors for a mouse, a keyboard, and a joystick. That should help you.

    Get one of the sample descriptors that come with PBP and modify it accordingly. It should work.

    Robert

  8. #8
    Join Date
    Jun 2009
    Posts
    3

    Default flavour of pic BASIC

    Hi all
    I ran into a problem right at the start when my basic compiler threw some error messages. I am sure it is related to the flavour of PicBASIC I am using.
    squibcakes you are using PBP (PicBASIC Pro), I am using Proton+.
    the difference can be seen in variable declaration eg.
    dog VAR Byte 'PBP
    Dim dog Byte 'Proton+

    Hope I am not talking mince here, anyone can support this theory I'd be glad to hear.

    Once I sort out the source of compile errors I can forge ahead.

    cheers.
    Gordon.

  9. #9
    Join Date
    Jun 2009
    Posts
    3

    Default flavour of picBASIC addendum

    OK
    it is
    Dim dog As Byte 'Proton+


    cheers.
    Gordon.

  10. #10
    scumari's Avatar
    scumari Guest

    Default Make a joystick

    After reading the guide carefully and preparing the code, while compiling, i get varios errors about Simbols not previously defines.
    this happens with USBDeviceInit, USBDeviceTasks GetUSB and PutUSB???

    Should something be included here and what??

    Thanx

  11. #11
    scumari's Avatar
    scumari Guest

    Default Make a joystick

    Found a work arround.
    Copy the hid_desc.bas file and all associated files to your working directory.
    Copy the text made by DT.exe and changed by the ways of the Dummy Manual, into the 'ReportDescriptor1' part, overwriting existing code.

    This should do the trick.
    By this way I created a 6 axis,16 button pedestal.

    Have fun

    More MCU and other projects:
    http://www.scumari.nl/www/mcu
    Last edited by scumari; - 3rd November 2010 at 10:18.

  12. #12
    Join Date
    Sep 2009
    Posts
    609

    Default

    Can you upload project or pbp code and descriptor file?

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,810

    Default

    Quote Originally Posted by scumari View Post
    Found a work arround.
    Copy the hid_desc.bas file and all associated files to your working directory.
    Copy the text made by DT.exe and changed by the ways of the Dummy Manual, into the 'ReportDescriptor1' part, overwriting existing code.

    This should do the trick.
    By this way I created a 6 axis,16 button pedestal.

    Have fun

    More MCU and other projects:
    http://www.scumari.nl/www/mcu
    A better way is to "INCLUDE" the file like so . . .
    Code:
    INCLUDE "hid_desc.bas"
    The file MUST be in the same directory as the program you are writing.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  14. #14
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default Re: USB HID Joystick for Dummies

    Hi,

    I have got my usb joystick working, but my axis starts in the centre moves to the right, to the left side then back to the centre as i increase the pot.

    I am doing a simple "adcin, 0, USBBuffer[0]" as in your example.
    I tried shifting the result 4 bits to the left but this just mixes it up onto 2 axes.
    What am I doing wrong?

    Doh, all i had to do is add 128 to the result, boy do i feel foolish :-)

    Regards
    Bob...
    Last edited by BobEdge; - 21st April 2011 at 16:23.

  15. #15
    Join Date
    Jun 2005
    Location
    Penang
    Posts
    40

    Default Re: USB HID Joystick for Dummies

    Hello all,

    I am trying to convert my old joystick to USB Joystick.Since i am kinda new to USB,i plan to take this advantage to learn how USB works.I have tried CDC before & now HID.As a starting point,i searched for a example code & bumped to a site (www.starlino.com),an accelerometer based joystick.I downloaded the codes (which is in PBP) & researched the codes.After going through the USBDesc & tried the code (which worked very well) & i plan to expand it from original (2 Axis & 6 Buttons) to 3 Axis,Throttle & 8 buttons.I have modified the USBDesc & added some lines in source.To my suprise it connects to the computer (ting tong) & showed the axis,throttle & buttons in the gamepad configuration but it freeze in there.Whenever i press any of the buttons,i didn't work..i mean nothing happened.I have tried few methods but didn't work.Can anyone help me??.Attached codes together.

    *PS - The attached code is only for x,y,z axis & buttons.

    You help is kindly appreciated
    Attached Files Attached Files

  16. #16
    Join Date
    Jun 2005
    Location
    Penang
    Posts
    40

    Default Re: USB HID Joystick for Dummies

    Hello all,

    Sorry.The above attached USBDesc have throttle & not Z axis.I have modified few of them but the result are the same.No response.One way around the Buttons should work,but in my case none of it is working.

  17. #17
    Join Date
    Jun 2005
    Location
    Penang
    Posts
    40

    Default Re: USB HID Joystick for Dummies

    hello all,

    Ok.We make it simple here.I added Z axis but in the gamepad configurator it shows the Z axis but not working...

  18. #18
    scumari's Avatar
    scumari Guest

    Default Re: USB HID Joystick for Dummies

    Ok , A 4 axis joystick with 12 buttons and a hat switch:
    PBP code-----------------------------------------------------
    Include "Js_hid_desc.bas" ' Include the HID descriptors
    'Include "modedefs.bas" ' Include serial modes

    DEFINE OSC 48
    DEFINE LOADER_USED 1
    DEFINE RESET_ORG 1100h ' For Microchip USB Bootloader
    DEFINE INTERRUPT_ORG 1108h ' For Microchip USB Bootloader 'LED var PORTC.0

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 100 ' Set sampling time in uS

    USBBufferSizeMax con 10 ' maximum buffer size
    USBBufferSizeTX con 10 ' input
    USBBufferSizeRX con 10 ' output

    ' the USB buffer...
    USBBuffer Var Byte[USBBufferSizeMax]
    USBBufferCount Var Byte
    temp var byte

    ' ************************************************** **********
    ' * Port configuration: *
    ' * PORTD.0-7 are digital inputs *
    ' * AN0,AN5 active as analog inputs *
    ' ************************************************** **********

    PORTA = 0
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    TRISA = %11111111
    TRISB = %11111111
    TRISC = %11111111
    TRISD = %11111111
    TRISE = %11111111

    ADCON1 = %00001001

    ' ************************************************** **********
    ' * main program loop - remember, you must keep the USB *
    ' * connection alive with a call to USBService every couple *
    ' * of milliseconds or so... *
    ' ************************************************** **********
    USBInit ' initialise USB...
    ProgramStart:
    ' gosub DoUSBIn
    ADCIN 0,USBBuffer[0]
    ADCIN 1,USBBuffer[1]
    ADCIN 2,USBBuffer[2]
    ADCIN 3,USBBuffer[3]
    USBService ' keep connection alive
    temp = 255-PORTD
    USBBuffer.0(32) = PORTD.0
    USBBuffer.0(33) = PORTD.1
    USBBuffer.0(34) = PORTD.2
    USBBuffer.0(35) = PORTD.3
    USBBuffer.0(36) = temp.4
    USBBuffer.0(37) = temp.5
    USBBuffer.0(38) = temp.6
    USBBuffer.0(39) = temp.7
    USBService ' keep connection alive
    temp = 255-PORTB
    USBBuffer.0(40) = temp.0
    USBBuffer.0(41) = temp.1
    USBBuffer.0(42) = temp.2
    USBBuffer.0(43) = temp.3
    USBBuffer.0(44) = temp.4
    USBBuffer.0(45) = temp.5
    USBBuffer.0(46) = temp.6
    USBBuffer.0(47) = temp.7


    DoUSBOut1:
    USBBufferCount = USBBufferSizeTX ' TX buffer size
    USBService ' keep connection alive
    USBOut 1, USBBuffer, USBBufferCount, DoUSBOut2 ' if bus available, transmit data
    DoUSBOut2:
    GoTo ProgramStart

    DISCRIPTOR code----------------------------------------------------------------
    ReportDescriptor1
    RETLW 0x05
    RETLW 0x01 ; USAGE_PAGE (Generic Desktop)
    RETLW 0x09
    RETLW 0x04 ; USAGE (Joystick)
    RETLW 0xa1
    RETLW 0x01 ; COLLECTION (Application)
    RETLW 0x05
    RETLW 0x01 ; USAGE_PAGE (Generic Desktop)
    RETLW 0x09
    RETLW 0x04 ; USAGE (Joystick)
    RETLW 0xa1
    RETLW 0x00 ; COLLECTION (Physical)
    RETLW 0x09
    RETLW 0x30 ; USAGE (X)
    RETLW 0x09
    RETLW 0x31 ; USAGE (Y)
    RETLW 0x09
    RETLW 0x32 ; USAGE (Z)
    RETLW 0x09
    RETLW 0x33 ; USAGE (Rx)
    RETLW 0x75
    RETLW 0x08 ; REPORT_SIZE (8)
    RETLW 0x95
    RETLW 0x04 ; REPORT_COUNT (4)
    RETLW 0x35
    RETLW 0x00 ; PHYSICAL_MINIMUM (0)
    RETLW 0x46
    RETLW 0xff
    RETLW 0x00 ; PHYSICAL_MAXIMUM (255)
    RETLW 0x15
    RETLW 0x00 ; LOGICAL_MINIMUM (0)
    RETLW 0x26
    RETLW 0xff
    RETLW 0x00 ; LOGICAL_MAXIMUM (255)
    RETLW 0x81
    RETLW 0x02 ; INPUT (DataVarAbs)
    RETLW 0xc0 ; END_COLLECTION
    ; ------------ Hat Switches -------------------
    RETLW 0x09
    RETLW 0x39 ; Usage (Hat Sw)
    RETLW 0x15
    RETLW 0x00 ; Log Min (0)
    RETLW 0x25
    RETLW 0x03 ; Log Max (3)
    RETLW 0x35
    RETLW 0x00 ; Phy Min (0)
    RETLW 0x46
    RETLW 0x0e
    RETLW 0x01 ; Phy Max (270)
    RETLW 0x65
    RETLW 0x14 ; Unit (Eng Rot : Ang Pos)
    RETLW 0x75
    RETLW 0x04 ; Report Size (4)
    RETLW 0x95
    RETLW 0x01 ; Report Count (1)
    RETLW 0x81
    RETLW 0x02 ; Input (Data, Variable, Absolute)
    ; ------------ Buttons ------------------------
    RETLW 0x05
    RETLW 0x09 ; USAGE_PAGE (Button)
    RETLW 0x19
    RETLW 0x01 ; USAGE_MINIMUM (Button 1)
    RETLW 0x29
    RETLW 0x0c ; USAGE_MAXIMUM (Button 12)
    RETLW 0x15
    RETLW 0x00 ; LOGICAL_MINIMUM (0)
    RETLW 0x25
    RETLW 0x01 ; LOGICAL_MAXIMUM (1)
    RETLW 0x45
    RETLW 0x00 ; PHYSICAL_MAXIMUM (0)
    RETLW 0x55
    RETLW 0x00 ; UNIT_EXPONENT (0)
    RETLW 0x75
    RETLW 0x01 ; REPORT_SIZE (1)
    RETLW 0x95
    RETLW 0x0c ; REPORT_COUNT (12)
    RETLW 0x81
    RETLW 0x02 ; INPUT (Data Var Abs)
    RETLW 0xc0 ; END_COLLECTION
    EndReportDescriptor1


    Now a 8 axis joystick with 8 buttons:
    PBP Code-----------------------------------
    Include "Th_hid_desc.bas" ' Include the HID descriptors
    'Include "modedefs.bas" ' Include serial modes

    DEFINE OSC 48
    DEFINE LOADER_USED 1
    DEFINE RESET_ORG 1100h ' For Microchip USB Bootloader
    DEFINE INTERRUPT_ORG 1108h ' For Microchip USB Bootloader 'LED var PORTC.0

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 100 ' Set sampling time in uS

    'Define LCD_DREG PORTB ' LCD data pin port
    'Define LCD_DBIT 0 ' LCD data pin bit
    'Define LCD_RSREG PORTC ' LCD register select pin port
    'Define LCD_RSBIT 6 ' LCD register select pin bit
    'Define LCD_EREG PORTC ' LCD enable pin port
    'Define LCD_EBIT 7 ' LCD enable pin bit
    'Define LCD_BITS 4 ' LCD number of data bits
    'Define LCD_LINES 2 ' LCD number of lines

    'define HSER_RCSTA 090h
    'define HSER_TXSTA 0A4h
    'define HSER_BAUD 115200
    'define HSER_CLROERR

    USBBufferSizeMax con 10 ' maximum buffer size
    USBBufferSizeTX con 10 ' input
    USBBufferSizeRX con 10 ' output

    ' the USB buffer...
    USBBuffer Var Byte[USBBufferSizeMax]
    USBBufferCount Var Byte
    temp var byte

    ' ************************************************** **********
    ' * Port configuration: *
    ' * PORTD.0-7 are digital inputs *
    ' * AN0,AN5 active as analog inputs *
    ' ************************************************** **********

    PORTA = 0
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    TRISA = %11111111
    TRISB = %11111111
    TRISC = %11111111
    TRISD = %11111111
    TRISE = %11111111

    ADCON1 = %00001001

    ' ************************************************** **********
    ' * main program loop - remember, you must keep the USB *
    ' * connection alive with a call to USBService every couple *
    ' * of milliseconds or so... *
    ' ************************************************** **********
    USBInit ' initialise USB...
    ProgramStart:
    'gosub DoUSBIn
    ADCIN 0,USBBuffer[0]
    ADCIN 1,USBBuffer[1]
    ADCIN 2,USBBuffer[2]
    USBService
    ADCIN 3,USBBuffer[3]
    ADCIN 4,USBBuffer[4]
    ADCIN 5,USBBuffer[5]
    GoSub DoUSBOut ' keep connection alive
    ADCIN 6,USBBuffer[6]
    ADCIN 7,USBBuffer[7]

    temp = 255-PORTD
    USBBuffer.0(64) = temp.4
    USBBuffer.0(65) = temp.5
    USBBuffer.0(66) = temp.6
    USBBuffer.0(67) = temp.7

    temp = 255-PORTB
    USBBuffer.0(68) = temp.0
    USBBuffer.0(69) = temp.1
    USBBuffer.0(70) = temp.2
    USBBuffer.0(71) = temp.3

    USBBuffer.0(72) = temp.4
    USBBuffer.0(73) = temp.5
    USBBuffer.0(74) = temp.6
    USBBuffer.0(75) = temp.7


    'GoSub DoUSBOut
    USBBufferCount = USBBufferSizeTX ' TX buffer size
    USBService ' keep connection alive
    USBOut 1, USBBuffer, USBBufferCount, DoUSBOut2 ' if bus available, transmit data
    DoUSBOut2:

    GoTo ProgramStart

    DISCRIPTOR code----------------------------------------------------------------
    ReportDescriptor1
    RETLW 0x05
    RETLW 0x01 ; USAGE_PAGE (Generic Desktop)
    RETLW 0x09
    RETLW 0x04 ; USAGE (Joystick)
    RETLW 0xa1
    RETLW 0x01 ; COLLECTION (Application)
    RETLW 0x05
    RETLW 0x01 ; USAGE_PAGE (Generic Desktop)
    RETLW 0x09
    RETLW 0x04 ; USAGE (Joystick)
    RETLW 0xa1
    RETLW 0x00 ; COLLECTION (Physical)
    RETLW 0x09
    RETLW 0x30 ; USAGE (X)
    RETLW 0x09
    RETLW 0x31 ; USAGE (Y)
    RETLW 0x09
    RETLW 0x32 ; USAGE (Z)
    RETLW 0x09
    RETLW 0x33 ; USAGE (Rx)
    RETLW 0x09
    RETLW 0x34 ; USAGE (Ry)
    RETLW 0x09
    RETLW 0x35 ; USAGE (Rz)
    RETLW 0x09
    RETLW 0x36 ; USAGE (Ry)
    RETLW 0x09
    RETLW 0x37 ; USAGE (Rz)
    RETLW 0x75
    RETLW 0x08 ; REPORT_SIZE (8)
    RETLW 0x95
    RETLW 0x08 ; REPORT_COUNT (8)
    RETLW 0x35
    RETLW 0x00 ; PHYSICAL_MINIMUM (0)
    RETLW 0x46
    RETLW 0xff
    RETLW 0x00 ; PHYSICAL_MAXIMUM (255)
    RETLW 0x15
    RETLW 0x00 ; LOGICAL_MINIMUM (0)
    RETLW 0x26
    RETLW 0xff
    RETLW 0x00 ; LOGICAL_MAXIMUM (255)
    RETLW 0x81
    RETLW 0x02 ; INPUT (DataVarAbs)
    RETLW 0xc0 ; END_COLLECTION
    RETLW 0x05
    RETLW 0x09 ; USAGE_PAGE (Button)
    RETLW 0x19
    RETLW 0x01 ; USAGE_MINIMUM (Button 1)
    RETLW 0x29
    RETLW 0x10 ; USAGE_MAXIMUM (Button 16)
    RETLW 0x15
    RETLW 0x00 ; LOGICAL_MINIMUM (0)
    RETLW 0x25
    RETLW 0x01 ; LOGICAL_MAXIMUM (1)
    RETLW 0x45
    RETLW 0x00 ; PHYSICAL_MAXIMUM (0)
    RETLW 0x75
    RETLW 0x01 ; REPORT_SIZE (1)
    RETLW 0x95
    RETLW 0x10 ; REPORT_COUNT (16)
    RETLW 0x81
    RETLW 0x02 ; INPUT (Data Var Abs)
    RETLW 0xc0 ; END_COLLECTION
    EndReportDescriptor1


    They both work for FSX and X-Plane.
    See http://www.scumari.nl

    Have fun!
    Last edited by scumari; - 3rd December 2012 at 23:12.

  19. #19
    Join Date
    Apr 2014
    Posts
    21

    Default Re: USB HID Joystick for Dummies

    Hello gentlemen, im new to the forum and dont really know much about usb or PBP3 so sorry for the may-be dumb question since i use HITECH-C

    i did all off the dummies guide stuff but in the end, it asks me to compile, compile where? in MPLAB?

    ok so i compiled on mplab using the PBP3 compiler on the 15 trial version and it gives me the following:

    ERROR: Macro USBINIT? not found in macro file.
    ERROR: Macro USBSERVICE? not found in macro file.
    ERROR: Macro USBIN?CBBL not found in macro file.
    ERROR: Macro USBOUT?CBBL not found in macro file.Halting build on first failure as requested.
    BUILD FAILED: Tue Apr 22 22:28:08 2014


    apart from this, i would really like to know where do i configure my PIC18f2550??

    do i make a .c file?? (i.e MY_JOYSTICK.c)
    and work from there??
    how do i prevent/correct this compile errors??

    also, where can i find the circuit diagram for this "dummie" joystick, thanks a bunch guys and see you later

  20. #20
    Join Date
    Apr 2014
    Posts
    21

    Default Re: USB HID Joystick for Dummies

    sorry this is what im getting now

    Executing: "C:\Program Files (x86)\PBP3\PBPX.EXE" -ampasmwin -k# -p18F2550 "C:\Users\Aramburo\Desktop\Nueva carpeta\HUB.pbp"
    PICBASIC PRO(TM) Compiler 3.0.7.1, (c) 1998, 2013 microEngineering Labs, Inc.
    All Rights Reserved.
    Trial version. 15 days left.
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 761 : Symbol not previously defined (USBDeviceInit)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 762 : Symbol not previously defined (USBDeviceInit)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 761 : Symbol not previously defined (USBDeviceTasks)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 762 : Symbol not previously defined (USBDeviceTasks)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 761 : Symbol not previously defined (GetUSB)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 762 : Symbol not previously defined (GetUSB)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 761 : Symbol not previously defined (USBDeviceTasks)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 762 : Symbol not previously defined (USBDeviceTasks)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 761 : Symbol not previously defined (PutUSB)
    Error[113] C:\PROGRAM FILES (X86)\PBP3\PBPPIC18.LIB 762 : Symbol not previously defined (PutUSB)
    Halting build on first failure as requested.
    BUILD FAILED: Tue Apr 22 22:54:59 2014

  21. #21
    Join Date
    Apr 2014
    Posts
    21

    Default Re: USB HID Joystick for Dummies

    i cant find this file anywhere, where was it generated???



    hid_desc.bas

  22. #22
    Join Date
    Apr 2014
    Posts
    21

    Default Re: USB HID Joystick for Dummies

    (ignore this post please, posted on the worng thread)

Similar Threads

  1. USB hid maker help please.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2013, 14:49
  2. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 21:17
  3. USB MSD with HID code ?
    By Chris Barron in forum USB
    Replies: 1
    Last Post: - 11th November 2009, 18:33
  4. i cant get 18f2550 work as HID
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 13th October 2009, 16:39
  5. Replies: 0
    Last Post: - 6th March 2009, 08:52

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts