write an application that interfaces with an input &/or output device that you made,comparing as many tool options as possible
wish to make an interface using python language,and reffered previous students documentation as i am from electronics background this task will be bit difficult for me.What i am planning to do monitor,control and interface LED Board ,part of my final my project board.After that i wish to monitor my thermistor board value also.
First of all i am going to make an interface to monitor 2 LED 's in my board.
Here is the python code which i edited.
from Tkinter import * # Import tk module
import tkFont
import serial
import time
arduino=serial.Serial() #Serial comunication with fabKit (Arduino UNO compatible)
arduino.port ="/dev/ttyUSB0" #Change this value for your COM / tty
arduino.baudrate = 9600 #comunication to 9600 bauds
arduino.open()
def sendOrder(order):
vf['text']="Waiting response..."
v0.update_idletasks()
arduino.flushInput()
arduino.flushOutput()
arduino.write(order+"\r\n")
if arduino.readline()=="OKI\r\n": # "OKI\r\n" is the default response of fabkit program
if order=="b":
v2['text']="LED 2: ON"
v2['bg']="green"
elif order=="a":
v2['text']="LED 2: OFF"
v2['bg']="red"
elif order=="d":
v1['text']="LED 1: ON"
v1['bg']="green"
elif order=="c":
v1['text']="LED 1: OFF"
v1['bg']="red"
vf['text']=""
print ("Hello..!! Arsheena LED interface") # Say hello in console (for debug, you can erase)
v0 = Tk() # Tk() Main window
v0.wm_title("Asheena Fab Academy - Interface and Application Programming")
#v0.config(bg="black") # if you need change background color
v0.geometry("1000x500") # windows size for aplication
helv16 = tkFont.Font(family="Helvetica",size=16,weight="bold")
helv24 = tkFont.Font(family="Helvetica",size=24,weight="bold")
helv14 = tkFont.Font(family="Helvetica",size=14,weight="bold")
helv8 = tkFont.Font(family="Helvetica",size=8,weight="bold")
l = Label(v0,font=helv16,text="Arsheena Fab Academy - Interface and Application Programming")
l.place(relx=.5, rely=.2, anchor="c")
v1 = Label(v0,font=helv14,text="LED 1: OFF",bg="red")
v1.place(relx=.3, rely=.35, anchor="c")
v2 = Label(v0,font=helv14,text="LED 2: OFF",bg="red")
v2.place(relx=.7, rely=.35, anchor="c")
b1=Button(v0,text="Activate LED 1",width=20,command=lambda: sendOrder('d'))
b1.place(relx=.3, rely=.7, anchor="c")
#b1['text']="test"
b2=Button(v0,text="Disable LED 1",width=20,command=lambda: sendOrder("c"))
b2.place(relx=.7, rely=.7, anchor="c")
b3=Button(v0,text="Activate LED 2",width=20,command=lambda: sendOrder("b"))
b3.place(relx=.3, rely=.8, anchor="c")
#b1['text']="test"
b4=Button(v0,text="Disable LED 2",width=20,command=lambda: sendOrder("a"))
b4.place(relx=.7, rely=.8, anchor="c")
vf = Label(v0,font=helv8,text="Waiting response...")
vf .place(relx=.5, rely=.97, anchor="c")
vf['text']=""
v0.mainloop() # launch the main window
After editing program i did test my program using FTDI cable.
this is the program which i created for this
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);
#define PIN1 13
#define PIN2 4
void setup()
{
mySerial.begin(9600);
pinMode(PIN1,OUTPUT);
pinMode(PIN2,OUTPUT);
digitalWrite(PIN1,LOW);
digitalWrite(PIN2,LOW);
}
void loop()
{
if(mySerial.available()>0)
{
switch(mySerial.read())
{
case 'b':
mySerial.println("OKI");
digitalWrite(PIN1,HIGH);
break;
case 'a':
mySerial.println("OKI");
digitalWrite(PIN1,LOW);
break;
case 'c':
mySerial.println("OKI");
digitalWrite(PIN2,LOW);
break;
case 'd':
mySerial.println("OKI");
digitalWrite(PIN2,HIGH);
break;
default: mySerial.println("?");
}
}
}
At last verified the output and it is sucess.