Week Thirteen : Interface And Application Programming


In this week, we had to write an application that interfaces with an input or output device that we made

I have decided to use my input sensor(IR - Infra-Red Sensor) and display the reading in a GUI using Python

Program in Arduino

    int obstaclePin = A5;
    int hasObstacle = LOW;

    SoftwareSerial Myserial(A0,A1);

    void setup()

    pinMode(obstaclePin, INPUT);
   void loop(){
   hasObstacle = digitalRead(obstaclePin);
   if (hasObstacle == HIGH)
    Myserial.println("Stop, Something Ahead!!");
   Myserial.println("Path is clear");

Serial GUI in Python

Given a menubar in GUI and displayed the Status of the sensor

To run the python code, follow the step mentioned below :

python ser.py /dev/ttyUSB0


from serial import *
from Tkinter import *

serialPort = "/dev/ttyUSB0"
baudRate = 1200
ser = Serial(serialPort , baudRate, timeout=0, writeTimeout=0) #ensure non-blocking

#make a TkInter Window
root = Tk()
root.wm_title("Reading Serial")

# make a scrollbar
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)

# make a text box to put the serial output
log = Text ( root, width=30, height=30, takefocus=0)

# attach text box to scrollbar

#make our own buffer
#useful for parsing commands
#Serial.readline seems unreliable at times too
serBuffer = ""

def readSerial():
    while True:
        c = ser.read() # attempt to read a character from Serial

        #was anything read?
        if len(c) == 0:

        # get the buffer from outside of this function
        global serBuffer

        # check if character is a delimeter
        if c == '\r':
            c = '' # don't want returns. chuck it

        if c == '\n':
            serBuffer += "\n" # add the newline to the buffer

            #add the line to the TOP of the log
            log.insert('0.0', serBuffer)
            serBuffer = "" # empty the buffer
            serBuffer += c # add to the buffer

    root.after(10, readSerial) # check serial again soon

# after initializing serial, an arduino may need a bit of time to reset
root.after(100, readSerial)





I also wanted to try MIT APP INVENTER. So I planned to make an android application.

Programming my board

SoftwareSerial serial(1,0);
void setup() {
pinMode(PA7,OUTPUT);// put your setup code here, to run once:


void loop() {
  if (serial.available() >0)

    char data = serial.read();
    if (data == '1')
    else if(data == '2')





Group Assignment

In this week, we had to Compare as many tool options as possible

We worked with both python and MIT app inventor tools, others almost try with any of the two. After completing the individual assignment we sit together and discuss the tools we used, What we have done is we share our knowledge that we gain from this week

In our lab all of them used At least MIT app inventor or Python to create the desktop or PC applications

App inventor is just a block-based programming tool to create Android applications. It is just a starting programming language for beginners and not for advanced purpose. Python is typing programming language. It doesn't rely on blocks for programming; Python is a much harder programming language than App Inventor. Apps created using App Inventor can be downloaded to your Android phone or, if you don't have an Android, you can download an emulator from the website, but Python does not require the use of either an emulator or a phone

Python Tkinter Vs game

Tkinter is one of the best GUI toolkits for Python and mostly it is used for utility applications. But pygame is used to create games and are not comparable. It all depends on the application you want to write. The choice of the right tool is usually something significant