DIY Project Control Using Bluetooth Gamepad. Part 1 (Arduino)

Some DIY projects involve some form of remote control. There are many ways and protocols to implement it, and one of them is Bluetooth. This article will tell you how to connect a Bluetooth gamepad to Arduino.

I decided to split this article into two parts, and although the task will be the same, the methods of implementing it differ depending on the chosen platform.

Part 1 (Arduino) – you are here now

Part 2 (ESP32) – all the same will be done on ESP32

Choosing Bluetooth-enabled hardware

Classic Arduino (Nano, for example) do not contain any wireless communication means, and therefore an additional module is needed to use Bluetooth.

The bulk of materials that are googled on request Arduino + Bluetoothoffer ready-made schemes and libraries for modules HC-05 or HC-06. Unfortunately, although these modules provide Bluetooth communication, they implement only one profile – Bluetooth Serial Port Profile (SPP), which is essentially a wireless COM port. To control via such modules, you will need a device that also supports this profile and will send commands via an open port – usually this is either a ready-made Android application or some in-house development with a simple but specialized UI for a specific control scenario.

If you plan to use a gamepad for control, you will need a more advanced Bluetooth module for Arduino.

The next candidate is Arduino Nano 33 BLE – this is a ready-made Arduino board with a Bluetooth chip right away. The board, in general, would deserve a separate article, since there are plenty of interesting differences from classic Arduino and functions in general (Bluetooth, new processor architecture, motion sensor, Python support), but I doubt that the board will become popular:

  1. Price. There are no clones available, and the original board is completely uncompetitive in terms of price.

  2. Supports only BLE (Bluetooth Low Energy). This type of Bluetooth is fashionable and modern, designed specifically for small devices and all kinds of sensors. Due to simplification, BLE chips and devices based on them should be cheaper and more accessible (there is no contradiction with the previous point, the price of original boards is always high), and in general, development using BLE is much easier compared to Bluetooth Classic. The downside is that you won’t be able to connect devices that need Bluetooth Classic via BLE

The only gamepad I know of that already supports BLE is the latest revision of the Xbox controller. Most gamepads continue to use BT Classic (4.0, 5.0, and later).

However, there is still a simple way to connect BT Classic devices to classic Arduino.

Arduino USB Host Shield

The method that will be discussed later in this article is to use several related components:

  1. Arduino board

  2. USB Host Shield for this board

  3. USB Bluetooth adapter

  4. Actually a Bluetooth gamepad

USB Host Shield

USB Host Shield

As you may have noticed, the USB Host Shield is the same size as the Arduino Uno board, and this kit is not suitable for all DIY projects. For more compact projects, there is the Mini USB Host Shield, which is the same size as the Arduino Pro Mini, and we will use this kit further.

Mini USB Host Shield

Mini USB Host Shield

Mini USB Host Shield comes in two versions – with 3.3V and 5V power supply (which also corresponds to the available Pro Mini versions). Since the board is still old and, apparently, not in demand, only 3.3V versions are currently available on marketplaces. There were some doubts whether 3.3V would be enough to power the USB Bluetooth adapter (which is still 5V by standard), but, looking ahead, I will say that 3.3V is enough for stable operation. Therefore, if you still implement the BT device connection scheme described in the article, then feel free to buy a 3.3V Mini USB Host Shield.

As for the USB Bluetooth adapter, the ready-made library that will be used further is quite old and rarely updated (and there is basically no point in updating it anymore), only USB BT 4.0 adapters are guaranteed to be supported (the full list is in the documentation for the library, the link will be below). For use in such a project, you can buy something with a name similar to CSR 4.0For example.

Arduino Pro Mini

Arduino Pro Mini is the most compact of the classic Arduino boards.

Arduino Pro Mini

Arduino Pro Mini

Functionally and in terms of the number of pins, the Pro Mini corresponds to the Nano board, with one important difference: the size reduction was achieved by removing the USB-UART converter from the board. To connect to a computer and upload sketches, you will need a special cable (more on that below). At the same time, the board still has a voltage regulator, allowing you to connect power from an unregulated 5-12V source. Since the Mini USB Host Shield is available in 3.3V, the Pro Mini will also be 3.3V (and the Pro Mini is also available in a 5V version).

USB-UART adapter

You can skip this section if you are already familiar with the process of uploading sketches to Arduino boards without a built-in USB-UART chip.

USB-UART adapter

USB-UART adapter

The megaAVR family processors themselves, on which classic Arduinos are based, do not have a built-in USB interface. Full-size Arduino boards have an additional USB-UART chip, and therefore such boards can be connected to a computer with a regular USB cable.

In the case of the Pro Mini, instead of the usual USB connector, the board only has GND/VCC/TX/RX/DTR pins. To connect such a board to a computer, an external USB-UART adapter is required. Typically, the adapter is a cable with a USB-male connector on one side, a ribbon cable for connecting to the Arduino pins on the other side, and a board with a USB-UART chip in the middle (and possibly with a 3.3/5V jumper – pay attention to it, the output voltage should match the Arduino board).

Very often such cables are found on marketplaces under the name FTDI cableI do not recommend buying such options: most likely, a non-original clone is sold with such a name, and after one story, in order to use the FTDI clone, you will have to download a modified driver from some unknown site.

A more reliable option is USB-UART adapters on CH340 or CP2102 chips, drivers for which are available on the websites of well-known component manufacturers (https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all or https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers). When buying, you should also pay attention to the presence of a wire for connecting to the DTR pin (and the absence of negative reviews – sometimes there is a DTR, but it works crookedly). A correctly working DTR greatly simplifies the process of uploading sketches from the Arduino IDE. Also, the TX / RX pin markings on the adapters can be mixed up, so if the adapter is detected, the system sees the COM port, but the sketches are not loaded – try swapping the TX / RX connections, and also raising the port speed setting to 115200.

Connecting Mini USB Host Shield to Arduino Pro Mini

Since the Mini USB Host Shield is a shield board, you need to connect the corresponding pins on the boards to connect to the controller. In fact, these connections will be enough: power, RST, and SPI pins.

Minimal Wiring Diagram for Mini USB Host Shield and Arduino Pro Mini

Minimal Wiring Diagram for Mini USB Host Shield and Arduino Pro Mini

The pins on the Mini USB Host Shield are not labeled, the correct orientation of the board can be determined by the USB connector and chip – in the diagram below they are on the top side of the board.

The assembly can be done, for example, in this form:

Left: Assembly in the form of a classic shield. Right: Components are individually mounted on the board and connected with very short jumpers.

Left: Assembly in the form of a classic shield. Right: Components are individually mounted on the board and connected with very short jumpers.

I also tried assembling it on a breadboard – and unfortunately, the shield didn't work in this form, SPI refuses to work when connecting the boards via jumper wires, even short ones. So you'll have to solder anyway.

When will there be a code?

There will be no code in this article at all – there is an excellent library for Arduino USB Host Shield 2.0. It has ready support for many USB devices, mostly wired, but most importantly, it has support for a USB Bluetooth adapter, through which the gamepad is connected.

Once you have assembled the hardware, all that remains is to adapt the ready-made code for your DIY project. For example, for the PlayStation 4 controller, the library has this one example.

I will also share my example: video on YouTube plus sources.

Note. The circuit and code in my example are purely for demonstration purposes, they do not provide any protection against overdischarge of LiPo batteries, so it is not recommended to use them in a more or less real project without modifications.

What's next?

What I ended up with works, of course, but it takes up more space than I would like. Plus, I already mentioned that the Mini USB Host Shield itself is becoming hard to find on sale, and the USB adapter needs to be version BT 4.0, and the USB Host Shield 2.0 library itself is quite old (although it is still supported and the connection of the PlayStation 5 gamepad has also been added).

Now is the time to remember that there is ESP32which combines all the necessary components for connecting Bluetooth devices in a compact form. In the next part of the article, I will tell you how to do the same thing, but on a more modern platform.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *