w.1.homw web.jpg

Week 14
Interface and application programming

For this week I have to write an application that interfaces with a user with an input and/or output device you made. but in my project, I don't find any need for any kind of mobile application. Maybe it will be used in the next spiral. But for this time I want to make it as simple as possible. So for this week, I decided to control a Servo motor, which is part of my project as an output device. And make a mobile application using MIT App inventor. 😀

The task list for this week:

  • Group assignment:
    • Compare as many tool options as possible.
  • Individual assignments.
    • Write an application that interfaces a user with an input and/or output device that you made.

Group assignment:

In this week's group assignment. We learned about various Interface and Application Programming that including understanding different tools for developing applications and interface programming. We also learned how to use these tools, their features and their purposes. We also try to make some applications using application tools like MIT app Inventor, Processing, etc.

Check here to read more about our group assigment.

Individual assignments:

MIT App Inventor:

What is App Inventor?

I saw it for the first time using my younger sister 3 years ago. At that time I was only aware of making Mobile applications with the help of android studio. But this was amazing for beginners to get a feel of making an application. The App Inventor project began at Google in 2007 when Prof. Hal Abelson of MIT went on sabbatical at Google Labs. The project leads were inspired by increased interest in educational blocks programming languages. App Inventor lets you develop applications for Android phones using a web browser and either the connected phone or emulator. The App Inventor servers store your work and help you keep track of your projects.its amazing 😀

image not found

How it works.

To reab more about MIT app inventors visit their Page by clicking here.

image not found

App Designing:

App development Is a two-stage work. One has to do front-end programming for creating UI (user interface) and back-end programming to run the application the way it has to. In the MIT app inventor programming environment, They make it very simple by creating a very easy graphical interface both for the Designing section(front end )and Block coding section(Back end). I start with the front end of the designing section that I refer to this document on their website which helps me in designing an app.

1. To start with the Mit app I first visit on there website and clock on creating app button. To start to build the application.

image not found

MIT app inventer home page.

2. After that I create the new project by clicking Start new project and giving a name to my Project.

image not found

Creating new project.

Front-end Design:

3. Here is a new fresh app development environment window open. It has 4 sections Palet where I found all the components I need to build my front end. Click here to read more here.

image not found

.

4. I start with the layout. I pick the vertical layout and scale up it fully to the entire screen as you can see in the picture.

image not found

.

5. Then I drag and drop an image palate from User Interface. and make it At the centre of the screen through the properties tab.

image not found

.

6. I define the Image size by defining the layout of the image as shown.

image not found

.

7. And then Upload a rendered image of a servo motor from my last assignments.

image not found

.

8. Then for listing the Bluetooth devices. I add a list picker and resize it with a width of 10% suitable for to screen.

image not found

.

9. I named it Searching for a new device. So that users can easily Identify its functionality of finding the device.

image not found

.

10. Then I use to give it a nice looking colour through Background colour in the properties tab.

image not found

.

11. Then I use a horizontal arrangement to leave some space after the slider.

image not found

.

12. For controlling the Servo motor through Interface I pick up a Sliding component and make it its full length to make a nice UX(User experience) design.

image not found

.

13. To make connection with other devices through this Interface I added a Bluetooth component to the design.

image not found

.

14. To provide the current angle of revolution of the Servo motor shaft. I provide a Lable tab just below the slider and name its degree. Because it will show the no. of degree the servo will revolve.

image not found

.

15. Then I provide another HorizontalArrangement at the very bottom of the screen to provide the Space for buttons.

image not found

.

16. I decided to add 3 buttons for moving servo at 0 degrees 90 degrees and 180 degrees respectively. I also use the property section to make them in place by resizing their size and also providing the buttons and their nomenclator respectively.

image not found

.

17.I rename the buttons .

image not found

.

18.I also provide colours in them for easy identification.

image not found

.

And here I endup with my front-end design.

Back-end Block Coding:

For designing the back end for the above UI .MIT media app provides the blocks language platform. where Built-in blocks are available regardless of which components are in the project. In addition to these language blocks, each component in the project has its own set of blocks specific to its own events, methods, and properties. To know more about Built-In Blocks in MIT app inventor Blocks Editor click here.

1. To start with back-end Programing. I click on the right-top left button (blocks) at the corner of the design window.which will open a new window dedicate to back-end Programing . It consists of two sections where in one section you are provided with Blocks including various functions in graphical block format and programing space to arrange them in secuence.

image not found

.

2. I follow the sequence that I follow in the design section and start with a list-picker code function. which I will need to pick a Bluetooth devise.

image not found

.

3. Then pick a block to specify the no. of devices(Elements) available to connect.

image not found

.

4. I came across an error and after hovering over it. I got this message .Which tries to mine that this is not enough to complete the logic.

image not found

.

5. So I have to specify the Source and the type of element input to the list picker to display on the app.

image not found

.

6. I duplicate the functional blocks and attach them to the After picking condition.

image not found

.

7.I change the Listpicer display from Elements to Selection.

image not found

.

8.I add a blutooth function for communicate obetween application with other blutooth devices.

image not found

.

9.For connecting the bluetooth devise .I require a listpicer function.

image not found

.

10.I pick a set listpicker block and change it to selection .Which retarn the value from selected device to app.

image not found

.

11.I added one more Listpicker block to add the text in it to show the device is connected.

image not found

.

12.For that I pick up a text component.

image not found

.

13.And print "connected.." on display after the device get paired with application.

image not found

.

14.Now to generate data from slider input I add a contition function.

image not found

.

15.I also add the blutooth function to send this generated value to paired devices.

image not found

.

16.I use a roundup from maths function to filter the analog signal from the input slider interface.

image not found

.

17.And add a slider function to take input from user.

image not found

.

18.I also provide a lable block in front end design .which will show the current angle of motor with respect to position of slider .

image not found

.

for that I pick a slider function which will provide the data from sliding input from ser

image not found

.

19.Finaly I have added some buttons at the bottom of the interface to directly assign the angle.For that I use the same while condition function as the slider.

image not found

.

20.Also I use the same bluetooth function to send the data .

image not found

.

21.And to assign the value I use integer blog to assign the angle for that button.

image not found

.

22.I did this for each of 3 buttons .

image not found

.

23.And here the back-end coding ends.

image not found

.

Installing the app in mobile:

For installing the app in mobile .You can Either download or open the app through browser .For that go to .
Build>Android Apk.

image not found

.

A window will open with an option of downloading the apk file or a QR scanner to open the application through brouser.I suggest downloading the apk file .In QR code one should need to scan the code from time to time to open the application.

image not found

.

Arduino Code:

For operating the servo motor using the this app. I use my final project bord from week 13 , A MG995 Servo motor and a HC-05 Blutooth module.

Connections :
Servo motor : Vcc , Gnd, PWM(PA4 ~0Arduino pin).
HC-05 : Vcc, Gnd, Rx(PBO~7), Tx(PB1~6 Arduino pin).

I use SoftwereSerial.h Libery to Define the Rx and Tx pin in ATtiny1614 microcontrol in my bord.

I write this costum code for my Board for controlling the Servo motor.

      /*Fab accademy 2022 by vrushavh.
      Code to controle  Servo motor  using blutooth module HC-05 and Servo motor App*/
       
      #include < SoftwareSerial.h> // TX RX software library for bluetooth
      
      #include < Servo.h> // servo library 
      Servo myservo; // servo name
      
      int bluetoothTx = 6; // bluetooth tx to 6 pin
      int bluetoothRx = 7; // bluetooth rx to 7 pin
      
      SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
      
      void setup()
      {
        myservo.attach(0); // attach servo signal wire to pin 9
        //Setup usb serial connection to computer
        Serial.begin(9600);
      
        //Setup Bluetooth serial connection to android
        bluetooth.begin(9600);
      }
      
      void loop()
      {
        //Read from bluetooth and write to usb serial
        if(bluetooth.available()> 0 ) // receive number from bluetooth
        {
          int servopos = bluetooth.read(); // save the received number to servopos
          Serial.println(servopos); // serial print servopos current number received from bluetooth
          myservo.write(servopos); // roate the servo the angle received from the android app
        }
      
      
      }
    

Code to controle Servo motor using blutooth module HC-05 .

Hero Video:

Here is how I control my servo motor. Using the application I creat.

A small demo of how I use this application to controle my servo motor .