Arduino Pills – Setting up IDE and Libraries

Another quick pill about Arduino, this is about setting up the IDE and manage libraries.

Arduino IDE (Integrated Development Environment) is not as advanced as other solutions but it’s quite light and easy to use. It can be found here.

Once installed, you might want to change the default sketchbook location by opening FilePreferences.
Now download, save and open a source file, for instance the one we are using in the Step by Step guide (it can be found here on AM-STUDIO’s GitHub) then compile it. You will get a number of errors, let’s review them.

Libraries

Libraries are, simply put, a collection of methods and functions that tell the board how to perform certain tasks. The default package contains only a little fraction of the available libraries, not to mention the fact that you can write your own. The “Joystick” library, that our project requires, does not come by default so we have to install it in a specific location. That location is the “libraries” subfolder of the aforementioned default sketchbook location.

arduino-pills-2-libraries
“libraries” subfolder location

Let’s download the Joystick library from GitHub and install it.
Careful though to respect the order of the subfolders: the ZIP file comes with a folder called “ArduinoJoystickLibrary-master”; if you copy this folder in your libraries your project won’t compile. So:

  1. open the ZIP file;
  2. open the “ArduinoJoystickLibrary-master” folder;
  3. copy the “Joystick” folder;
  4. Paste it into your Arduino “libraries” folder.

A couple of friends had to install the “keypad” folder as well. This library can be installed in a different and faster way. Go to SketchInclude LibraryManage Libraries and look for “keypad”. Scroll until you find the library I have selected in the following screenshot and install it.

arduino-pills-2-keypad-library
Installation of the Keypad library

Lord of the boards

Last step is selecting the correct board and the relative port. Depending on which board you have bought, select either “Arduino Leonardo” or “Arduino/Genuino Micro” from the ToolsBoard: “xyz”. Then, in a similar way, select the correct port from the “Port” menu: ToolsPort: “xyz”.
Both entries report the last option selected.

Quick troubleshooting

Always try to isolate the issue. Since we are using a source code that definitely work you should fairly easily found the issue, at this stage is either a library problem or missing or a connectivy issue. The IDE suggests you where the problem is. The following, for instance, is caused by the selection of an incorrect Port.

arduino-pills-2-error
Arduino uploading error: wrong port selected

Advertisements

Arduino Control Box: a Step by Step Guide – Part 6 – Release the Solderer!

“Solderer” – Is that even English? Not sure.. I’ve just seen the release trailer for the Kraken in Star Citizen and I got carried away..


Anyway, part 5 ended with every component allocated and screwed in its location. Now it’s time to replicate the wiring diagram into reality.

SbS_6-soldering-control-column

Soldering the wires is not difficult at all, it’s just a matter of practice. Here are a couple advices that might help you:

  • Don’t overheat! don’t leave the soldering iron in contact with wires and components for too long. You can melt the plastics of both the components and the wires.
  • Leave the Arduino board for last. Especially if you are not used to solder, it might happen to drop drops of melted solder wire. If one of them falls on the board, it might cause severe damages to it.
  • Place the wires first. Most of the components have a small hole on their pins. You can usually place your wire there before soldering it.
  • Pre-solder wires and contacts of any component that haven’t the aforementioned hole. By doing that you will need to hold your wire with one hand, the soldering iron with the other and that’s it: the solder material is already in place.
    To pre-solder just place the iron and the solder in contact with the uncovered core of a wire. You will notice that it will be quickly covered by the solder; making your life much, much easier.
  • Clean your soldering iron every now and then. Solder and antioxidant might accumulate on the iron after a while (they usually form a black mass). Hold the soldering iron tight with your hand, make sure there’s nothing in the area underlying the iron and hit your table with your fist: the burnt material will drop from the soldering iron. Nice and easy.
  • Save your furniture! Melted solder and the iron itself are hot, easily more than 300+ deg C. Although the solder becomes cold in milliseconds, it can still damage your furniture. Place some cardboard or do your soldering on an appropriate surface. You will thank me when your wife won’t kill you for damaging her precious table 😉
  • If you have to connect a wire where another one is already soldered, add some solder and pre-solder the new wire. The new material will help spreading the heat.
  • Same as the previous point, if you do a mistake and can’t remove a soldered wire, add some solder: it may sound unintuitive but it helps spreading the heat uniformly.

That being said, this phase is quite straightforward as long as you follow a plan. I usually follow the same order I adopt when designing the wiring diagram; therefore I start from the wire that comes from the top pin of the board (although the board is always my last step) then proceed with every common connection such as GND. When the matrix is completed I then solder the encoders.

SbS_6-soldering-ufc

After completing the soldering of the circuit we can proceed and perform a quick test the continuity of GND, lines and buses by means of a multimeter. Do this check before connecting the board to the USB. The board is protected and we are working with low tensions but you know, better safe than sorry.
If the test doesn’t show any issue we can plug the board, load up Arduino IDE and write our firmware.

Arduino Control Box: a Step by Step Guide – Part 5 – Drilling time!

Part V of the guide, we’re almost there: the wiring diagram is ready, we have our buttons and encoders and we have our box. Before starting the assembling phase, let’s review some of the tools that might come handy.

Drill driver: I have an old DeWalt cordless drill driver, it holds drill bits max Ø10mm. It does the job.
Drill bits: I used to build model for WH40k years ago and I have a 1-5mm set. I have bought another cheap set, max Ø10mm. I recommend two sizes: a small one, to prepare a guide for wider holes (2-3mm will do, whatever you have in your garage). Most of the smaller buttons I have found have a diameter of 5-6mm so a second drill bit of that size will come handy.
Cone drill bits: I have bought a cheap set only recently and damn, they make your life so much easier. Since we will be working mostly with plastic, even quite cheap sets work like a charm.
Countersink drill bit: optional. Before buying the Cone bits I used this tool to make holes wide enough to host some particularly wide buttons. It comes handy when dealing with unusual diameters or to “clean” the hole instead of using sandpaper.
Caliper: the real man best friend 🙂 Simply a must have; you need one.
Thin permanent marker: you can decided to either mark the points to drill with a marker or cut them into the plastic. It’s up to you, I personally do both.
Multimeter: a must have for debugging the wiring. Unless you have done everything perfectly and I bow to you 🙂

Mirror mirror

IMPORTANT! We will drill on the internal part of the enclosure. Therefore, when planning and defining the position of the holes, remember that our wiring diagram is the specular image of what we actually need.
The easiest solution is to paste the image in GIMP and flip it.

Marking time

Get the wiring diagram on your PC and calculate the distances between the borders or the box and the centre of the buttons. I’ve found that drawing a reference matrix is actually easier. If you are using LibreOffice Draw, this operation will take just a few minutes and will be also very precise if you have draw your components and the box in 1:1 scale.

Now get the cover of the enclosure and the calipre. Measure the distances between the borders of the box, both vertically and horizontally and mark the points where your components will be placed with the marker. Proceed until every button of your UFC has is respective dot on the cover. For sake of clarity and to avoid confusion, you can write the expected diameter of every hole near every reference dot.

This is a detail of my Auxiliary Box. As you can see, the marks and cuts are clearly visible inside the enclosure cover (green arrows).

SbS_5-enclosure-cover-cuts
Reference marks and cuts inside the enclosure cover

Once every reference is marked, it’s time to start drilling. I usually start with a drill bit of very small diameter, then enlarge it depending on the final diameter required. This is a fairly quick operation, assuming every button is Ø12mm, you can start with the 2mm drill, check that the hole is exactly where you want it then use any other drill to make the hole wider enough to use the Cone drill bit. The Cone drill bit cuts throught the plastic very easily so pay attention and avoid making an excessively large hole.

When everything is done, get your buttons and encoders, place them in their slots and clamp screws and nuts and check the result.
SbS_5-bolts-and-nuts
Don’t put the encoders knobs in place, you risk unnecessary scratches.

Some buttons won’t be perfectly aligned but remember we are not using a CNC or any very precise tool. Small errors and imperfections might occur.

The manual part is almost over. Next step is soldering and then, finally, my favourite part: coding!

PS: it may sounds taken for granted but remeber to drill a hole for the USB cable 🙂

Arduino Control Box: a Step by Step Guide – Part 4 – Wiring Diagram II

I have decided to split the chapter about the Wiring Diagram to ease the reading of the guide.

Wiring Diagram

IMPORTANT NOTE: there’s an almost infinite amount of ways to wire a button matrix, mine is just one of them. I usually start from the top pin then proceed vertically. If you prefer any other order, go for it!
less important note: the order of the buttons might be a bit wonky, unless amended via code. I personally don’t care at all about it: we will assign controls in DCS by pressing a button, not by selecting it from a combo box or something like that.

SbS_4-diagram-wiring-full

Too messy? Let’s clean the diagram and analyse it step by step.
I usually separate the wires into vertical and horizontal. The fact that I start from the vertical wires is clearly reflected on the wiring diagram.


The task of the horizontal wires – I usually refer to them as buses; whereas I call the vertical as lines – is to link the vertical wires and intuitively you can understand why their path is much more complex. In other words, each bus has to “touch” every line, one per colour and only once, with just one noticeable exception.

A 3-way Conundrum

A 3-way switch has three pins. How come? If you google 3-way switch diagram (←sorry) you find plenty of explanations from the electrical point of view. From the button matrix PoV instead, a 3-way switch is a combination of two buttons. The common pin is normally the middle one and it should be wired to a bus, whereas the top and bottom pins should be wired to two different lines.
When the bus is wired to the middle pin it is de facto connecting two different lines in one go: the switch basically counts as two; that’s why the red, blue and yellow buses connect a total of four physical switches, whereas the grey and the green connect five buttons.

Still having issue? Take a look at this pic:
SbS_4-diagram-wiring-3-way
In this application, there is no difference between a single 3-way momentary switch and the two pushbuttons. This image also makes even more clear how a single bus manages to connect two lines.
We can, therefore, replace the 3×3-way switches with 6x pushbuttons:

SbS_4-diagram-wiring-3-way-swap
6x pushbuttons as 3×3-way momentary switches

Encoders: the Easy Part

Encoders are the easiest part. They come with 3 pins (as we have already seen, the two separated pins are the pushbutton): mid is the GND, the others two go in the order you prefer, straight to the the Arduino board.

SbS_4-diagram-wiring-encoders
Wiring Diagram – Encoders

Any GND pin can be used, so pick the one that makes your life easier 🙂

If everything is clear – drop a message here or ED’s forum otherwise – we can move on and start the dirty, manual part: drilling and soldering.

Arduino Pills – Change USB HID names

When multiple control boxes are connected they all come with the same name. In theory that’s not a big issue but I have noticed that DCS sometimes messes up. There must be a way to fix this situation, isn’t it?

A-firm, the solutions is quite simple: we just need to change a couple lines in the boards.txt file, then recompile and write the code.

My Kingdom for a Board!

boards.txt is a sneaky file though because it’s located in multiple folders. The one we are aiming for (and it should work for you as well) is located in AppData.

As of now, the path is:
C:\Users\USERNAME\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21
If the path doesn’t exist start from AppData and walk your wait down to boards.txt.

arduino-pills-vid_pid
boards.txt Path

Open boards.txt and locate this three fields:

leonardo.build.vid
leonardo.build.pid
leonardo.build.usb_product

These are the values we want to change. These, for instance, are mine:

arduino-pills-1-boardstxt
vid, pid and product from boards.txt

If you are using a Genuino Micro instead of Arduino Leonardo (it’s still based on the ATmega32u4), the values you need to change are different. These are from my Radio box, for instance:

micro.build.vid=0x1212
micro.build.pid=0x3434
micro.build.usb_product="K Radio Panel"

If you are wondering where I got my VID and PID values well, I’ve blatantly invented them. IIRC for commercial applications you should buy them; I guess they work as the MAC address. It’s not a problem for us since we are working on simple, personal, project.

Arduino Control Box: a Step by Step Guide – Part 3 – Wiring Diagram I

4 Encoders, 25 buttons. What to do with them? Considering how popular the F/A-18 is, an option can be a sort of minimalistic version of the UFC.

ufc
F/A-18 UFC from the NATOPS Flight Manual

“Minimalistic” because 25 buttons are barely enough to build a the UFC but not the handy controls that come beneath it.
Also, in order to make this project more interesting, we will build an UFC plus some additional controls in the form of 3-way momentary switches.
The 25 buttons will be assigned as:

  • 2x buttons: COMM1 and COMM2 radio selector knobs “pull” action;
  • 12x buttons: 0-9 keypad + Cancel and Enter;
  • 5x buttons: OSPs – Option Select Pushbuttons;

The remaining 6 buttons can be used to control 3x 3-way momentary switches. Although non latched, they can control for instance the ADF or the HUD Reject by moving up and down the switch lever. They can also be used to control the BARO/RAD Altimeter or the DAY/NIGHT HUD mode. Alternatively, they can control some of the Function Selector Pushbuttons. That’s entirely up to you.
A different yet interesting option can be the coding of a 3-way switch as a Master Mode selector in order to double the number of available functions.

SbS_3-diagram-1

Time to draw now. You can use pencil and paper or any software you want. I suggest LibreOffice Draw: it’s free, cross-platform and it’s also quite flexible.
Let’s start by drawing each component the same way we see it. Drawing them on a 1:1 scale will really help the next phases, not to mention if you want to to make this control box part of a wider plan (such as my poor-man-wannabe-cockpit).
Drawing the pins of both Arduino and the various controls is a good idea and will help drawing the wiring diagram. I usually draw the diagram of each control and the duplicate and place them in a general disposition. It doesn’t have to be precise yet.
In case you haven’t noticed yet, the 3-way momentary switch has 3 pins; this is something we will have to take into account later.

The Button Matrix

I have already mentioned the Button Matrix. Let’s see how it works, considering a 3×3 example:
SbS_3-diagram-matrix
Easy right? Understanding a 3×3 matrix is indeed quite immediate but when the matrix gets really big the diagram can instead become a mess.
As a rule of thumb, if the matrix is square, every wire has to “touch” as many buttons as the dimension of the matrix itself.

The First Sketch

This is a quick sketch of our Control Box. Only two encoders will use the pushbutton function and they will be assigned, in our UFC transposition, to COMM1 and COMM2.
SbS_3-diagram-wiring1
I haven’t talked about the size of the box yet and honestly there’s little point in it. Choose the box that you think will better suites your project by containing both the Arduino board and the wires and that will provide enough room to operate the switches without accidentally pressing any other.
In this case, a 170×140 [mm] box will do. Sometimes starting from the box is actually easier because not every size and shape is available on the market. A quick way to find an appropriate box is googling something like “abs enclosure“. Click here if you need help 😛

DCS-BIOS and Arduino TFT

I don’t use DCS-BIOS often. It somehow kills the idea of flexibility that the custom-built Control Boxes provide. Exceptions exist though, one is the TFT: it has to “speak” with DCS in order to get and then display information.

For the sake of experimenting I have bought a 2.8″ TFT, ready to be used with Arduino UNO and, of course, the first project has been focus on the Ka-50.
This is the TFT I used. I opted for simplicity and this small TFT is literally plug&play with Arduino UNO. I was surprised by how easy drawing on the TFT is; moreover a good number of tutorials and examples are available on Elegoo’s website.
After setting up the TFT, the next step is installing DCS-BIOS, which is a very easy thing and perhaps I will cover it later.

Once everything is set up and running, the job now is elaborating the values returned by DCS-BIOS into something that can be displayed on the TFT. As you can imagine is a long (yet simple) reiteration of the same type of function:

get data from DCSelaborate datadisplay on the TFT

This is the result of my first test:

This version was still WIP, although almost completed. My goal was replicating all those information that IRL you would get by a glance at your cockpit but, because of the low resolution or whatever other reason, it cannot be done when in front of a monitor. Therefore I have displayed on the TFT some of the info I check more often, such as SPU-9, R-828 and R800L1 for comms; lights and AP statuses; some functions of the PVI-800 and laser, parking wheels and DL Ingress activated.

Plans for the next update

Since the construction of the UFC/PRTz/PVI800 I moved the TFT on the left side so VVI and the “ball” have become redundant. I plan to replace them with the Engine Power Indicator, which is often disregarded but it’s quite important to ensure a correct Engine Management (thanks 132nd.Donkey for reminding me of that gauge!). I will also try to squeeze a Fuel Cross-Feed indicator that will change colour depending on how much fuel I still have in my tanks and will remind me to activate the X-Feed when a tank is low on fuel.

tft