Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python program to communicate through Bluetooth to Orion controller with sunfounder BLE. controls direction and robot arm/grip.
from Tkinter import *
import Tkinter as tk
from PIL import Image, ImageTk
import os
root = tk.Tk()
frame = Frame(root,width=300,height=800)
frame.grid(row=0, column=0, padx=5, pady=5)
framespeed = Frame(root,width=300,height=800)
framespeed.grid(row=2, column=0, padx=5, pady=5)
framearm = Frame(root,width=300,height=800)
framearm.grid(row=1, column=0, padx=5, pady=5)
root.wm_title("Bluetooth MakeBlock")
photo1 = tk.PhotoImage(file="rsz_left.png")
photo2 = tk.PhotoImage(file="rsz_right.png")
photo3 = tk.PhotoImage(file="rsz_up.png")
photo4 = tk.PhotoImage(file="rsz_down.png")
photo5 = tk.PhotoImage(file="rsz_stop.png")
#background_image=tk.PhotoImage(file="stop.png")
#background_label = tk.Label(image=background_image)
#background_label.place(x=0, y=0, relwidth=1, relheight=1)
def forward():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 66')
def back():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 62')
def right():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 72')
def left():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 6c')
def stop():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 73')
def Holder_Up():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 61')
def Holder_Down():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 63')
def Hand_open():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 64')
def Hand_close():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 65')
def speed_1():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 31')
def speed_2():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 32')
def speed_3():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 33')
def speed_4():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 34')
def speed_5():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 35')
def speed_6():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 36')
def speed_7():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 37')
def speed_8():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 38')
def speed_9():
os.system('/usr/bin/gatttool -i hci0 -b 00:0D:19:12:3B:38 --char-write-req -a 0x0011 -n 39')
forwardbutton = Button(frame, text="Forward", command=forward, image=photo3)
forwardbutton.grid(row=0, column=1, padx=0, pady=0)
backbutton = Button(frame, text="Reverse",command=back, image=photo4)
backbutton.grid(row=2, column=1, padx=0, pady=0)
rightbutton = Button(frame, text="Right", command =right, image=photo2)
rightbutton.grid(row=1, column=2, padx=0, pady=0)
leftbutton = Button(frame, text="Left", command=left,image=photo1)
leftbutton.grid(row=1, column=0, padx=0, pady=0)
stopbutton2 = Button(framearm, text="Stop", command=stop, image=photo5)
stopbutton2.grid(row=4, column=2, padx=0, pady=0)
stopbutton3 = Button(framearm, text="Stop", command=stop, image=photo5)
stopbutton3.grid(row=4, column=0, padx=0, pady=0)
stopbutton = Button(frame, text="Stop", command=stop, image=photo5)
stopbutton.grid(row=1, column=1, padx=0, pady=0)
HolderUpbutton = Button(framearm,text="Up",command=Holder_Up,image=photo3)
HolderUpbutton.grid(row=3, column=2, padx=0, pady=0)
HolderDownbutton = Button(framearm,text="Down",command=Holder_Down, image=photo4)
HolderDownbutton.grid(row=5, column=2, padx=0, pady=0)
HandClosebutton = Button(framearm, text="Close",command=Hand_close,image=photo4)
HandClosebutton.grid(row=5, column=0, padx=0, pady=0)
HandOpenbutton = Button(framearm,text="Open",command=Hand_open,image=photo3)
HandOpenbutton.grid(row=3, column=0, padx=0, pady=0)
speed1button = Button(framespeed, text="speed_1", fg="black",bg="grey", command=speed_1)
speed1button.grid(row=7, column=0, padx=0, pady=0)
speed2button = Button(framespeed, text="speed_2", fg="black",bg="grey", command=speed_2)
speed2button.grid(row=7, column=1, padx=0, pady=0)
speed3button = Button(framespeed, text="speed_3", fg="black",bg="grey", command=speed_3)
speed3button.grid(row=7, column=2, padx=0, pady=0)
speed4button = Button(framespeed, text="speed_4", fg="black",bg="grey", command=speed_4)
speed4button.grid(row=8, column=0, padx=0, pady=0)
speed5button = Button(framespeed, text="speed_5", fg="black",bg="grey", command=speed_5)
speed5button.grid(row=8, column=1, padx=0, pady=0)
speed6button = Button(framespeed, text="speed_6", fg="black",bg="grey", command=speed_6)
speed6button.grid(row=8, column=2, padx=0, pady=0)
speed7button = Button(framespeed, text="speed_7", fg="black",bg="grey", command=speed_7)
speed7button.grid(row=9, column=0, padx=0, pady=0)
speed8button = Button(framespeed, text="speed_8", fg="black",bg="grey", command=speed_8)
speed8button.grid(row=9, column=1, padx=0, pady=0)
speed9button = Button(framespeed, text="speed_9", fg="black",bg="grey", command=speed_9)
speed9button.grid(row=9, column=2, padx=0, pady=0)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.