With this code you will be able to blink LED1 when you push a graphical button. I use RPC and RTOS librairies on Mbed LPC1768. On python I use mbedRPC, and Tkinter.

Dependencies:   mbed-rpc mbed-rtos mbed

Fork of Blinking_RPC by thomas cassera

Committer:
Thom_cass
Date:
Sun Jul 30 12:06:24 2017 +0000
Revision:
1:589beced7ccc
With this code you will be able to link a mbed variable to a python variable.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thom_cass 1:589beced7ccc 1 # coding: utf8
Thom_cass 1:589beced7ccc 2
Thom_cass 1:589beced7ccc 3 #linux command to execute the script : python 'path'/RPC_test_code/GUI.py
Thom_cass 1:589beced7ccc 4
Thom_cass 1:589beced7ccc 5
Thom_cass 1:589beced7ccc 6 from Tkinter import * #GUI Librairie
Thom_cass 1:589beced7ccc 7 from mbedrpc import * #Libraire to link serial communication mbed <=> PC, (serial or http)
Thom_cass 1:589beced7ccc 8
Thom_cass 1:589beced7ccc 9 mbed = SerialRPC('/dev/ttyACM0', 9600) #setup on the serial port ACM0.
Thom_cass 1:589beced7ccc 10 #You can check what port you are using with a linux shell command : ls /dev/ttyACM*
Thom_cass 1:589beced7ccc 11 #9600 : default baudrate
Thom_cass 1:589beced7ccc 12
Thom_cass 1:589beced7ccc 13
Thom_cass 1:589beced7ccc 14
Thom_cass 1:589beced7ccc 15 #------------RPCvariable
Thom_cass 1:589beced7ccc 16
Thom_cass 1:589beced7ccc 17 Blink = RPCVariable(mbed,"Blink_RPC") #Create a new variable : name= Blink_RPC, on the mbed setup before, link to the mbed variable Blink
Thom_cass 1:589beced7ccc 18
Thom_cass 1:589beced7ccc 19
Thom_cass 1:589beced7ccc 20 #--------------GUI display
Thom_cass 1:589beced7ccc 21 root = Tk() #creation a new window
Thom_cass 1:589beced7ccc 22 root.title('Blinking led') #display title
Thom_cass 1:589beced7ccc 23 root.geometry('150x50+200+200') #Set geometry of root window
Thom_cass 1:589beced7ccc 24
Thom_cass 1:589beced7ccc 25
Thom_cass 1:589beced7ccc 26 Area = LabelFrame(root,text = "Blinking mode : ") #area creation
Thom_cass 1:589beced7ccc 27 Area.pack(fill="x",expand="yes")
Thom_cass 1:589beced7ccc 28
Thom_cass 1:589beced7ccc 29
Thom_cass 1:589beced7ccc 30 #--update function
Thom_cass 1:589beced7ccc 31 def update():
Thom_cass 1:589beced7ccc 32
Thom_cass 1:589beced7ccc 33 if(var.get() == 0):
Thom_cass 1:589beced7ccc 34 Blink.write(1) #change Blink_RPC value on mbed
Thom_cass 1:589beced7ccc 35 print 'Blinking' #Linux terminal output
Thom_cass 1:589beced7ccc 36 var.set(1) #change var value for the next clic
Thom_cass 1:589beced7ccc 37
Thom_cass 1:589beced7ccc 38 else:
Thom_cass 1:589beced7ccc 39 Blink.write(0) #change Blink_RPc value
Thom_cass 1:589beced7ccc 40 print 'No blink'
Thom_cass 1:589beced7ccc 41 var.set(0)
Thom_cass 1:589beced7ccc 42
Thom_cass 1:589beced7ccc 43
Thom_cass 1:589beced7ccc 44 #---------------------------create a simple button
Thom_cass 1:589beced7ccc 45 var = DoubleVar()
Thom_cass 1:589beced7ccc 46 var.set(0)
Thom_cass 1:589beced7ccc 47 Blink_button = Button(Area, text="Blink", command = update) #command = update => call function update() when you clic button
Thom_cass 1:589beced7ccc 48 Blink_button.pack()
Thom_cass 1:589beced7ccc 49
Thom_cass 1:589beced7ccc 50 root.mainloop()