Problem adding axes

I am using this project to use my controller.

Now the computer sees the Arduino as 2 devices. One device has 128 buttons and 8 axes. The second one has 128 buttons and no axes. I would like to add an additional 8 axes to the second device.

In descriptors.c I added:
0x09, 0x01, /* Usage (Pointer) */

/* 8 axes, signed 16 bit resolution, the actualy resolution is still 10 bit range 0~65535  */
0xa1, 0x00,          /*   Collection (Physical)                            */
0x05, 0x01,          /*     Usage Page (Generic Desktop)                   */
0x09, 0x30,          /*     Usage (X)                                      */
0x09, 0x31,          /*     Usage (Y)                                      */
0x09, 0x32,          /*     Usage (Analog1)                                */
0x09, 0x33,          /*     Usage (Analog2)                                */
0x09, 0x34,          /*     Usage (Analog3)                                */
0x09, 0x35,          /*     Usage (Analog4)                                */
0x09, 0x36,          /*     Usage (Analog5)                                */
0x09, 0x37,          /*     Usage (Analog6)                                */
0x27, 0xff, 0xff, 0x00, 0x00,    /*     Logical Maximum (65535)                        */
0x47, 0xff, 0xff, 0x00, 0x00,    /*     Physical Maximum (65535)                        */
0x75, 16,            /*     Report Size (16)                               */
0x95, 8,             /*     Report Count (8)                               */
0x81, 0x82,          /*     Input (Data, Variable, Absolute, Volatile)     */
0xc0,                /*   End Collection                                   */

In Arduino-joystick.h in typedef struct Joystick2 int16_t axis[8];

typedef struct {
int16_t axis[8];
uint8_t button[16]; // each byte represent 8 button state
} USB_Joystick2Report_Data_t;

In the library I changed it define NUM_AXES 8 to define NUM_AXES 16
and
for (uint8_t ind=0; ind< NUM_AXES; ind++) {
joyReport.axis[ind] = analogRead(54+ind) << 6;

I tried manually running additional axes
joyReport.axis[0] = analogRead(A0) << 6;
joyReport.axis[1] = analogRead(A1) << 6;
but when I want to add 9 axes
joyReport.axis[8] = analogRead(A8) << 6;
They still do not respond to changes in the potentiometer. The only thing that changes is that the buttons turn on themselves. I've been looking for a solution to my problem for a long time, but I haven't found anything. Maybe someone could help me or tell me what else to do.

I hope I added this in the right section. Thank you in advance.

You should make a drawing of your project and post the sketch with a description of what you intended, and what you observe.

2 Likes

I don't know how to know ten sketches to depict well.
I use Arduino Mega and now Windows sees two devices from this code.
1 device: 8 axes( Analog inputs A0-A7) and 128 buttons.
2 device: 0 axes and 128 buttons.

I'm trying to do it
1 device: 8 axes (Analog inputs A0-A7) and 128 buttons.
2 device: 8 axes (Analog inputs A8-A15) and 128 buttons.

When I add axes as in the post above, the axes in the 2nd device do not respond to the movements of the potentiometer and buttons turn on for no reason.

Maybe the problem is in the library ?

typedef struct joyReport_t {
int16_t axis[NUM_AXES];
uint8_t button[(NUM_BUTTONS+7)/8]; // 8 buttons per byte
};

The USBjoystick project seems to have died or moved.

Now here...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.