Week 12- Interface and application programming

Overview

For this week we have two assignments:

  1. Group assignment
  2. Compare as many tool options as possible.

  3. Individual assignment
  4. Write an application that interfaces a user with an input and/or output device that you made

Have you?

Documented your process

Explained the UI that you made and how you did it

Outlined pro blems and how you fixed them.

Explained problems and how you fixed them.

Included original code (or a screenshot of the app code if that's not possible).

Included a ‘hero shot/video’ of your application running with your board.

Linked to the group assignment page.


The Process

The idea

I wasn't be able to access the lab for 2 weeks now. when I go through my old stuff from college I found a heart beat sensor that I used in one of my college projects 4 years ago.

So i decided to read it's signal through arduino and build an interface with python.

Install the required libraries

I open the terminal then run the following code to make sure of my python version.

 python3 --version
pyhtonversion3

then I install pyserial in order to be able catch the data from arduino

 pip3 install pyserial
pip3 install pyserial

and finally install vpython

 pip3 install vpython
pip3 install pyserial

Check the vpython

run quick code to check all is good

 nano try.py

simple code in which I bringe a white box that can be rotated with mouse

vpython check code

then run the code through the terminal.

 python3 try.py
vpython check code

check pyserial with arduino
vpython check code

write simple code to arduino to present data on the serial monitor.

vpython check code

The serial monitor from Arduino IDE.

vpython check code

write the corresponding code in python to catch the data from arduino print it.

vpython check code

the data python capture and present. as you can see it's a string so I should remmeber to convert the data before use it.


Build the GUI

Now All looks good time to write the GUI, the idea I have in mind is really simple just to make a sphere that represent the sensor in real world and it's radius will change depend on the sensor readings

Heartmonitor.py
#import the libraries that we need
import serial
from vpython import *
#create an object to read the data
arduinoSerialData =serial.Serial('/dev/ttyACM2',115200)
measuringShape= cylinder(length=3, color=color.red,radius=0.5,pos=vector(0,0,0))
readingText= label(text='Heart Beat sensor reading:', pos=vector(0,1,0), height=25)
readingData= label(text='', pos=vector(0,0,0), height=25,box=False)

while (1):
    rate(100)
    if (arduinoSerialData.inWaiting()>0):
        myData= arduinoSerialData.readline()
        heartBeat= int(myData)
        myText= "Heart Beat sensor reading"
        print (heartBeat)
        measuringShape.radius= heartBeat/100
        readingText.text= myText
        readingData.text= heartBeat

Try Tkinter

in the lecture Neil said that most of his GUIs has been build with tkinter ,So I decided to try create one.

Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way to create GUI applications.

Tkinter is a built in function, but for some reason that I'm not aware of them I cannot find it so I start by install it through terminal

 sudo apt-get install python3-tk
 sudo apt-get install tk-dev

I found this quick tutorials about tkinter basics to be familier with it, I go through them, however at the end I still didn't now how to connect tkinter with arduino in order to present the data

So I came back to Neil documentation read the Temprature gui code and try to figure things on my own =).

at the end I was able to come up with this GUI, however I couldn't connect it with the comming data from arduino also I couldn't figure out away to solve this yet, but it was nice to be familier with tkinter and it is time now to move on to teh next assignments

tkinter app