For a recent project an optional requirement was to provide a means of controlling a device remotely. The device was running a modified version of the open source firmware GRBL on an Arduino UNO. Normally the Arduino is connected through a USB cable and sends and receives messages over a serial link. For the same project a Samsung tablet running Android was already available. The logical conclusion was to make the two communicate with each other.
I found a bluetooth device compatible with Arduino made by Adafruit, the Adafruit EZ-Link. The reason for choosing this device is that you connect it up to the RX and TX of your microprocessor and does not require any extra libraries to function. While testing the bluetooth communication I could communicate between a PC and the breakout board but not between the breakout board and any of the bluetooth apps in the Google Play store. Some investigating was required.
UPDATE: Adafruit now sells the: Adafruit Bluefruit LE UART Friend. This is a Bluetooth Low Energy (BLE) breakout board that you can use to replace the older Adafruit EZ-Link.
GRBL the latest versions of GRBL communicate by default on a baudrate of 115200 where Android prefers a baudrate of 9600. A modification to GRBL's source code corrects this. Still after making this change GRBL and Android would not communicate. Something else was going on. After looking at the source code of GRBL it becomes clear that GRBL waits for characters to come in over serial until a NULL character ('\0') is received. I did not expect this to be the problem because several of the applications I tried had the option to enable a string termination character, NULL character and/or carriage return.
I decided to borough a Saleae logic analyser which I had experience with. The logic analyser was connected to the RX and TX of the EZ-Link and commands were sent through an Android application. Then it became clear that even though the application advertised it would send a string termination character it actually did not send it. Since I wanted to provide a GUI to control the device and all the Android applications did not work as advertised anyway I wanted to create my own application.
Because of my limited amount of time available on my project and being unfamiliar with Android development at the time I preferred not having to start from scratch. Luckily Google has an example named "BluetoothChat" available for Android. After a quick test it became clear that again a string terminating character was not send. But since I now had access to the source code I could program in my own solution. The solution was fairly simple. In the function call “private void sendMessage(String message)” add the following line of code: message += "\n";//add newline character for GRBL
In the image above channel 0 is the serial stream captured with the logic analyzer from the Android application to the Arduino. Channel 1 is the response from the Arduino after receiving a valid command.
A simple proof of concept GUI was made. By pressing a button a command in the form of a string sent over a Bluetooth serial connection to the Arduino running GRBL. Some of these commands are specific to GRBL others consist of the widely used G-code.