WEEKLY ASSIGNMENTS

Interface and Application Programming

 

Understanding interface programs work together was challenging. As a graphical interface to design (visual) is ok using the design software, but how to program it and develop the graphic design interact with the command or the clicks on the electrical device, that was new for me.

The function for this interface to build a keyboard, so when I click on A the LCD will show the Letter A on it. That is the concept I will work on. 

I will use the LCD from the Input and the output tasks (the time not on my side to design and build a current board for this task). I start reading about Python as a basic, to follow the logic of it in general and I obtained the advice from our instructor to use phyton. My experience in programming is extremely shallow. So I start with Python for beginners, I watch some tutorials how it works and program https://wiki.python.org/moin/BeginnersGuide/Programmers) that was an extremely valuable source to learn.

Python

the application wasn't install on my computer plus other aplication

Install  and extracting

sudo apt-get update
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

sudo wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz sudo tar xzf Python-2.7.14.tgz


Tkinter

Tkinter provides several GUI widgets like buttons,menu, canvas,text,frame,label etc.

installing Tkinter:

 sudo apt-get install python-tk

Pyserial

is a library which provides support for serial connection, betweem my board and computer

install it

 pip install pyserial==2.7

import serial
import Tkinter arduinoData = serial.Serial ("/dev/ttyUSB6", 4800) def lcd_a():

arduinoData.write('a')

def lcd_b():

arduinoData.write('b')

def lcd_c():

arduinoData.write('c')

def lcd_d():

arduinoData.write('d')


def lcd_clear():

arduinoData.write('1')

def close_window ():

led_control_window.destroy()  

led_control_window = Tkinter.Tk()
led_control_window.geometry('500x500')
led_control_window.title("light control")
Button = Tkinter.Button
btn = Button(led_control_window, text="A", height=5, width=5, background="yellow", command=lcd_a)
btn1 = Button(led_control_window, text="B",height=5, width=5, background="red", command=lcd_b)
btn2 = Button(led_control_window, text="C" ,height=5, width=5, background="green", command=lcd_c)
btn3 = Button(led_control_window, text="D" ,height=5, width=5, background="blue", command=lcd_d)
btn5 = Button(led_control_window, text="clear" ,height=5, width=5, background="blue", command=lcd_clear)
btn4 = Button(led_control_window, text="Press to close",height=5, width=20, background="orange", command=close_window) btn.grid(row=0,column=0) btn1.grid(row=1,column=0)
btn2.grid(row=2,column=0)
btn3.grid(row=3,column=0)
btn4.grid(row=4,column=0)
btn5.grid(row=5,column=4) led_control_window.mainloop() input("press enter to exit")

Arduino code


#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 7); // RX, TX
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 10, en = 8, d4 = 3, d5 = 2, d6 = 1, d7 = 0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

char serialData;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.

mySerial.begin(4800);
lcd.begin(16, 2);

}

// the loop routine runs over and over again forever:
void loop() {

if (mySerial.available()) {
serialData = mySerial.read();
mySerial.print(serialData);

if (serialData == 'a')

{
lcd.print("A"); // turn the LED on (HIGH is the voltage level)

}
if (serialData == 'b' )
{
lcd.print("B"); // turn the LED off by making the voltage LOW

}
if (serialData == 'c')

{
lcd.print("C"); // turn the LED on (HIGH is the voltage level)

}
if (serialData == 'd' )
{
lcd.print("D"); // turn the LED off by making the voltage LOW

}
}
}

 lilclipse text editor to create and run my graphical user interface

To download the files, right click with the mouse and chose “save link as”