arduino connection
This commit is contained in:
parent
a3e64638b5
commit
744280fab8
60
gui/SerialEvent/SerialEvent.ino
Normal file
60
gui/SerialEvent/SerialEvent.ino
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Serial Event example
|
||||||
|
|
||||||
|
When new serial data arrives, this sketch adds it to a String.
|
||||||
|
When a newline is received, the loop prints the string and clears it.
|
||||||
|
|
||||||
|
A good test for this is to try it with a GPS receiver that sends out
|
||||||
|
NMEA 0183 sentences.
|
||||||
|
|
||||||
|
NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or
|
||||||
|
other ATmega32U4 based boards.
|
||||||
|
|
||||||
|
created 9 May 2011
|
||||||
|
by Tom Igoe
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
http://www.arduino.cc/en/Tutorial/SerialEvent
|
||||||
|
*/
|
||||||
|
|
||||||
|
String inputString = ""; // a String to hold incoming data
|
||||||
|
bool stringComplete = false; // whether the string is complete
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// initialize serial:
|
||||||
|
Serial.begin(9600);
|
||||||
|
// reserve 200 bytes for the inputString:
|
||||||
|
inputString.reserve(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// print the string when a newline arrives:
|
||||||
|
if (stringComplete) {
|
||||||
|
String ss = " I got :";
|
||||||
|
ss = ss + inputString;
|
||||||
|
Serial.println(ss);
|
||||||
|
// clear the string:
|
||||||
|
inputString = "";
|
||||||
|
stringComplete = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
|
||||||
|
routine is run between each time loop() runs, so using delay inside loop can
|
||||||
|
delay response. Multiple bytes of data may be available.
|
||||||
|
*/
|
||||||
|
void serialEvent() {
|
||||||
|
while (Serial.available()) {
|
||||||
|
// get the new byte:
|
||||||
|
char inChar = (char)Serial.read();
|
||||||
|
// add it to the inputString:
|
||||||
|
inputString += inChar;
|
||||||
|
// if the incoming character is a newline, set a flag so the main loop can
|
||||||
|
// do something about it:
|
||||||
|
if (inChar == '\n') {
|
||||||
|
stringComplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,22 +16,34 @@ def initComPort(index):
|
|||||||
serialObj.open()
|
serialObj.open()
|
||||||
|
|
||||||
for onePort in ports:
|
for onePort in ports:
|
||||||
comButton = Button(root,text=onePort,font=('Calibri','13'),height=1, width=45,command=functools.partial(initComPort,index=ports.index(onePort)))
|
comButton = Button(root,text=onePort,font=('Calibri','8'),height=1, width=45,command=functools.partial(initComPort,index=ports.index(onePort)))
|
||||||
comButton.grid(row=ports.index(onePort),column=0)
|
comButton.grid(row=ports.index(onePort),column=0)
|
||||||
|
|
||||||
dataCanvas = Canvas(root,width=600,height=400, bg='white')
|
dataCanvas = Canvas(root,width=600,height=400, bg='white')
|
||||||
dataCanvas.grid(row=0, column=1,rowspan=100)
|
dataCanvas.grid(row=0, column=1,rowspan=100)
|
||||||
vsb = Scrollbar(root,orient='vertical',command= dataCanvas.yview)
|
vsb = Scrollbar(root,orient='vertical',command= dataCanvas.yview)
|
||||||
vsb.grid(row=0,column=2,columnspan=100,sticky='ns')
|
vsb.grid(row=0,column=2,rowspan=100,sticky='ns')
|
||||||
dataCanvas.config(yscrollcommand=vsb.set)
|
dataCanvas.config(yscrollcommand=vsb.set)
|
||||||
dataFrame = Frame(dataCanvas,bg='white')
|
dataFrame = Frame(dataCanvas,bg='white')
|
||||||
dataCanvas.create_window((10,0),window=dataFrame,anchor='nw')
|
dataCanvas.create_window((10,0),window=dataFrame,anchor='nw')
|
||||||
|
|
||||||
def letsDoIt():
|
def homeAll():
|
||||||
serialObj.write(b'Ok there\n')
|
serialObj.write(b'<G28>\n')
|
||||||
|
def homeX():
|
||||||
|
serialObj.write(b'<JX>\n')
|
||||||
|
def homeY():
|
||||||
|
serialObj.write(b'<JY>\n')
|
||||||
|
def homeZ():
|
||||||
|
serialObj.write(b'<JZ>\n')
|
||||||
|
|
||||||
b1 = Button(root,text='Click me',command=letsDoIt)
|
b1 = Button(root,text='Home All',command=homeAll)
|
||||||
b1.grid(row=0,column=3)
|
b1.grid(row=0,column=3)
|
||||||
|
b2 = Button(root,text='Home X',command=homeX)
|
||||||
|
b2.grid(row=1,column=3)
|
||||||
|
b3 = Button(root,text='Home Y',command=homeY)
|
||||||
|
b3.grid(row=2,column=3)
|
||||||
|
b4 = Button(root,text='Home Z',command=homeZ)
|
||||||
|
b4.grid(row=3,column=3)
|
||||||
|
|
||||||
def checkSerialPort():
|
def checkSerialPort():
|
||||||
if serialObj.isOpen() and serialObj.in_waiting:
|
if serialObj.isOpen() and serialObj.in_waiting:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user