Control your 2048 with a smartphone by simply adding a Bluetooth module. All the information you need is in this tutorial.
For this project, we will be using an HM-10 Bluetooth 4.0 module, that you can easily find and get one online.
The HM-10 is a readily available Bluetooth 4.0 module based on the Texas Instruments CC2541 Bluetooth low energy (BLE) System on Chip (SoC). The Bluetooth 4.0 HM-10 module is basically a breakout board for CC2541. We will be using VCC, GND, TX and RX pins for this project. Let's start!
You will need 4 female - female jumper wires to make the connections between Creoqode Mini Mega and the Bluetooth module. Start by connecting jumper wires to VCC, GND, TX and RX pins of the Bluetooth module.
VCC pin will be connected to 5V on Creoqode Mini Mega.
GND pin will be connected to GND of the ICSP pins for ATmega2560, which are the 6 pins just next to the reset button on Creoqode Mini Mega. Out of these 6 pins, the one on the lower-left corner is GND, the one next to the pin 30.
TX pin will be connected to RX0 on Creoqode Mini Mega. It might intuitively feel wrong to connect TX to RX, as common sense would be matching TX with TX. However, TX pin (transmitting pin) needs to be connected to RX pin (receiving pin) in order to transfer signals.
RX pin will be connected to TX1 on Creoqode Mini Mega.
Assembly is finished. Let's continue with the coding.
Below, you will find the codes added to the template sketch for Creoqode 2048 to run with the Bluetooth module. You can also download the sketch through the link at the bottom of this page.
Firstly, we need to include the Software Serial library as can be seen at the beginning of the sketch. This library will already be installed on your PC, so you do not have to download anything.
Secondly, we need to create a variable to save the data that is read from the Bluetooth module. In this template sketch, we called it 'data_bluetooth'. Pay attention to the type of the variable, it needs to be a 'char' variable. If you create an integer variable and save the characters received by Bluetooth module, characters will automatically be converted into numbers according to the ASCII system.
Then, create three integer variables. Two of them will be 'x' and 'y', which are going to be used as the coordinates of the pixel for this test sketch. Third variable, called 't' in this template, will be used to define states for the if-loops later.
In the Setup function, Serial.begin(9600) sets the data rate to 9600 bits per second for serial data transmission.
Finally, in the Loop function, you will find the codes of a test sketch that basically moves a pixel according to the characters received by the Bluetooth module. It is useful to add Serial.println() in the loop to be able to see which characters or values you are receiving with the Bluetooth module through the serial monitor on the Arduino Software. In this sketch, we defined 'u' for up, 'd' for down, 'l' for left and 'r' for right.
It is a common issue that the sketch might not be uploaded to your board while the TX and RX pins are connected to Mini Mega board. Please disconnect TX and RX pins, upload the code, and connect them again.
This is all the code you need to add to your sketch. Now, the final step is to set up your smartphone.
For this project, we used an app called 'Hobby Ino' for the iPhone. There are many Bluetooth serial communication apps available both for Android and iOS. The only reason we have chosen 'Hobby Ino' is for the virtual buttons feature.
You can add various virtual switches and potentiometers on this app, and define the values to be sent via Bluetooth at any given state. We have used 4 virtual momentary push buttons for directions, where we adjusted UP to send the character 'u' when pressed, DOWN 'd', LEFT 'l' and RIGHT 'r'. You can use this app to create any kind of controller for 2048.
The blinking red LED on the Bluetooth module indicates that it is not connected to any device yet. After connecting your phone to the Bluetooth module over the app, LED should stop blinking and be steadily on.
Your 2048 should now be working fine with the Bluetooth module. You can create any kind of controller for 2048 and access it remotely!