Mach3 CNC Controller ดูเป็นที่นิยม สำหรับงาน Mini cnc ใครทราบบ้างใหมว่ามันมีลูกเล่นมากมาย ที่มีหลายคนทราบ แล้วเก็บใว้คนเดียว หรือ คนที่คิดว่าชำนาญ แต่อาจไม่ทราบเรื่องเหล่านี้ก็ได้ เรามาเริ่มศึกษากับแบบ ง่าย ๆ กับช่องทาง สื่อสาร Serial Port กันก่อน (ไม่ใช่ Mod bus Protocol นะครับ Serial ธรรมดา)
สิ่งที่คุณต้องมี
1.ฺBoard Arduino Nano หรือ UNO พร้อม LCD (แนะนำให้ใช้ I2C LCD ง่าย และ สะดวก ไม่แพง)
2.Mach3 CNC Controller (ตัว Demo ก็ใช้ได้นะครับ) ข้อแนะนำการติดตั้ง ดูได้จาก Link นี้ครับ
ขั้นตอน การทดลอง
ก่อนขั้นตอนนี้ คุณควรเรียนรู้ การทำงานของ Arduino Board ก่อนนะครับ ตาม Link นี้ก่อนนะครับ และ ที่ www.arduino.cc
1.ทำการ เขียน โปรแกรม serial monitor สำหรับ การ monitor จาก mach3
/**
* Displays text sent over the serial port (e.g. from the Serial Monitor) on
* an attached LCD.
*/
#include
#include
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 20, 4);
void setup()
{
lcd.begin();
lcd.backlight();
// Initialize the serial port at a speed of 9600 baud
Serial.begin(9600);
}
void loop()
{
// If characters arrived over the serial port...
if (Serial.available()) {
// Wait a bit for the entire message to arrive
//delay(10);
// Clear the screen
lcd.clear();
// Write all characters received with the serial port to the LCD.
while (Serial.available() > 0) {
lcd.write(Serial.read());
}
}
}
2.ทำการทดสอบ Serial Monitor ด้วย Arduino Monitor Serial port
3.Config Mach3 เพื่อส่งค่า ไป Arduino
4.เขียน macro script ใน Mach3 เพื่อทดสอบ การส่งข้อมูล macro จะอยู่ใน C:\Mach3\macros\Mach3Mill
4.1 ตัวอย่าง การเขียน Macro และ VB Script ซึ่งหาอ่านได้จาก Link ข้างต้น
M3.m1s
rem DoSpinCW()
SendSerial "Spindle_CW"
หรือ macropump สำหรับการส่งค่า ตำแหน่ง X Y Z
macropump.m1s
If getVar(1005) = 0 Then
XV = Format (GetDro(0) , "+000.0000;-000.0000")
YV = Format (GetDro(1) , "+000.0000;-000.0000")
ZV = Format (GetDro(2) , "+000.0000;-000.0000")
AV = Format (GetDro(3) , "+000.0000;-000.0000")
rem SendSerial "?c0?f?a?g"
rem SendSerial "?y0?x00 X: " &XV
rem SendSerial "X Axis: " &XV
rem SendSerial "Y Axis: " &YV
rem SendSerial "Z Axis: " &ZV
SendSerial "Serial Test By Panmaneecnc"
setVar(1005, 1)
setVar(1004, 0)
End If
If getVar(1004) = 10 Then
setVar(1004, 0)
If getVar(1000) <> Getdro(0) Then
XV = Format (GetVar(1000) , "+000.0000;-000.0000")
rem SendSerial "?x04?y0" &XV
SendSerial "Axis X" &XV
setVar(1000, Getdro(0))
End If
If getVar(1001) <> Getdro(1) Then
YV = Format (GetVar(1001) , "+000.0000;-000.0000")
SendSerial "Axis Y" &YV
setVar(1001, getDro(1))
End If
If getVaR(1002) <> Getdro(2) Then
ZV = Format (GetVar(1002) , "+000.0000;-000.0000")
SendSerial "Axis Z" &ZV
setVar(1002, getDro(2))
End If
if getVar(1003) <> Getdro(3) Then
AV = Format (GetVar(1003) , "+000.0000;-000.0000")
SendSerial "Axis A" &AV
setVar(1003, getDro(3))
End If
else
setVar(1004, getVar(1004) + 1)
End If
จากการทดลองนี้ คุณสามารถ ส่งข้อมูลจาก Mach3 ไปควบคุม อุปกรณ์ผ่าน Serial Port ได้ โดยการเขียนโปรแกรมเพิ่มเติมบน Arduino เช่น ควบคุม Clamp , Spindle หรือ อื่น ๆ เท่าที่คุณจินตนาการ ในโอกาสต่อไป เราจะ มาเขียนการติดต่อ โดยใช้ Modbus กันต่อครับ
สิ่งที่คุณต้องมี
1.ฺBoard Arduino Nano หรือ UNO พร้อม LCD (แนะนำให้ใช้ I2C LCD ง่าย และ สะดวก ไม่แพง)
2.Mach3 CNC Controller (ตัว Demo ก็ใช้ได้นะครับ) ข้อแนะนำการติดตั้ง ดูได้จาก Link นี้ครับ
ขั้นตอน การทดลอง
ก่อนขั้นตอนนี้ คุณควรเรียนรู้ การทำงานของ Arduino Board ก่อนนะครับ ตาม Link นี้ก่อนนะครับ และ ที่ www.arduino.cc
1.ทำการ เขียน โปรแกรม serial monitor สำหรับ การ monitor จาก mach3
/**
* Displays text sent over the serial port (e.g. from the Serial Monitor) on
* an attached LCD.
*/
#include
#include
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 20, 4);
void setup()
{
lcd.begin();
lcd.backlight();
// Initialize the serial port at a speed of 9600 baud
Serial.begin(9600);
}
void loop()
{
// If characters arrived over the serial port...
if (Serial.available()) {
// Wait a bit for the entire message to arrive
//delay(10);
// Clear the screen
lcd.clear();
// Write all characters received with the serial port to the LCD.
while (Serial.available() > 0) {
lcd.write(Serial.read());
}
}
}
2.ทำการทดสอบ Serial Monitor ด้วย Arduino Monitor Serial port
4.เขียน macro script ใน Mach3 เพื่อทดสอบ การส่งข้อมูล macro จะอยู่ใน C:\Mach3\macros\Mach3Mill
4.1 ตัวอย่าง การเขียน Macro และ VB Script ซึ่งหาอ่านได้จาก Link ข้างต้น
M3.m1s
rem DoSpinCW()
SendSerial "Spindle_CW"
หรือ macropump สำหรับการส่งค่า ตำแหน่ง X Y Z
macropump.m1s
If getVar(1005) = 0 Then
XV = Format (GetDro(0) , "+000.0000;-000.0000")
YV = Format (GetDro(1) , "+000.0000;-000.0000")
ZV = Format (GetDro(2) , "+000.0000;-000.0000")
AV = Format (GetDro(3) , "+000.0000;-000.0000")
rem SendSerial "?c0?f?a?g"
rem SendSerial "?y0?x00 X: " &XV
rem SendSerial "X Axis: " &XV
rem SendSerial "Y Axis: " &YV
rem SendSerial "Z Axis: " &ZV
SendSerial "Serial Test By Panmaneecnc"
setVar(1005, 1)
setVar(1004, 0)
End If
If getVar(1004) = 10 Then
setVar(1004, 0)
If getVar(1000) <> Getdro(0) Then
XV = Format (GetVar(1000) , "+000.0000;-000.0000")
rem SendSerial "?x04?y0" &XV
SendSerial "Axis X" &XV
setVar(1000, Getdro(0))
End If
If getVar(1001) <> Getdro(1) Then
YV = Format (GetVar(1001) , "+000.0000;-000.0000")
SendSerial "Axis Y" &YV
setVar(1001, getDro(1))
End If
If getVaR(1002) <> Getdro(2) Then
ZV = Format (GetVar(1002) , "+000.0000;-000.0000")
SendSerial "Axis Z" &ZV
setVar(1002, getDro(2))
End If
if getVar(1003) <> Getdro(3) Then
AV = Format (GetVar(1003) , "+000.0000;-000.0000")
SendSerial "Axis A" &AV
setVar(1003, getDro(3))
End If
else
setVar(1004, getVar(1004) + 1)
End If
หากคุณชอบกดติดตามเราได้ที่ www.facebook.com/panmaneeminicnc
ความคิดเห็น
แสดงความคิดเห็น