arduino connection

This commit is contained in:
jfs atom 2021-06-12 21:34:27 +02:00
parent a3e64638b5
commit 744280fab8
2 changed files with 77 additions and 5 deletions

View 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;
}
}
}

View File

@ -16,22 +16,34 @@ def initComPort(index):
serialObj.open()
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)
dataCanvas = Canvas(root,width=600,height=400, bg='white')
dataCanvas.grid(row=0, column=1,rowspan=100)
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)
dataFrame = Frame(dataCanvas,bg='white')
dataCanvas.create_window((10,0),window=dataFrame,anchor='nw')
def letsDoIt():
serialObj.write(b'Ok there\n')
def homeAll():
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)
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():
if serialObj.isOpen() and serialObj.in_waiting: