Interface and Application Programming

Group assignment:

  • Compare as many tool options as possible

  • Individual assignment:

  • Write an application that interfaces a user with an input &/or output device that you made
  • Introduction to interface and application Programming


    The application programming interface, also known by the acronym API, application programming interface, is a set of subroutines, functions and procedures that offers a certain library to be used by other software as an abstraction layer.

    In computing, an application programming interface (API) is an interface that defines interactions between multiple software applications or mixed hardware-software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc. It can also provide extension mechanisms so that users can extend existing functionality in various ways and to varying degrees. An API can be entirely custom, specific to a component, or designed based on an industry-standard to ensure interoperability. Through information hiding, APIs enable modular programming, allowing users to use the interface independently of the implementation.


    Image taken from appinventor

    App development.


    App Inventor is a software development environment created by Google Labs for the development of applications for the Android operating system. The user can, visually and from a set of basic tools, go linking a series of blocks to create the application, in this week's assignment we will use a Bluetooth module to communicate with the panel and manage to turn on a led from an application on our cell phone, Due to inconveniences due to the pandemic and due to a stoppage of activities in the public transport sector, I will use an arduino to carry out the activity

    Starting the design.


    To start with AppInventor we go to its website and create an account

    For this task I use App Inventor you can use it from the following link App Inventor

    Once we have registered we can start with the development of our app, for this we will start a new project



    In the pop-up window we will put a name to our project, Next we will see the different components of the AppInventor work interface


    1 Toolbar, project toolbar

    2 Blocks: opens the code to run this app. You can go back to design by clicking on design located on the top right side of the window

    3 Pallet: where you can find many options for your interface

    4 Viewer: shows a preview

    5 Components: shows the components selected and active in the app

    6 Properties: allows to change the configuration of the components



    Now that we know the different parts and tools of our interface, we can design our App, AppInventor is a modular type of App development program, of the drag and drop type, this facilitates development since it has many tools, to be able to locate each of the tools we can search for it, using the component search tool

    If we go from the design window to the design window by blocks, we will find on the right the different components by color, even we have the control, logical, mathematical ones among others



    For the design of the App that will control the lights of the bus stop through the use of a Bluetooth module, we will separate the programming logic into several modules, in the following image we can see the modules used in detail.



    Finally, once we finish our development we will proceed to download our App to the cell phone, for this we will use the toolbar the option Built, App (provide QR code for .apk), then AppInventor will compile our development and at the end it will give us a QR code, which when accessed from our mobile phone, will start downloading the App, and then we can install it on our mobile



    Now we have our App on our mobile, and we can run it to start our mobile application




    Testing the Bluetooth.aia project:



    The first thing to do to test our app is to build our circuit, in my case for pandemic reasons, and because I do the fabacademy course virtually from another city I will use an arduino, a circuit board for the bluetooth module and a HC-05 module



    You can see the whole process in Networking and communication week Networking and communication



    Below you can see the connection diagram of the HC-05 Bluetooth module and their respective connections in the arduino, once the molecule is connected you can check its operation using the respective AT commands


    Image taken from aprendiendoarduino


    Image taken from appinventor


    This post follows on from Arduino With HC-05 Bluetooth Module in Slave Mode

    The STATE pin on the HC-05 zs050 board is connected to the LED 2 pin on the small bluetooth module and the LED 2 pin is used to indicate when there is an active connection. This means the Arduino can connect to the STATE pin and determine when we have a connection. The STATE pin is LOW when the HC-05 is not connected and HIGH when the HC-05 is connected.

    As a quick visual indicator you can put a LED + suitable resistor on the STATE pin. When the module is connected the LED will light.

    You can also use the Arduino to read the value of the STATE pin.

    Add a wire from the STATE pin on the HC-05 to the D4 pin on the Arduino

      Image taken from martyncurrey



    Upload the following sketch. The sketch now waits until pin D4 goes HIGH before starting the software serial and making a connection to the HC-05.

    This sketch does not copy what you enter in the serial monitor input field to the serial monitor main window.

    // Basic Bluetooth sketch HC-05_03 Using the state pin 
                  // Connect the HC-05 module and communicate using the serial monitor
                  //
                  // The HC-05 defaults to communication mode when first powered on.
                  // The default baud rate for communication mode is 9600
                  //
                   
                  #include <SoftwareSerial.h>
                  SoftwareSerial BTserial(2, 3); // RX | TX
                  // Connect the HC-05 TX to Arduino pin 2 RX. 
                  // Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
                  // Connect the HC-05 STATE pin to Arduino pin 4.
                  //
                   
                  char c = ' ';
                   
                  // BTconnected will = false when not connected and true when connected
                  boolean BTconnected = false;
                   
                  // connect the STATE pin to Arduino pin D4
                  const byte BTpin = 4;
                   
                   
                  void setup() 
                  {
                      // set the BTpin for input
                      pinMode(BTpin, INPUT);   
                   
                      // start serial communication with the serial monitor on the host computer
                      Serial.begin(9600);
                      Serial.println("Arduino is ready");
                      Serial.println("Connect the HC-05 to an Android device to continue");
                   
                      // wait until the HC-05 has made a connection
                      while (!BTconnected)
                      {
                        if ( digitalRead(BTpin)==HIGH)  { BTconnected = true;};
                      }
                   
                      Serial.println("HC-05 is now connected");
                      Serial.println("");
                   
                      // Start serial communication with the bluetooth module
                      // HC-05 default serial speed for communication mode is 9600 but can be different
                      BTserial.begin(9600);  
                  }
                   
                  void loop()
                  {
                   
                      // Keep reading from the HC-05 and send to Arduino Serial Monitor
                      if (BTserial.available())
                      {  
                          c = BTserial.read();
                          Serial.write(c);
                      }
                   
                      // Keep reading from Arduino Serial Monitor input field and send to HC-05
                      if (Serial.available())
                      {
                          c =  Serial.read();
                          BTserial.write(c);  
                      }
                   
                  }

    Connecting the Led and linking the code together


    finally we include the following code at the end inside the void loop



    Performing the connection tests with the bluetooth module






    General Conclusion:

    App inventor is a very powerful and easy-to-use framework, which allows us to develop mobile applications intuitively and quickly. App inventor allows us to work visually and from a set of basic tools, link a series of blocks to create the app. The practicality of its download to the mobile via a qr code makes it even more practical to develop and steal our apps in a few minutes