Arduino UNO plays in 2048 with a field size of 8x8

Relatively recently, an exciting game 2048 appeared on the network. A lot of people have been dragged on since the first days of its appearance on the network. And all in order to collect the coveted number 2048. Having played enough of this game, I came across a new version of the game in which the number of cells in rows and columns increased to eight.
That's where it all started, after three hours of the game I never lost, and the excitement only increased in proportion to the points received. Having killed almost half a day, folding up the numbers, I became interested. How long can I play this game? But I didn’t want to lose on purpose, (it’s not in vain that I played all day) I decided to write a sketch that will perform not complicated actions for me, moving rows and columns with numbers. I want to clarify right away that I rejected the idea of ​​writing a program for execution on a PC, because this is a long-worn topic. The algorithm in the video is different from what I used when writing the sketch.
So, let's start what we need:
  • Arduino uno
  • Atmel proprietary utility - Flip
  • Wire and jumper
The goal was quite simple: write a sketch for Arduino UNO, which will emulate the keystrokes on the keyboard. So that when the device is connected to the computer, a sketch is started and the digits of the game 2048 begin to move on the monitor.
The algorithm of our actions:
  1. We write a sketch with the necessary functionality and fill in the ATmega328 MK
  2. Flashing Arduino bootloader, ATmega8U2 usb controller
To emulate keystrokes, I used the HIDKeyboard library . Well, now we turn to the most interesting - we will turn the Arduino UNO into a HID device, and more specifically into a USB keyboard.
A bit of theory.
Bootloader firmware - first you need to put Arduino in Device Firmware Update mode or in the more commonly used version of DFU. It serves for flashing the controller acting as a serial to usb converter.
As you know, the main difference between Arduino UNO and previous Arduino boards is the presence of a second ATmega8U2 controller, which replaces the USB <-> COM (FT232R) hardware converter. The advantage of this solution is the ability to replace the firmware in the interface controller in order to emulate an arbitrary device when connecting the Arduino to a PC (drive, hid device, etc.). How to do it? The interface controller has DFU mode - ATmega8U2 controller firmware via USB connection. Almost like the firmware of the central Arduino controller. To do this, you can use the proprietary utility Flip. In order to transfer the controller to this programming mode, a small hardware upgrade of the Arduino is required. Apparently, the developers created it specifically to use the DFU mode of the interface controller.
Formally, there is no difficulty, but not everyone will risk soldering. And honestly, this is of no use. There is a way much more convenient.
After these steps, the computer will detect a new device and try to install the drivers on its own, but it will fail. It is time to install Atmel's proprietary Flip utility. Open the task manager and see the new Arduino Uno DFU device.
Select the driver from the folder of the recently installed FLIP utility. As a result, we will have a new device - AT90USB82. Further, when you connect the Arduino, the device will be detected as a USB device. Now we need to fill in the HEX file with the USB keyboard instructions. So that the computer further recognizes our Arduino as a usb keyboard. We start FLIP.

  1. Select in the menu Device> Select> AT90USB82
  2. Select in the menu Setting> Communication> USB
  3. Click Open
  4. Getting to the firmware, click Run
At the end of the firmware process, you can close the program and check how the device works. As a result, my Arduino successfully played in 2048 for almost a week. He didn’t turn it off even at night. In confirmation, here is my result.
This is how you can turn an Arduino UNO into a HID device. By the way, you can not only play games but also play a friend by connecting a device to his computer that will start a notebook and write jokes there, or run commands, because the keyboard is the main computer control panel. Unfortunately, this method cannot be applied to the Arduino Nano board. As mentioned earlier, the second Arduino UNO controller (ATmega8U2) is used as a USB to Serial converter to identify the Arduino UNO computer as a USB device. We can conclude: to implement this method, without extraneous devices, it is possible only if the Arduino board has a microcontroller programmed as a USB-to-serial converter. But what if you have an Arduino Nano or other board without a USB to Serial converter? In this case, you can buy a separate converter like this one.

Also popular now: