This past week I mainly focused on learning how to create a PhoneGap application that can connect to my Flora board using Bluetooth and can send and receive data.
Using the PhoneGap CLI to Create PhoneGap Apps
In the past I had used the PhoneGap desktop app to create PhoneGap apps as it’s simple to use and easy for beginners. However, while it is easy to use, using the desktop app is not the best way to develop an app as you cannot use it to install plug-ins. Since I need to incorporate Bluetooth in this project, I needed to use a Bluetooth plug-in so I had to create my app using the PhoneGap CLI.
I learned how to create an application using the PhoneGap CLI from this tutorial. It didn’t take me long to learn how to create an application with the CLI, but it did take me an abnormally long time to install all of the necessary requirements (Java JDK, Android SDK, and Xcode) to build and run the application on both Android and iOS devices.
Bluetooth Plug-ins and Loading Apps
After learning how to build the simple “hello” application from the tutorial, I searched for a simple Bluetooth PhoneGap app that could connect to my Flora and that I could load onto my iPhone. I found don’s repository for his BluetoothSerial plug-in here, cloned the repository, and built his example “Chat” app using the CLI. The code that I used for this app is the same and can be found in this repository.
After following the instructions for how to build the app I had to learn how to deploy the app to my iOS device. I did this by following these instructions for how to side-load an app to my iPhone with Xcode. The directions for side-loading an app were pretty straightforward, but I did find that there were a lot of permissions issues that arose when trying to open and edit files in Xcode, but I was able to find my way through the issues without much difficulty and I was able to load the “Chat” app onto my iPhone.
I used the “Chat” app and was able to connect to the Adafruit Flora Bluefruit LE and send messages to the Flora from my phone but I couldn’t yet receive anything as I didn’t have the proper code loaded onto the Arduino. I looked at don’s example code here but I knew it wouldn’t work as he used a different Arduino board and different Bluetooth hardware with a hardware SPI configuration which is entirely different from the hardware serial configuration that is needed for a Flora. I searched around for a long time and couldn’t find an example using hardware serial communication and I even wrote to don, the creator of the repository, before I found out that my real issue was that I was using the wrong PhoneGap Bluetooth plug-in. I needed to use the Bluetooth Low Energy plug-in found here instead of the Bluetooth Serial plug-in. I cloned the Bluetooth Low Energy plug-in, built the example “bluefruit le” app, and uploaded my code to this repository. I was able to test this code with just the exact same code that I had used from last week that was able to send data from the Flora to PhoneGap’s Bluefruit app that I’d downloaded from the app store. The app worked and was able to send to the Flora and receive data from it, but it was also printing out “AT+BLEUARTRX” after every message that was received. I modified my Arduino code and made it much simpler and was able to fix this issue. The code now sends ints instead of charArrays and the “Failed to send?” error message is also no longer printed in the serial monitor. All in all I’m pretty satisfied with my current Arduino code, but I am a little bit concerned about the delay that I had to put in after the number of completed reps is sent. I’m a little bit worried that we might not count an athlete’s rep if it occurs during that 1 second delay. I’ll be sure to keep an eye on this in the future though and make sure it’s not a problem.
Plans for the Coming Week
I’m planning edit my original MuscleMemory app that keeps track of the completed and incomplete reps and get the app to work with Bluetooth and update using switches. I’m also planning to edit the MuscleMemory app and the Arduino code so that we can keep track of “half-completed” reps. I’ll have to be careful with this though so that we don’t store half-completed reps when an athlete isn’t attempting a squat. Lastly, if I have time I’d like to edit the Arduino code to replace the digital sensors with analog sensors and incorporate the NeoPixels into the code.