**It's python's time folks **
Python is a nice language when it's comes to produce small utilities and middlewares
For the moment, I just implemented the "Arduino side"
this program accepts a string and transmit it to Arduino, through the serial port
in same way as Arduino Serial Monitor in Post #18
This is Rubik kasBot V1.13 (May 2017: change software versioning )
## Rubik kasBot @ kas 2014
## V1.13 changed windows position
## V1.12 removed delayB4scan
## V1.11 slow/fast cube moves
## V1.1 communication error management
## V1.0 initial release, serial communication with Arduino only
from tkinter import *
import serial, time
from serial import SerialException
import atexit
import subprocess
defaultPortNumber = '3' ## default Serial port
root =Tk()
root.title('Rubik kasBot')
root.geometry('325x335+1000+100') # window size + position
vSolve = StringVar()
comVar = IntVar()
speedVar = IntVar()
comSent = StringVar()
comIn = StringVar()
vErrror = StringVar()
vComPort = StringVar()
vComPort.set(defaultPortNumber)
comSent.set("")
comIn.set("")
def bSolve_CallB():
arduino.write(b"x02" + str.encode(vSolve.get() + 'T') + b"x03")
def speed_CallB():
if speedVar.get():
arduino.write(b"x02 S2 x03") ## slow moves
else:
arduino.write(b"x02 S1 x03") ## fast moves
def com_CallB():
if comVar.get():
root.update()
global arduino
try:
arduino = serial.Serial('COM' + vComPort.get(), 57600, timeout=15)
time.sleep(1.25) ## give time to settle
sComPort.config(state = DISABLED)
print("COM <ON>")
comSent.set("COM <ON>")
EnableButtons(True)
speedVar.set(True)
except SerialException:
EnableButtons(False)
comVar.set(False)
displayComError('COM' + vComPort.get() +" not available")
else:
speedVar.set(False)
EnableButtons(False)
arduino.close()
sComPort.config(state = NORMAL)
print("COM <OFF>")
comSent.set("COM <OFF>")
comIn.set("")
## utilities ------------------------------------
def displayComError(message):
vErrror.set(message)
root.update()
print(message)
time.sleep(2)
vErrror.set("")
def EnableButtons(flag):
if flag == True:
aspect = NORMAL
else:
aspect = DISABLED
bSolve.config(state=aspect)
eSolve.config(state=aspect)
checkSpeed.config(state=aspect)
def cleanup(): ## Exit Cube Explorer and close COM port
if comVar.get():
arduino.close()
atexit.register(cleanup)
## UI elements --------------------------
eSolve = Entry(textvariable = vSolve, width = 60, fg="Blue", bd = 2, font=('arial', 6))
eSolve.place(x=20, y=135, height=20, width=285)
bSolve = Button(padx=59, pady=0, bd=3, text="Solve cube ", fg="black", font=('arial', 16), command = bSolve_CallB)
bSolve.place(x=20, y=160, height=55, width=285)
checkSpeed = Checkbutton(text = "High speed", variable = speedVar, command = speed_CallB)
checkSpeed.place(x=20, y=255)
tError = Label(textvariable = vErrror, fg = "red", bd = 3, font=('arial', 8))
tError.place(x=160, y=260)
checkCom = Checkbutton(text = "COM", variable = comVar, command = com_CallB)
checkCom.place(x=20, y=287)
tComOut = Label(textvariable = comSent, bd = 3, font=('arial', 8))
tComOut.place(x=140, y=278)
tComIn = Label(textvariable = comIn, bd = 3, font=('arial', 8))
tComIn.place(x=140, y=297)
sComPort = Spinbox(from_=1, to=9, width = 1, textvariable=vComPort)
sComPort.place(x=80, y=289)
checkCom.invoke()
root.mainloop()
To run or modify this code, please download Python 3.4.2
(available for Windows, Mac OS, Linux and others)
As for previous test, I shuffled the cube using < D B2 R2 U' F' L F2 R D2 R B2 R' > moves
and entered < R B2 R' D2 R' F2 L' F U R2 B2 D'> to solve it
Same result as above video, trust me on this one
Next steps:
- install a Webcam on the robot, to allow color recognition by Cube Explorer
- probably also install a LED lighting to overcome possible white balance variations
EDIT: getting started (April 2017) ---------------------------------------------------
install Python 3.xx
install tkinter (graphical UI)
install pyserial (Serial comm)
now... do your home work (this thread is not a Python tutorial)
... and run this basic "hello World" test program:
## Rubik (Hello, World) @ kas 2017
from tkinter import *
import serial, time
from serial import SerialException
import atexit
import subprocess
root =Tk()
root.title('Hello, World')
root.geometry('300x300+200+200') ## window size + position
root.mainloop()
See the window ?? you are all set