How to Build a Button Box

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
gelda in this video I'm going to give you instructions on how to build your own Arduino button box for flight soms space Sims racing Sims whatever you might want a button box for they're already a bunch of other button box videos online but they're usually pretty inflexible like they'll give instructions on how to build a particular box with a bunch of switches and buttons and rotaries but they'll all have to be laid out in a very precise and exact format if you want that button box to work what I'm hoping to explain in this video is how to design build and code your own original button box to your own specifications you shouldn't need to know anything about coding or electronics to follow this video as much as possible I'm going to keep it simple enough for a complete beginner okay so first let's look at what components you can use for this video we're going to explain how to use momentary switches rotary encoders and potentiometers so what are all of those first momentary switches these are switches which flick on and then off again automatically like for the switch it's a momentary switch you can see it flicks on and then it flicks back off automatically as soon as I release my finger this button is also the kind of momentary switch because after I stop pressing it it clicks back into the off position you can also use a toggle switch like this one which you can see it locks into the on position but personally I find these a little bit annoying to deal with second we have rotary encoders these work by sending out digital pulses so each click in one direction counts as one button press and every click and the other direction it counts as a different button press rotary encoders come in a wide variety of types I'd really mean one like this which has lots of clicks and it can be turned and indefinitely finally we have potentiometers a potentiometer is basically like a dimmer switch on a light it can be tuned smoothly through 360 degrees you can also get versions that slide up and down like a fader on a mixing disc so what should you get well it depends totally on what you want your button box to do but I'll give you a couple of tips in most cases I'd recommend using a momentary switch or button rather than a toggle switch that's because a toggle will hold the button down so if you want to push that button twice you'll need to flip the switch or push the button twice which is usually just a waste of time second tip if you want some kind of rotary input I'd usually recommend a rotary encoder rather than a potentiometer potentiometers have a limited range of motion they're like an access on a joystick whereas most rotary encoders can be tuned indefinitely in either direction and that means they have a greater range of users because each click and either direction counts as a button press and they often have an additional push button function so effectively you get three buttons on a Component they're also a little bit better for fine adjustments so for example if you want one for tuning a radio you know always that one little click is going to mean one number up on tuning your radio now that said there are some reasons you might prefer a potentiometer for example if you want a really smooth action for an axis so like if you're building a rip like a throttle or a rip like a trim wheel for a flight sim or maybe you're designing a steering wheel for erasing some for those you'd probably prefer to use a potentiometer also one little trick with rotary encoders is that if you spin them too fast they sometimes won't register all of the clicks that they're being turned through so if you want something that you can turn really quickly to get to a certain position then you probably want a potentiometer instead there are ways to get around that with a rotary encoder but you need to do a bit more work on the electronic side you need to create something called a debounce circuit if you want to do that and just look it up online lookup debounce rotary encoder and there's tons of resources out there okay so the next step is to design your button box now I'd recommend just spend a bit of time with a pencil and paper just scribbling down different ideas of how you want your button box to work think about what kinds of switches or rotaries or other components you might want to link to different functions and your some think about how you want to lay them out on your box it's a good idea to do a final mock-up and free 3d modeling software like Sketchup because that'll give you a better feel for the ergonomics of your box so in my case I wanted one that would work for il-2 and dcs I already have a warthog hotus which comes with a bunch of different switches so I don't even any more of those toggle switches what I really want is some rotary knobs to control things like radiator and let's radar antenna trim plus a bunch of momentary buttons for things like weapon selection lights stuff like that I also want it to be sort of three-dimensional so I want some of the buttons on the top and and a couple of the rotary and functions on the front but I also want some on the side so that like this one for example I want to use this one from my elevator trim so when I turn it this way my trim makes me nose heavy and I turn it this way and my elevator trim goes nose light but look you don't want you and have to build it this way if you just want to make it on one big flat panel that's totally fine okay so that's the design stage done now we need to work out how we're going to wire up all our components to our Arduino so I'm going to use the arduino leonardo as an example but these same principles could equally be applied to a different kind of board like an you know or a pro micro now if you look at an Arduino you'll see a bunch of holes around the sides these are called pins some of them you'll see they have numbers these are digital pins which could be used to receive digital signals some of them will have a and vina number beside them these are analog pins which can be used for digital or analog signals and we'll come back to that in just a second there are also a few other kinds of pins but for the purposes of a button box you can ignore all of them aside from the ground and pen and the five volt output pen okay so now let's look at how to connect our components to these pens okay so for a normal momentary button or switch there will be two terminals you need to wire each terminal to a different pen to complete the circuit for most rotary encoders you will have five terminals two of them will control the push-button function and they just work like any other button you hook them up to two separate pens these are the three of further rotary functions the middle one gets hooked up to ground and these other two control the twist function and they both each get linked to a digital pen and you can also get rotary encoders which look like this but these have helpful labels which tell you what each terminal is for potentiometers have three terminals the left and right ones are connected to the five volt output and to the ground now the center terminal measures how far the dial is being turned now this terminal will send out an analog signal so you have to hook it up to one of the analog pins it won't work if you connect it to a digital pin okay so now let's set up our wiring system I recommend using some drawing software like or Photoshop you need something which lets you draw in multiple layers because by the time we've finished our diagram it is going to look like this so it's going to help you a lot if you can just show the layers for the wires you are interested in and just hide everything else but honestly if you just wanted to use a few sheets of paper and some colored pencils that would also work perfectly fine so our first layer is going to have the Arduino board plus a simplified layout of our components based on that 3d mock-up I drew earlier so these here are the buttons these are encoders and these are our potentiometers so now we start drawing all the wires which connect our switches and rotaries and potentiometers to our different pins um make sure you use a different layer for each wire and that you label them clearly and use a different color for each wire because that is going to make your life so much easier when you have to use this diagram to actually physically go and connect up all your different components and now we've run into a problem we haven't got enough pins to fit all our components so you'll notice every rotary encoder has a total of five pins every button has two pins and every potentiometer needs three pins so that's in total with all of these components that's way too many terminals for the number of pins we have on this board so what do we do well first we can save ourselves a lot of pins by using the same ground pin to connect to all our potentiometers and rotary encoders we just connect all those wires together then run them to the same pen and we can do the same for the five volt pen to our potentiometers now our potentiometers only use one pen for each output that's not a big deal we can just hook those up directly remember they need to go to an analog pin so for this example we'll use pens a4 and a5 but for our buttons and encode we still have way more terminals then we have the pens to connect them to and we can't just link them up in a big loop like we did with the ground wire and the 5 volt instead we need to create something called a button matrix and basically this is how every keyboard or like a keypad on alarm system works and what you do is you create a grid so every button is going to have one terminal connected to a horizontal row in the grid and the other terminal is going to be connected to a vertical column so for our example we are going to make a matrix which has three rows of buttons and four columns so this lets us include all our momentary buttons and the push button function for all five of our rotary encoders and you'll notice there's just one button missing here I just didn't need an extra button there so I'm leaving it out of this matrix so this saves us a huge number of pens on the arduino because we only need one pen for each column and each row so for our example our rows are going to be connected to pins 13 12 and 11 well our columns are connected to pins a 0 a 1 a 2 and a 3 so just to explain a bit more about how this works like when we push this button the Arduino is going to get a signal that says ah one of the four buttons connected to pin 13 has been pressed then it's going to get another signal that says one of the three buttons on pen a3 has been pressed and then it's going to ask itself well which button is connected to both a3 and 13 and well the only one is this button here so it's going to go well this button must be pushed so just a quick warning note this matrix will run into problems if you try to push a lot of buttons at the same time so like more than 2 or 3 buttons if you hold them down at the same time and your box will probably end up telling you that a whole lot of other buttons that you're not pressing up also being pushed and this is something called ghosting and you can get around it by some by wiring some blocking diodes into the matrix so if you want to do that if you want to push a whole lot of buttons at once and your button box just Google keypad ghosting and you'll find plenty of information about how to stop that but for my button box I'm only ever gonna push one button at a time so I'm just not going to worry about it okay so that's our buttons and potentiometers dealt with the last step as the two terminals on each rotary encoder which sends the signals for the twist function now unfortunately I can't include these in my button matrix so I'm just gonna wire each of them directly to the Arduino but luckily I now have enough space to connect them all now there are a couple of important things to remember when wiring rotary encoders just using the code that we're going to show you later on first with the code we're using they must be connected to the lowest numbered pens and sequence so you have to wire the first encoder to pin 0 and to pin one the second one needs to be to a pen two and pen 3 and so on second they need to be connected in pairs so if you try to connect the first encoder two pins 0 and 2 and the second one to pins 1 & 3 it won't work I really recommend getting some colored wires and using a different color of wire to connect each rotary encoder just make just so that you don't accidentally mix them up when you're trying to connect them okay so now you have a plan you can go and actually buy the stuff you need to make this thing obviously you'll need your buttons and your encoders and your Arduino and you also need some wire I recommend getting a pack of multicolored wire like this so that you can match the color of the wire in your wiring diagram to the actual physical wires that you're connecting it just makes things much less confusing when you're actually doing this if you're using an Arduino Leonardo or an Arduino Uno you will also need some jumper cables like these which plug into the pins again get a bunch of different colors to match your wiring diagram you'll also need an enclosure and just make sure it's big enough because for my project I ended up wiring up everything and then discovered that my box was way too small to fit in all of my components and wires so I had to tear the whole thing apart and start from scratch um you'll also need some solder and for a project like this you want quite fine solder like this you'll also need a soldering iron you don't need anything expensive this one cost fifteen New Zealand dollars and it's powered by a USB port and it worked perfectly fine also you might want to buy a pair of wire strippers and I actually just used a pair of nail clippers to save myself a few bucks and they're mostly worked okay um you could also give a what of one of these things which is called helping hands for the magnifying glass not essential it might make life a little bit easier at the very least do make sure you have a pair of vise grips or pliers to hold your components still while you're soldering them okay so the next step is to build your button box and this is gonna be different for every project so I'm not gonna walk you through each step basically you just need to connect all your components up the same way you have mapped out in your wiring diagram I will give a few tips when it comes to soul during it's worth watching a few videos on technique and practicing with some bits of spear wire before you actually start work on your project just to make sure you really feel confident you feel like you know what you're doing when you're connecting up your button matrix only use the shortest length of why you need to to get from one component to the next because if you don't your box will end up as a horrific confusing tangle of wire like-minded on my first attempt and that means that if something breaks it becomes really hard to find what's broken and then to you know fiddle in your soul during iron your solder to solder it back together again on a similar note I'm usually quite helpful to use a bit of electrical tape or blue tech just to keep things organized so for example like I tape together all my row wires separately from my column wires and then I taped up my potentiometer wires and my rotary encoding wires and that just means that when I was ready to plug those wires into my Arduino it was much easier to figure out which wire belong to which pen also just don't get too frustrated if everything goes wrong like personally I had to start from scratch three times before I got my button box working you just got to stick to it and eventually I promise you'll figure it out okay so your button box is all wired up and now you are ready to start coding now for this you will need to download the arduino ide software so get that installed i've included a link below then you need to download the keypad and joystick libraries and there are links to both of those in the description copy and paste those libraries into the directory you and then open IDE Oh before I forget credit to AE studio for a lot of this code all I have to really done is modify his work to make it a bit easier to follow and also to make potentiometers work with it so check out his videos get them alike and definitely check out as other videos cuz he has lots of instructional videos on how to make button boxes and all sorts of awesome things so now we've wired everything up we've built our button box and now we are ready to start coding the code which we're looking at here you can find in the description of this video all you need to do is just download it and copy and paste it into a new project here so let's see what we're looking at and look I know this all looks very complicated and I'm not going to ask you to actually understand any of it I don't understand a bit of it myself I had to get help from my partner who is a proper software developer to make it all work I'm only just going to explain what you need to change to make your own button box work okay so first it starts pretty simple we just need to tell our computer what to expect from our button box what functions we expect it to have so first of all how many rotaries do we have well we can go back to our circuit diagram and check so we have 1 2 3 4 5 rotary encoders so we go back here change this to 5 next number of buttons how many buttons do we have again go back here we have 1 2 3 4 5 6 and we also have the push button functions on each of these so that's 7 8 9 10 11 go back to our code change this to 11 the next two we need to know how many how many rows and columns we have in our button matrix so again go back to the diagram we have 1 2 3 rows 1 2 3 4 columns come back here we have 3 rows four columns cool so now I move on to the bit of the code which deals with the button matrix so if you look here this is basically sort of like imagine this is a layout of our button matrix it has rows and it has columns so the first thing we need to do is change this to match what our matrix looks like so you'll see here that there are 4 rows and 4 columns now if we had say like a 5x5 matrix so this is a four by four matrix if we had a five by five matrix we just have to change this so we had one extra number here and add to add up to having five columns so then you go there you go there and we need one extra row and you'll notice here we have one comma behind beside each line of code except for the last one that's important you just got to make sure that it always looks like that there's always one comma beside each line of code except for the last one in this part but we don't have a five by five matrix we have a 3 by 4 matrix so we need only 3 rows and 4 columns so we can just get rid of this get rid of this and remember here get rid of this last comma the next step here is to change all of these question marks and to a number and we start from 0 so we go 0 1 2 3 cool so there we go we have our button matrix all set up good to go the Knicks but we have to deal with is our rotary encoders and so basically what we've got here is each line of code here refers to a different encoder so we've got 1 2 3 4 5 so the first two numbers refer to which pen the rotary encoder is connected to so you remember each rotary encoder has two pins controlling the twist function and this is telling us which two pins are controlling those things so we go again we go back to our code here and this is why we're using layers here so we can make it easy to spot what's what we have a look in here and we can see our first encoder it's connected to pins 0 and 1 so again we come back here and look at our code 0 and 1 and we have to with this code we have to start with 0 and 1 next two numbers are telling us which buttons will be pressed when we turn in each direction so if I just bring up my my game controller properties here you can see that if I'm twisting one of my potentiometers at one of my rotary encoders it's pushing a button for every little click that it goes through and this is telling it which button to press now it's not exact because we start again we start counting from zero so we only go up to 32 but 31 because we start counting from zero and by the way you cannot have more than 32 buttons on a joystick controller you'll see here only goes up to 32 so that means that you cannot exceed 31 as your final rotary encoder button so just make sure you don't do that and so say if we had one more rotary encoder say in your project you want six rotary encoders then you would copy this here put it below oops put it below and then we would check which pins we were connected to so let's just pretend we had another one that was connected to pins 10 and 11 so we come in here we say 10 and 11 and if we did want to do this we would have to leave this at 30 and 31 we'd have to change this back so this one become 29 28 27 26 and so on but we're not going to do that we only have five rotary encoders and again if you had less than five you just delete a line of code here and then you'd delete the comma here so you're all done cool next step moving along cool so this is the second part of the button matrix we need to tell it which pins our rows are connected to and which pins our columns are connected to so we do that by going again back to our schematic here we show our button matrix wires and we can check and we can see here that our rows are connected to pins 13 12 and 11 well our columns are connected to a 0 a 1 a 2 a 3 and we'd come through here and change those so I've already done this so it's 13 12 11 0 a 1 a 2 a 3 but obviously you can have your project connected to different two different things for example maybe you had an extra row maybe you had another row that's connected to 2 Penton so you're just a dent in there cool the next step is our joystick settings so this is telling our computer how many different functions our joystick hairs so the first function is the number of buttons we've sit there 232 which again is the most number of buttons that you can have you can see this lower if you want to personally I don't see any but there's no particular the problem just putting it on 32 you can just have buttons that buttons and and this grid here that you wouldn't even be able to press but that doesn't really matter then you have hat switches I'm not going to explain how to do hats which is in this video because to be honest I don't know I imagine it's relatively straightforward and the next step here has to do without potentiometers so these are all the different axes which our button box can have and you'll see this quite a lot of them if I just open up I've got a I've got my hota at my on Warthog connected here or Sochi I'll do my joystick so if I open this up you'll see that there's a few different axes here like I've got this little slider this is an X YZ my joystick XS and then I've got a rotation which is the rudder function here and you can do the same thing for your Arduino for your button box so for mine I have two potentiometers just by the way these first two the y-axis and the x-axis they control if I go back here for a second they control this thing here so that you can see its X and y-axis so X across Y up and down and then you also have these just two-dimensional ones which just go across and those are all of the rest of the different axes that you can have in this code here so I'm not going to use the X&Y axis because I've just got some knobs and I don't want them to to control something in sort of like a pointer in a box and I just want them to go left and right so instead I'm going to use the Z and our X axes for my two potentiometers so I just change each of these to true to tell them that those axes are there and you can see it as many of these as you want to true but it'll only pick up the ones that have got potentiometers connected to them cool so we've come down to the next potentiometer next part of the potentiometer code actually for this purpose let's pretend I have a third potentiometer I don't really but I'm going to pretend I do for the purpose of this example so I'm going to pretend I have a third potentiometer and I want to bind it to the R xx to the our y-axis so if you come down here to part one you'll see that we've already got the z-axis set up the our x-axis set up so all we need to do for our imaginary third potentiometer is a drop and placeless but change it to our y-axis that's us done their next step here is we need to tell our code which pins our potentiometers are connected to so we'll go back to our diagram here again we will show our potentiometer cables hide everything else and we'll see here that our potentiometers are connected to pins a 5 and a 4 and we'll pretend our imaginary potentiometer is connected to pin a 3 so come back to our code we'll see here between chiama to pin 1 is a 4 potentiometer pin 2 is a five and let's pretend we have our third potentiometer or copy and paste this here potentiometer pen three need to change this of course you could have a four five six seven and then we'll tell it which pen that imaginary third potentiometer is connected to and it is going to be connected to pen a three cool that's that done so we scroll down a little bit further here this I'm not going to explain what all this stuff does but basically again it's just copying and pasting this and changing it to match what you have from above so I'm going to copy and paste this here so I go through and change everything to match what I have above so I know that this is our third potentiometer so it's potentiometer pin three which you remember from earlier here potentiometer pin three and it's and it is connected to the our y-axis so we just need to go through here and change everything to our y-axis cool and that's literally it so it's it's really just a little bit of copying and pasting and changing things around to match whatever is in your circuit diagram here the final step that you have to take is to export this code but first I'll just show you this last function which is verify so this is just a check that your code doesn't have any obvious problems with it so you click this and it goes compiling sketch takes a little while sometimes done compiling no problems but say I had forgotten to take off this semicolon here then I would verify and oh it spotted a problem it's expecting something before current output level and what it's expecting is a semicolon so that's just to help you a little bit find stuff that's that's gone wrong you can if you like the best way to figure out what you've done if something happens is to just go back and compare your code to the original code that's in the description to the video and just make sure there's not little things missing like make sure that for example you might have forgotten to change this from our X to our Y or something a little like that it won't always pick it up if you do the verify thing that something's wrong so you do just have to hunt through and figure out what's wrong the final step is to actually upload this code to your button box so to do that you plug in your button box and to the USB port you go to tools you check which board you have so I have an arduino leonardo so i click that you check which port it is connected to and it should tell you so here it says comm 14 arduino leonardo so i click that one and then you click upload and from there your button box should be working the final step that you have to take is go ahead and test it so you open up your game controllers click on it at properties fiddle with your knobs push all the buttons and the final thing you have to do is calibrate like say if this was uploaded for the first time it might be yeah you can see here actually I haven't calibrated this properly so that's not moving smoothly and this one this one's moving properly but what you got to do is go to calibrate so you hit next next and then move your things all the way up and down don't worry about what it looks like and this little thing here it is working then you go next do you next potentiometer turn it up and down next finish and we see there these are working perfectly and finally before you finish make sure you check each one of your buttons make sure that all of them are working make sure that when your rotary encoders are turning that they're being picked up because you may need to go in and fix some loose connection and things like that I definitely had to do that a few times before I got this working and it helps actually when you have this code in here because it'll tell you which buttons aren't working and that makes it a lot simpler to find where you've soldered something wrong so yeah I hope that was really helpful I hope you can get your own button box working yeah Cheers bye now
Info
Channel: Wim
Views: 109,182
Rating: undefined out of 5
Keywords:
Id: wkY1NsbWj5I
Channel Id: undefined
Length: 34min 21sec (2061 seconds)
Published: Sat Jul 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.