Arduino pills: Sending Keystrokes

Arduino has a very simple and effective way to send a keystrokes to the PC. It just takes a single instruction, Keyboard.write and the parameter is the key that we want our board to simulate. As usual, details and more info are available in the official documentation.

I use this instruction to send the F12 key and reset my Track IR.

Keyboard.write(KEY_F12);

I have assigned the big round button of my Radio Box to it since I have the habit of recentering my ancient Track IR v4 quite often.

Advertisements

Arduino Pills – Be Flexible or Be DCS-BIOS

This is more a Showerthoght than an actual “Arduino pill” and it’s about HID vs DCS-BIOS. It’s potentially a quite long discussion but I will keep it as short as possible by pointing out the factor that, in my opinion, is the most important: flexibility.

By using HID (Human Interface Device) your control box is “seen” by the PC as any other game controller, allowing it to be used with almost any game (I managed to fly my ships in Star Citizen via the UFC, for instance). DCS-BIOS-based controllers instead use a bus to communicate with DCS and they work on just one module (not entirely true, see below). Therefore, if your intention is to use your Control Boxes with multiple games and modules then HID is probably your best option. It must be noted thought that HID is not supported by every Arduino board (at the moment) so if you need a specific feature not provided by Arduino Leonardo or similar, well, that can be a problem.

DCS-BIOS on the other hand provides an impressive interface between your device and DCS. By using DCS-BIOS you have access to the status of most of the avionics (in the form of numerical values), then what do to with those values is entirely up to the coder. For instance, I use DCS-BIOS to interface my TFT (Arduino Uno). A fellow 132nd Virtual Wing friend uses DCS-BIOS to bring the idea of building Control Boxes to next level. Have a look!

A quick note about DCS-BIOS and multiple modules: I did some tests and my TFT worked both for the Ka-50 and the Mi-8 at the same time. I implemented a number of checks in order to understand which module was running (reading a certain variable, for instance) and then by running only the routines needed for that particular module.
Unfortunately I later scrapped the Mi-8 code because I was running out of memory..

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

Arduino Pills – Change USB HID names

UPDATE 032019

Latest versions of the IDE use a different path. I have just reinstalled the IDE to work on a new version of my Radio Box and my boards.txt is now located in G:\Program Files (x86)\Arduino\hardware\arduino\avr. Everything else (PID/VID) still applies.

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.