pip install tkinterwait until the module is already installed
pip install pyseriali first made simple interface that read user input and giveout feedback on the interface
from tkinter import *
root = Tk()
root.geometry('300x300')
root.title("fabacademy")
tit = Label(root, text="my fab interface:)", font=('Bauhaus 93', 25))
tit.pack(padx=20)
userI = Entry(root, width=20)
userI.pack()
def printt():
printtt = Label(root, text=userI.get())
printtt.pack()
BTN = Button(root, text="send 2 MCU", command = printt)
BTN.pack()
root.mainloop()
as i mentioned above we have to import the library for the package the first line indicates how the library importedfrom tkinter import *the following lines create an application window
root = Tk()
root.geometry('300x300')
root.title("fabacademy")
this is the title written above the texte box these are labels under the variable name tit, the keyword pad means to set the object
tit = Label(root, text="my fab interface:)", font=('Bauhaus 93', 25))
tit.pack(padx=20)
this create a text box that enables us to input the characters with keyword "Entry"
userI = Entry(root, width=20)
userI.pack()
so i created a function that reads user input and prit it out
def printt():
printtt = Label(root, text=userI.get())
printtt.pack()
then the last there's also a button i added that i give a command to do a certain thing
BTN = Button(root, text="send 2 MCU", command = printt)
BTN.pack()
root.mainloop() #we loop forever
void setup() {
Serial.begin(9600);
}
void loop() {
int r = random(1, 100);
Serial.println(r);
}
at first we start and set the baud rate to (9600)
import serial
serdata =serial.Serial('COM6', baudrate=9600, timeout=1)
while 1:
print(serdata)
the first line includes the library of the serial module
if (serial.read() == 'Y'){
digitalWrite(LED, HIGH);
}
else if (serial.read() == 'N'){
digitalWrite(LED, LOW);
}
these codes check if we have received character 'Y' and then the LED turn HIGH and if we receive character 'N' LED turn LOW
import serial
from tkinter import *
ser = serial.Serial('COM4',9600, timeout=1)
root = Tk()
root.geometry('300x300')
root.title("fabacademy")
tit = Label(root, text="my fab interface", font=('Bauhaus 93', 25))
tit.pack(padx=20)
# userI = Entry(root, width=20)
# userI.pack(padx=30, pady=10)
def turnON():
ser.write(b'Y')
def turnOFF():
ser.write(b'N')
BTN = Button(root, text="TURN ON", command = turnON)
BTN.pack()
BTN1 = Button(root, text="TURN OFF", command = turnOFF)
BTN1.pack()
root.mainloop()
char _data;
void setup() {
Serial.begin(9600);
pinMode(25, OUTPUT);
}
void loop() {
if (Serial.available() > 0){
_data = Serial.read();
if (_data == 'Y'){
digitalWrite(25, HIGH);
Serial.print("ON");
}
else if (_data == 'N'){
digitalWrite(25, LOW);
Serial.print("OFF");
}
}
}