AlanChatham / UnoJoy

UnoJoy! allows you to easily turn an Arduino Uno (or Mega or Leonardo) into a PS3-compatible USB game controller

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raising the amount of buttons on megajoy

Mikkelhost opened this issue · comments

Hi

Im trying to make som flightsim hardware as cheaply as possible. So i started using this, and it works great with 64 buttons. But when i edit the descriptor and everything to add more buttons. as an example im using 80 buttons for this project. The buttons 64-71 (8 buttons which is exactly 1 byte of buttons) doesnt work. i have looked through the descriptor and everything, and i can't find out why this 1 byte of buttons doesn't work.

20190101_230951
Here is a gif of what im talking about. I made the arduino cycle through the buttons from 0-79 and then repeat. As seen on the gif, every button works exept those 8 buttons.

I also tried one time changing the amount of buttons to 144, her there are 16 buttons that doesn't work. more specifically buttons 64-71 and 128-135. So it seems to behappening after every 8th byte.

I've fixed the problem. Found out that it was in the arduino ". h" file itself. Don't know why i hadn't looked there yet😅 but seems to have fixed the problem. Now i would just have to find out how i will be able to activate all buttons at once. Maybe you have an idea on how that is supposed to happen :-)

Best regards
Mikkel

Im not sure i understand quite what you mean. All i have tried is to let the arduino run through a sequence which turns all the buttons on. but it doesnt work :/

Hello there,
at the moment i plan on building a similar Project for my flightsim.
I am planning for ca. 52 digital inputs.
However, i would like to build it, so i can expand on it in the future.
My problem is, no matter what i do, Pointys Joysticktester only shows 2 devices with 32 buttons.
I veryfied this by trying to assain a button beyond that to a controll in the flightsim (DCS) and it doesn't recognize it either, so something isn't working.
I don't have that much experience in programming and i tried solving this problem for the last 3 days, so i thought that someone here could maybe help me.
What i did was changing the button array size in Megajoy.h and expanding the "for loop" to assain the new buttons in the array.
Can someone please give me a hint on what to try additionaly?
I am currently testing running on a 64bit Win10 computer.
Thank you and greetings!
(and sorry for my bad english speaking skills, i am working on them :) )

Hey Coach

add me on discord
Mikkelhost#1366

I got something that might help you out

@AlanChatham @Mikkelhost I was going to start a new issue thread, but I saw this one and based on what I see as the original post, I believe this ties directly to what I am trying to do. I'm trying to use UnoJoy to add a couple more buttons but I'm having a bit of difficulty. For starters, I've only tried to add 1 new button as a test to see what I get. I have download Atmel Studio 7, but I'll admit this is the first I've used it, so I'm not exactly sure what I could be missing.

For starters, I modified the UnoJoyArduinoSample and UnoJoy.h files and flashed them to my UNO. For my test, I decided to make pin A3 a digitalWrite, just like A4 and A5. After turning into a joystick, obviously nothing new happened because I didn't change any of the ATmega code. So........

Next, I modified the following files in the ATmega8u2Code folder...
usb_gamepad.h
uint8_t newTest_btn : 1;
usb_gamepad.c
.newTest_btn = 0 (added in the gamepad_idle_state function signature)
gamepad_state.newTest_btn = btnList.newTestOn; (in the sendPS3Data function)
UnoJoy.c
dataToSend.newTestOn = 1 & (buttonData3 >> 1);
dataForController_t.h
uint8_t newTestOn : 1; (right below the dpadDownOn line)
ButtonMapping.txt (I realize this is only a reference file)
physicalButtonList_t.h (this file didn't seem to be included in the solution, so after my first attempt which didn't work, I decided to include it, but got the same results)

After modifying and building successfully, I copied the output files into the ATmega8u2Code/HexFiles folder and turned into a joystick again. Unfortunately, I did not get a new button to show up in the controller tester. However, this time grounding the A3 pin did cause button 5 to turn on. I'm really unsure why it made that button turn on.

Is there some sort of constant I need to increase that defines the total number of buttons? I can include additional code snippets if I've been unclear on anything. I appreciate any help with this.

Are you using UnoJoy or MegaJoy? MegaJoy has a bunch of buttons, way more than the 13 that UnoJoy has, so if you haven't, give that a shot.
Otherwise, you're going to be entering the horrible world that is USB HID device programming, which is a real pain. If you're trying to add more buttons, you'll also need to update the HID report descriptor, and possibly some other HID stuff somewhere (I don't totally remember at this point, but doing a diff between the UnoJoy and MegaJoy files could help a lot there). You also might need to add 8 buttons at a time, since you may run into some issues packing bits into things here and there.
Importantly, between tests, you'll need to uninstall your controller from Windows, since the OS will cache the HID report descriptor between device plug-ins, so if you don't uninstall the device on the system level, it won't actually pay attention to the new HID device report you're trying to give it.

Hope this is helpful!

Thanks for such a quick reply! I found the issue though! It was in the gamepad_hid_report_desc constant. I saw that I had to increase the REPORT_COUNT and USAGE_MAXIMUM, but missed the fact that I then had to decrease the REPORT_COUNT for the next INPUT which was essentially the padding.

Also, I found the other issue that I had of the wrong button turning on from my pin. For that one, I simply had the order of my button names wrong in the typedef struct in my usb_gamepad.h file.

FYI....I'm using UnoJoy, not MegaJoy. The buttons that I'm adding, I'll be able to fit in using a matrix pattern with the number of pins that the UNO provides, plus I found a couple of UNOs for much cheaper than the Megas. I'm learning a ton with this in a very short while. Thanks for creating a cool project!

Glad things worked out! Just FYI, you should be able to use the MegaJoy! code on an Uno, giving you more buttons to play with.

Thanks! I'll give that a shot too.

Hello mr @Mikkelhost. I wanted to ask you about your project because I'm doing something similar, but couldn't find your Discord ID. Would you be so kind to contact me for some help? my ID is SrSosio#4606
Thank you

Hi @Assamita81 I abandoned my own project years ago.
So im no longer able to assist as i havn't looked into it since 😕

Hello @Assamita81, I used this project for awhile, but I ended up going a different direction. Feel free to take a look at what I did here...
https://github.com/briancavanaugh/RetroGameController

Thank you @briancavanaugh I'm pretty confident building button boxes with Leonardos and Pro Micros. In fact, my current project was designed originally for a Pro Micro. However, it has too many inputs and I run out of pins, that's why I'm exploring the Mega solution.
I tried port expanders like the PCF8575, but the only library I found for them to handle 8x8 matrix could not handle several buttons pressed at once, like the Keypad library does, and I'm not smart enough to program the code for a matrix myself.
@Mikkelhost my project is not really that complex. If you could let me know how did you wire your 80 buttons that'd be enough, I could try to figure out the rest from there. Did you use a matrix?

I believe that i ended up using a matrix yes, and then i used diodes to make sure that i could push multiple buttons at the same time.