Arduino - Python GUI
Hi all, I'm using arduino for a while now. For my purposes I was using matalb to communicate with it. I want to move to python now. I started building my first python gui to control my arduino program. The problem: I'm trying to pass a sentence which contains python's entry values to arduino, but for some reason the arduino doesn't read it. The codes are written here. Arduino code #define LED 13 void setup() { pinMode(LED, OUTPUT); pinMode(2,OUTPUT); Serial.begin(9600); } void loop() { if (Serial.available()) { char c = Serial.read(); if (c == 'H') { digitalWrite(LED, HIGH); digitalWrite(2,HIGH); } else if (c == 'L') { digitalWrite(LED, LOW); digitalWrite(2,LOW); } } } Python code from tkinter import * import serial import time ser = serial.Serial('com7', 9600) # com7 need to be changed for linux ^%&*^$%&$%&$%^&###@@@ time.sleep(0.2) # ser.close() print('serial communication started') def pent(ard): s = entry1.get() c = bytes(s, 'utf-8') ard.write(c) time.sleep(0.5) # ard.write(b'H') # the b before 'H' is conversion to bytes. needed for arduino. print("LED ON") time.sleep(0.5) ard.write(b'L') print("LED OFF") time.sleep(0.5) root = Tk() RTitle = root.title("LaserOdorPython") root.minsize(200, 200) root.maxsize(1400, 850) root.geometry("300x500") label1 = Label(root, text='Odor#\Laser', font=11) entry1 = Entry(root) label1.place(x=10, y=20, width=90, height=20); entry1.place(x=120, y=20, width=90, height=20) button1 = Button(root, text='single pulse', font=8, command=lambda: pent(ser)) button1.place(x=100, y=140, width=90, height=30) root.mainloop()
Topic by torr.polakow