Usb Joystick axis are hat

alenovo55

New member
Hello, im trying to have a 6 axis usb joystick using teensy lc. this is for a twin throttle quadrant for flight sim.
Im hoping perhaps a kind person can help me figure it out.

Ive flashed an example form teensyduino and set "keyboard+mouse+joystick" in usb settings and flashed.

Ive noticed some strange things

1) in ubuntu jstest-gtk is detecting 3 devices,
"teensyduino keyboard/mouse/joystick mouse" with 2 axis 8 buttons /dev/input/js1
"teensyduino keyboard/mouse/joystick" with 7 axis and 32 buttons /dev/input/js2
"teensyduino keyboard/mouse/joystick" with 12 axis and 78 buttons /dev/input/js3

only "teensyduino keyboard/mouse/joystick" with 7 axis and 32 buttons seems to be reporting any values.

2) only 2 axis actually work as axis, the other work as HAT , they have only 2 positions, 1 or 0, so only when i move the lever to the max the axis goes to 100% and when i move the lever to the min goes to 0 as a digital change, not gradual.

axis 5 is not even responding

how can i have 6 normal analogue axis reported as a usb joystick? ive measured with a multi-meter and all analogue axis from 0-5 are being feed voltage from 0 to 3.3v. im using analogue ports 0-5 pins 14 to 19.

code:

void setup() {

Joystick.useManualSend(true);
}

void loop() {
Joystick.X(analogRead(0));
Joystick.Y(analogRead(1));
Joystick.Z(analogRead(2));
Joystick.Zrotate(analogRead(3));
Joystick.sliderLeft(analogRead(4));
Joystick.sliderRight(analogRead(5));

Joystick.send_now();

delay(5);
}

thanks so much for your help
 
i managed to solve this, so for reference, i had some issues with sensors but still the default core code only supports 5 axis and 2 hats. i needed 6 axis no hats so i end up modifying the core scripts usb descriptors, and also now its reporting just 1 usb device instead of 3.

these can be found in ./.arduino15/packages/teensy/hardware/avr/1.59.0/cores/
for teensy lc modify cores/teensy3, for teensy 4.1 similarly its cores/teensy4

cores/teensy3/usb_desc.c
Code:
253,256c253
<         0x15, 0x00,                     //   Logical Minimum (0)
<         0x25, 0x07,                     //   Logical Maximum (7)
<         0x35, 0x00,                     //   Physical Minimum (0)
<         0x46, 0x3B, 0x01,               //   Physical Maximum (315)
---
>         // (Hat removed) keep 4 bits so packing stays aligned
259,263c256,258
<         0x65, 0x14,                     //   Unit (20)
<         0x05, 0x01,                     //   Usage Page (Generic Desktop)
<         0x09, 0x39,                     //   Usage (Hat switch)
<         0x81, 0x42,                     //   Input (variable,absolute,null_state)
<         0x05, 0x01,                     //   Usage Page (Generic Desktop)
---
>         0x81, 0x01,                     //   Input (Constant)  // padding
>
>     0x05, 0x01,                     //   Usage Page (Generic Desktop)
280,281c275,276
<         0x09, 0x36,                     //   Usage (Slider)
<         0x09, 0x36,                     //   Usage (Slider)
---
>         0x09, 0x33,               //   Usage (Rx)
>         0x09, 0x34,               //   Usage (Ry)
1273c1268
<         0,                                      // iInterface
---
>         4,                                      // iInterface

cores/teensy3/usb_desc.h
Code:
257,269c257,278
< #elif defined(USB_HID)
<   #define VENDOR_ID        0x16C0
<   #define PRODUCT_ID        0x0482
<   #define MANUFACTURER_NAME    {'T','e','e','n','s','y','d','u','i','n','o'}
<   #define MANUFACTURER_NAME_LEN    11
<   #define PRODUCT_NAME        {'K','e','y','b','o','a','r','d','/','M','o','u','s','e','/','J','o','y','s','t','i','c','k'}
<   #define PRODUCT_NAME_LEN    23
<   #define EP0_SIZE        64
<   #define NUM_ENDPOINTS         6
<   #define NUM_USB_BUFFERS    24
<   #define NUM_INTERFACE        5
<   #define SEREMU_INTERFACE      2    // Serial emulation
<   #define SEREMU_TX_ENDPOINT    1
---
> #elif defined(USB_HID)  // Joystick + SEREMU (no keyboard/mouse)
>   #define VENDOR_ID             0x16C0
>   #define PRODUCT_ID            0x0482
>   #define MANUFACTURER_NAME     {'T','e','e','n','s','y','d','u','i','n','o'}
>   #define MANUFACTURER_NAME_LEN 11
>   #define PRODUCT_NAME          {'J','o','y','s','t','i','c','k'}
>   #define PRODUCT_NAME_LEN      8
>
>   #define EP0_SIZE              64
>   #define NUM_INTERFACE         2          // Joystick + SEREMU
>   #define NUM_ENDPOINTS         3
>   #define NUM_USB_BUFFERS       20
>
>   // Joystick (your 6-axis descriptor stays as you edited it)
>   #define JOYSTICK_INTERFACE    0
>   #define JOYSTICK_ENDPOINT     1
>   #define JOYSTICK_SIZE         12
>   #define JOYSTICK_INTERVAL     1
>
>   // SEREMU (HID serial emulation) -> provides 'Serial' for Print.cpp
>   #define SEREMU_INTERFACE      1
>   #define SEREMU_TX_ENDPOINT    2
272c281
<   #define SEREMU_RX_ENDPOINT    2
---
>   #define SEREMU_RX_ENDPOINT    3
275,296c284,288
<   #define KEYBOARD_INTERFACE    0    // Keyboard
<   #define KEYBOARD_ENDPOINT     3
<   #define KEYBOARD_SIZE         8
<   #define KEYBOARD_INTERVAL     1
<   #define KEYMEDIA_INTERFACE    4    // Keyboard Media Keys
<   #define KEYMEDIA_ENDPOINT     6
<   #define KEYMEDIA_SIZE         8
<   #define KEYMEDIA_INTERVAL     4
<   #define MOUSE_INTERFACE       1    // Mouse
<   #define MOUSE_ENDPOINT        5
<   #define MOUSE_SIZE            8
<   #define MOUSE_INTERVAL        1
<   #define JOYSTICK_INTERFACE    3    // Joystick
<   #define JOYSTICK_ENDPOINT     4
<   #define JOYSTICK_SIZE         12    //  12 = normal, 64 = extreme joystick
<   #define JOYSTICK_INTERVAL     2
<   #define ENDPOINT1_CONFIG    ENDPOINT_TRANSMIT_ONLY
<   #define ENDPOINT2_CONFIG    ENDPOINT_RECEIVE_ONLY
<   #define ENDPOINT3_CONFIG    ENDPOINT_TRANSMIT_ONLY
<   #define ENDPOINT4_CONFIG    ENDPOINT_TRANSMIT_ONLY
<   #define ENDPOINT5_CONFIG    ENDPOINT_TRANSMIT_ONLY
<   #define ENDPOINT6_CONFIG    ENDPOINT_TRANSMIT_ONLY
---
>
>   // Endpoint configs
>   #define ENDPOINT1_CONFIG      ENDPOINT_TRANSMIT_ONLY   // joystick IN
>   #define ENDPOINT2_CONFIG      ENDPOINT_TRANSMIT_ONLY   // seremu IN
>   #define ENDPOINT3_CONFIG      ENDPOINT_RECEIVE_ONLY    // seremu OUT
737a730,770
>
> #elif defined(USB_MTPDISK_SERIAL)
>   #define VENDOR_ID             0x16C0
>   #define PRODUCT_ID    0x04D5
>   #define DEVICE_CLASS    0xEF
>   #define DEVICE_SUBCLASS 0x02
>   #define DEVICE_PROTOCOL 0x01
>   #define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
>   #define MANUFACTURER_NAME_LEN 11
>   #define PRODUCT_NAME    {'T','e','e','n','s','y',' ','M','T','P',' ','D','i','s','k'}
>   #define PRODUCT_NAME_LEN  15
>   #define EP0_SIZE              64
>
>   #define NUM_ENDPOINTS         6
>   #define NUM_USB_BUFFERS       20
>   #define NUM_INTERFACE         3
>
>   #define CDC_IAD_DESCRIPTOR    1
>   #define CDC_STATUS_INTERFACE  0
>   #define CDC_DATA_INTERFACE    1 // Serial
>   #define CDC_ACM_ENDPOINT      1
>   #define CDC_RX_ENDPOINT       2
>   #define CDC_TX_ENDPOINT       3
>   #define CDC_ACM_SIZE          16
>   #define CDC_RX_SIZE           64
>   #define CDC_TX_SIZE           64
>  
>   #define MTP_INTERFACE         2 // MTP Disk
>   #define MTP_TX_ENDPOINT       4
>   #define MTP_TX_SIZE           64
>   #define MTP_RX_ENDPOINT       5
>   #define MTP_RX_SIZE           64
>   #define MTP_EVENT_ENDPOINT    6
>   #define MTP_EVENT_SIZE        32
>   #define MTP_EVENT_INTERVAL    10
>   #define ENDPOINT1_CONFIG      ENDPOINT_TRANSMIT_ONLY
>   #define ENDPOINT2_CONFIG      ENDPOINT_RECEIVE_ONLY
>   #define ENDPOINT3_CONFIG      ENDPOINT_TRANSMIT_ONLY
>   #define ENDPOINT4_CONFIG      ENDPOINT_TRANSMIT_ONLY
>   #define ENDPOINT5_CONFIG      ENDPOINT_RECEIVE_ONLY
>   #define ENDPOINT6_CONFIG      ENDPOINT_TRANSMIT_ONLY
 
Back
Top