How to create a simple Android app to connect to the BLE module

 In this tutorial we will show how to create a simple Android app to connect to the BLE module. This is the 3rd part of the tutorial series Bluetooth Weather Station with Arduino with the 2nd part being .Bluetooth Weather Station with DHT Sensor

By connecting the Adafruit BLE module, we open up avenues to: • Acquire hands-on experience with pre-existing open-source projects. • Deconstruct Java code and gain insights into the linkage between the Main activity and the layout files. • Customize the code to activate an LED through Bluetooth and ensure its functionality.

Our endeavor employs an open-source solution that seamlessly integrates with the Adafruit Bluetooth module and is finely tuned for employment within the Android Studio IDE.

In the course of this chapter, we will also comprehensively elucidate the purpose of various segments within the codebase.

For the successful execution of the project, it is imperative to have the requisite SDKs, which are outlined in Chapter 1, "Setting Up Your Workspace," properly installed. Access to the SDK can be attained through the SDK Manager, conveniently located under Tools > Android > SDK Manager.

The primary stride entails navigating to Tony Dicola's GitHub public repository, accessible via the following link: https://github.com/tdicola/BTLETest, as exemplified in the subsequent screenshot:

Android app to connect to the BLE module
At this juncture, you have the choice to either utilize the GitHub desktop application for Desktop Cloning or to obtain the ZIP file, subsequently extracting its contents onto your desktop, as depicted in the provided screenshot:


 

Here are the rewritten instructions:

  1. To begin, give the extracted file a double-click (applicable for both Windows and Mac systems).

  2. Launch Android Studio and proceed to select "Import Project." Then, opt for "Choose Extracted Folder," following the example illustrated below:

 
To aid you in the selection process, you will be able to see a small Android logo next
to the folder you need to choose, as shown in the following screenshot:

After successfully importing the project, you might need to modify the Gradle settings file so that it compiles correctly and is successfully built. The Gradle settings file acts as a preferences manager for our Android project and allows us to manage what libraries we would like to include for our project. You can modify the Gradle settings file by accessing the project tree and clicking on app > src followed by build.gradle, as shown in the following screenshot :

andriod app 3


We advise modifying the buildToolsVersion to 19.1.0. Please don't be misled by the appearance of the 'app' in the tabs. The accurate configuration is visible below:

 After making changes to the settings in the Gradle Settings menu, you'll receive a prompt to synchronize your project configuration. To perform the synchronization, simply click on the "Sync Now" button. With the Gradle settings successfully configured, you're ready to test the application on a physical Android device that is compatible with BLE. Ensure the device runs Android 4.3 or a more recent version. To run the app, navigate to the toolbar, click on "Run," then select "Run app." Finally, choose the appropriate physical device from the options, as illustrated in the screenshot below:
 

 

You have the option to transmit the subsequent messages to the Bluetooth module by touching the Text Field and subsequently selecting the Send command:

  • /mode/7/o /
  • /digital/7/1 /
  • /digital/7/0 /

Once you observe that the aforementioned messages generate appropriate responses through the LED – turning on and off in accordance with the given sequence – we can then move forward with adjusting the layout file.

 

adsf


Post a Comment

Previous Post Next Post