Wiring Diagram for sim racing Button Box

This is somewhat of a cross post from SimHub. I hope that’s okay here as this is my first post and first time using an arduino.

I recently purchased quite a few electronics from AliExpress to build a button box for my sim racing rig but I am having a hard time, however, making sense of the wiring. The button box I'm trying to build is based on this one and will have 15 2-post buttons, 1 NO/NC/C button, 7 2-way 3-post toggle switches and 7 rotary encoders that have CLK, DT, SW, + and GND pins.

I currently have it all assembled and wanted to start wiring before getting into the coding side of things. I tried using the Simhub arduino sketch setup as that is what the original creator of this button box did. It basically asks you what hardware you’re using and creates a pinout for your chosen microcontroller to give you a better idea of how to wire your hardware. So I emulated what he did to a degree (see picture below that includes picture of arduino mega pinouts) using 7 rotary encoders, 6 'additional buttons' and a separate button matrix of 5 columns and 4 rows. I'm hoping someone might be willing to check my work based on the pinout pictures and the wiring diagram I (sloppily) put together in the picture below. My apologies for not embedding, because I’m a new user, the forum will not let me.

Imgur album of button box, arduino pinout, and wiring diagram

I greatly appreciate any help or input to assist me getting through this project. I don’t know if anyone here can help since I’m using a third-party tool but I’m hoping that won’t matter for this project. It is definitely above my knowledge level at the moment so I'm hoping to learn more so I can do more projects like this moving forward while knowing what I'm doing!

EDIT: Uploaded picture of pinout and wiring diagram to post.
EDT2: Uploaded hand-drawn (hopefully) cleaner wiring diagram.
EDIT3: Reverted picture in original post to help thread narrative.

Take a look at this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

Then You might get replies.

Hello Railroader!

Thanks for the link! I read through the guide and the only things I can think of that I haven’t done are post links to the hardware data sheet/purchase page (which I can’t do because I’m a new account) or I possibly posted in the wrong category.

Would you mind advising me as to how to improve my question so that I might get some help? I’m more than happy to provide any needed information or do anything else to make it easier to help me!

Thank you! :smiley:

Do not post links to your diagrams and code in third party sites. Post them like you were told to when you read that link.

I’m only able to post a single piece of media in my post since my account is new and the pinout and wiring diagram is 3 in total.

Let me try to stitch the pictures together and I’ll reupload.

EDIT: Spliced them all together in MS Paint and uploaded image.

Sorry that is not what you have uploaded.
We need a schematic not a photograph with lines on it. Quite frankly that is worse than useless at being able to see what you have.

Please read this

Thanks for the link.
I just tried to draw out the diagram as best I could on a piece of notebook paper and updated the original post with it. It's still a little confusing based on the layout of the switches and buttons but hopefully it is a bit more organized and easy to read.

EDIT: Uploaded drawn diagram to this post instead of original.

You should not do that because it makes all the requests for a diagram look silly and spoils the narrative of the thread. This action is described in the house rules you have been pointed at.

Second I can't see the link in the first post.

I reverted the picture in the first post to the original and posted the drawn diagram in my previous post.

Which link is not working for you? The thingiverse or the imgur link? Both seem to be working fine for me.

I really don't think you have got the hang of schematics.
There are no rotary encoders shown anywhere, but they are in your photograph. Where do these connect to your processor? Seven rotary encoders are going to be hard to read. What type are they? Are they smooth or do they click as you rotate them?

Also where did you get the schematic of the buttons? With the way you have it you can only ever detect a single button press. If two buttons are held down at the same time, or two of the toggle switches are in the made position, it will appear that four buttons are being held down. To fix that you need a diode in series with each switch.

Also there is no indication on you schematic of how the various pins are going to be programmed, that is which are inputs and which are outputs. This is important to know because it determines what way round to fit the missing diodes.

I don’t really have the hang of anything to be quite honest. I tried to mention it in my first post but this is the first time I’ve worked with an arduino and the first time I’ve worked with small electrical components. Most of my background is in building keyboards from pre-packaged components and flashing gaming systems and phones. I’m a bit of a fish out of water in this area but I am relatively capable and I’m genuinely trying to learn.

I didn’t include the rotaries because the pinout made it seem quite straightforward in terms of wiring. I also didn’t initially include them in the button matrix but I’m starting to think about wiring the SW pins for each in the matrix based on some feedback from other forums. They do click as they turn.

The pinout was generated by a software called simhub which is a sim-racing-focused software that allows you to plug in the hardware you want to use (whatever switches, rotaries, etc) and it will give you a pinout to use and a file to flash your chosen arduino.

Most of what is done in sim racing button boxes, from what I’ve read, is button matrices which would cause exactly what you mentioned - only one button being able to be used at once. I’m okay with that for the majority of the buttons but wanted the button at the top and the top row of 5 buttons to be pushed together. I tried to make that work in the wiring diagram I drew out but I’m not sure if that would work. I wasn’t planning on using diodes both because I don’t have any but also because I don’t fully understand how they work or what the implication would be in coding - which I don’t know anything about yet.

As for the pins on the individual switches and buttons - they aren’t marked. I even tried pulling the data sheet and they aren’t marked. For the 2-position switches, I came to understand that the middle is ground and the pins on the top and bottom are the positions. For the push buttons, I figured one would simply be input and the other would be ground. I’m probably wrong about that, but that’s how I’ve seen many other button boxes wired with two-post push switches like the ones I have.

I’m sorry, I don’t mean to be an inconvenience by not knowing much but I’m genuinely trying to understand so I can accomplish this project and have the know-how to finish some upcoming projects I have. I don’t mean to be difficult, I am just new to this and a lot of it is slightly over my head so I often need time to research after reading responses so I can understand what’s going on. Hope that makes sense.

EDIT: Forgot to mention this portion. I’m now running into the issue of the arduino mega not being able to be used as an HID. Because of that, I’ve explored the MegaJoy project and successfully flashed my mega, however I don’t believe I will still have the functionality of using toggle switches and rotaries. Not sure if you have any experience or input into megajoy but that would be greatly helpful as well.

Can you post that file here please as a zip file.

I think you have a lot to learn, as I am sure you will admit.

First off the rotary encoders. You can't simply supply 5V to them and then attach the switch output to a matrix, because that will stop the matrix from scanning. If you connect the 5V line to the scanning matrix then the encoder will be powered down most of the time and you will not be able to read the clicks. When the rotary encoder clicks the two signals from the output go through a sequence of changes very quickly and end up at the same state. Unless you are polling these switches rapidly or you get them to generate an interrupt from them you will miss these changes. There are two different change sequences on these pins, with one sequence indicating a clockwise click and the other indicating an anti-clockwise click.
Check this out

Next I think you should learn how a scanning switch matrix works

All your switches can be incorporated into one matrix there is no need to split them up into separate ones. You are going to need diodes on each switch because the toggle switches you want to use will act as a button permanently held down when switched In one direction.

No never come across that a link to it would help. But if it is anything like the way you can put an HDI interface onto an Arduino it might be more trouble than it is worth. It might be better to swap to an Arduino that can be used as a USB HID out of the box, like a Leonardo or a Micro.

I am always suspicious about auto generated stuff like this, because it can lead you to making all sorts of mistakes that you won't be aware of, as you have found.
As it stands I can't see your current circuit working at all, but I am sure we can come up with something that will.

Hey Mike, sorry for going silent. Last couple days of work have been a lot to handle.

Thanks for the links to the encoders and matrix write-ups. I haven't been able to read them fully yet but I've skimmed most of both and they make much more sense now. I'm now realizing that the idea of incorporating the push button function of the encoders (which was suggested to me by two people on separate forums) was somewhat foolish. Didn't think about it initially but it wouldn't even be possible to wire into a matrix without eliminating the rotation function.

Here's the file that SimHub gives you after configuring the arduino. It's a whole lot of .h files and a .ino file called DisplayClientV2. I'm sure the code reflects the specific hardware I plugged into the configuration tool.
DisplayClientV2.zip (55.1 KB)

I actually got a hold of the original creator of the button box and he told me he made the mistake of using the Mega since it is not HID-compatible. Because of that, his only option was to use it as a Simhub button box where the simhub software detects the input, assigned a keyboard key to it, and then you can bind the keyboard keys to functions in the game (Assetto Corsa in this case). This isn't ideal because for some reason, the permanent keybinds that require modifiers (i.e. CTRL+whatever key) won't work through those means. Also, the toggle switches won't work properly as for some reason, you have to flip them up and down 2-3 times for Simhub to recognize the input.

Because of all that, I finally put some attention into the Megajoy/Unojoy project which is a pretty straightforward process to make a Uno or Mega a simple HID device that can handle up to 64 simple buttons and a few axis. Originally meant for arcade-like joystick and button clusters. It involves uploading a file in the IDE, then putting the arduino into DFU mode and flashing it with the included .bat file.

I think my best option at this point is to go with the megajoy method and replace my encoders with simple push buttons. I'll likely buy a pro micro in a few months to make a smaller button box which can handle a few encoders and toggle switches.

They also make a lot more sense when you read them thoroughly a few times. :slight_smile:

Thanks, it is what I feared a load of functions that to trail through would take a lot more time than to write it properly. Especially if you need to integrate something like a rotary encoder. I looked at that section of your code and that is not to correct way to implement a rotary encoder. You don't need to debounce the encoder switches, you need to make the state machine you follow a self correcting path through it. And it should be interrupt driven not polled.

If you say so. On first read it looked a bit complex to me.

But good luck with that.
Cheers
Mike

Thanks for all your help Mike! Sorry for being a tough person to help at times but I appreciate your patience! Hopefully I won’t have to return for help when I build the pro micro boxes but if I do, I’ll be posting here again! :joy:

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