การสื่อสารจัดเก็บข้อมูลอุตสาหกรรมด้วย Lambda Board และ แสดงผลแบบ Smart HMI (Human Machine Interface)
การสื่อสารจัดเก็บข้อมูลอุตสาหกรรมด้วย Lambda Board และ แสดงผลแบบ Smart HMI (Human Machine Interface)
รายละเอียด : วันพฤหัสบดีที่ 23 มิ.ย. 2559 เวลา 13:30-16:30น. ห้อง MR221ศูนย์นิทรรศการและ ประชุมไบเทค (BITEC)

ก่อนอื่นต้องขอขอบพระคุณผู้ใหญ่ใจดีทุกๆท่านเลยครับ ที่จัดงานดีๆ แบบนี้ขึ้นมา
จากผมได้ไป อบรม เกี่ยวกับการนำเอา Arduino มาประยุกต์ใช้งานกับจอ Human Machine Interface(HMI) สำหรับเป็นตัวเก็บข้อมูล และนำไปประยุกต์ใช้ในอุตสหกรรมได้ เลยอยากจะนำความรู้ที่ได้มาเผยแพร่ให้กับทุกๆท่านได้ทราบ มาเริ่มเนื้อหาที่ผมไปอบรมมากันเลยดีกว่าครับ
หลักๆ ก็จะมีอยู่สองส่วนครับ
1. Arduino ที่โปรแกรมจำลองการส่ง ข้อมูล แบบ Modbus (Modbus คืออะไร)
- ได้นำ Arduino มาใช้งานร่วมกับ PLC ในอุตสาหกรรม
- ได้ศึกษาการติดต่อสื่อสารแบบ Modbus มากขึ้น
2. ส่วนหน้าจอแสดงผล HMI โดยใช้โปรแกรม SKWorkshop (HMI คืออะไร)
- ได้เรียนรู้วิธีสร้างหน้า UI บนจอ HMI เพื่อติดต่อกับ Arduino ด้วย Modbus Protocol เบื้องต้น

>>>ก่อนอื่นเตรียมไฟร์ที่จะใช้ก่อนครับ โดยเข้าไปโหลดตามลิ้งค์ข้างล่างนี้เลยครับ
https://drive.google.com/folderview?id=0B2-9JHfO97K3TGVabDVsay1HdXM&usp=sharing
เมื่อโหลดไฟร์เสร็จแล้วครับมาเริ่มติดตั้งโปรแกรมกันครับ
เข้าไปที่ File และทำการติดตั้งไฟร์ Modbus Poll Setup 64Bit (Next only)

เข้าไปที่ File\HMI-Arduino\HMI และทำการติดตั้งไฟร์ setup_SK 2015-9-16 (Next only)

ก็จะได้โปรแกรมที่ใช้ 2 ตัว ดังรูปครับ

< Modbus Poll เป็นโปรแกรมที่ใช้สำหรับดูข้อมูลของ Protocol Modbus (ใช้ได้ 30 วัน)
< SKWorkshop เป็นโปรแกรมออกแบบหน้าจอสำหรับจอHMIสามารถจำลองการออกแบบได้
ขั้นตอนถัดไปมาเตรียมทางฝั่ง Arduino กันบ้างครับ (ลง Arduino IDE ให้เรียบร้อย)
และทำการติดตั้ง Library Modbus จาก File ที่ Download มา
นำไปไว้ใน โฟร์เดอร์ Library ของ Arduino
เสร็จแล้วก็เปิด Example เลยครับ
จากนั้นเพิ่ม Code นิดหน่อยครับ มาอธิบาย Code กันสักนิดดีกว่า
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <modbus.h> | |
#include <modbusDevice.h> | |
#include <modbusRegBank.h> | |
#include <modbusSlave.h> | |
/* | |
This example code shows a quick and dirty way to get an | |
arduino to talk to a modbus master device with a | |
device ID of 1 at 9600 baud. | |
*/ | |
//Setup the brewtrollers register bank | |
//All of the data accumulated will be stored here | |
modbusDevice regBank; | |
//Create the modbus slave protocol handler | |
modbusSlave slave; | |
void setup() | |
{ | |
//Assign the modbus device ID. | |
regBank.setId(1); | |
/* | |
modbus registers follow the following format | |
00001-09999 Digital Outputs, A master device can read and write to these registers | |
10001-19999 Digital Inputs, A master device can only read the values from these registers | |
30001-39999 Analog Inputs, A master device can only read the values from these registers | |
40001-49999 Analog Outputs, A master device can read and write to these registers | |
Analog values are 16 bit unsigned words stored with a range of 0-32767 | |
Digital values are stored as bytes, a zero value is OFF and any nonzer value is ON | |
It is best to configure registers of like type into contiguous blocks. this | |
allows for more efficient register lookup and and reduces the number of messages | |
required by the master to retrieve the data | |
*/ | |
//กำหนด Address ต่างๆใน modbus | |
//Add Digital Output registers 00001-00016 to the register bank | |
regBank.add(1); | |
regBank.add(2); | |
regBank.add(3); | |
regBank.add(4); | |
regBank.add(5); | |
regBank.add(6); | |
regBank.add(7); | |
regBank.add(8); | |
regBank.add(9); | |
regBank.add(10); | |
regBank.add(11); | |
regBank.add(12); | |
regBank.add(13); | |
regBank.add(14); | |
regBank.add(15); | |
regBank.add(16); | |
//Add Digital Input registers 10001-10008 to the register bank | |
regBank.add(10001); | |
regBank.add(10002); | |
regBank.add(10003); | |
regBank.add(10004); | |
regBank.add(10005); | |
regBank.add(10006); | |
regBank.add(10007); | |
regBank.add(10008); | |
//Add Analog Input registers 30001-10010 to the register bank | |
regBank.add(30001); | |
regBank.add(30002); | |
regBank.add(30003); | |
regBank.add(30004); | |
regBank.add(30005); | |
regBank.add(30006); | |
regBank.add(30007); | |
regBank.add(30008); | |
regBank.add(30009); | |
regBank.add(30010); | |
//Add Analog Output registers 40001-40020 to the register bank | |
regBank.add(40001); | |
regBank.add(40002); | |
regBank.add(40003); | |
regBank.add(40004); | |
regBank.add(40005); | |
regBank.add(40006); | |
regBank.add(40007); | |
regBank.add(40008); | |
regBank.add(40009); | |
regBank.add(40010); | |
regBank.add(40011); | |
regBank.add(40012); | |
regBank.add(40013); | |
regBank.add(40014); | |
regBank.add(40015); | |
regBank.add(40016); | |
regBank.add(40017); | |
regBank.add(40018); | |
regBank.add(40019); | |
regBank.add(40020); | |
/* | |
Assign the modbus device object to the protocol handler | |
This is where the protocol handler will look to read and write | |
register data. Currently, a modbus slave protocol handler may | |
only have one device assigned to it. | |
*/ | |
slave._device = ®Bank; | |
// Initialize the serial port for coms at 9600 baud | |
slave.setBaud(9600); | |
} | |
void loop() | |
{ | |
//put some data into the registers | |
regBank.set(1, 1); | |
regBank.set(2, 1); | |
regBank.set(3, 0); | |
regBank.set(4, 1); | |
regBank.set(5, 1); | |
regBank.set(6, 0); | |
regBank.set(7, 1); | |
regBank.set(8, 0); | |
regBank.set(10001, 1); | |
regBank.set(10002, 1); | |
regBank.set(10003, 1); | |
regBank.set(10004, 1); | |
regBank.set(10005, 0); | |
regBank.set(10006, 0); | |
regBank.set(10007, 0); | |
regBank.set(10008, 0); | |
regBank.set(30001,1); | |
regBank.set(30002,2); | |
regBank.set(30003,3); | |
regBank.set(30004,4); | |
regBank.set(30005,5); | |
regBank.set(30006,6); | |
regBank.set(30007,7); | |
regBank.set(30008,8); | |
regBank.set(30009,9); | |
regBank.set(30010,10); | |
regBank.set(40001,1); | |
regBank.set(40002,2); | |
regBank.set(40003,2); | |
regBank.set(40004,4); | |
regBank.set(40005,5); | |
regBank.set(40006,6); | |
regBank.set(40007,7); | |
regBank.set(40008,8); | |
regBank.set(40009,9); | |
regBank.set(40010,10); | |
regBank.set(4,0); | |
while(1) | |
{ | |
//put a random number into registers 1, 10001, 30001 and 40001 | |
//สุ่มค่าใน Address ต่างๆ | |
regBank.set(1, (byte) random(0, 2)); | |
regBank.set(10001, (byte) random(0, 2)); | |
regBank.set(30001, (word) random(0, 32767)); | |
regBank.set(40001, (word) random(0, 32767)); | |
analogWrite(13,regBank.get(40002)); | |
//#######################เพิ่มส่วนี้เข้าไป################################## | |
int DO8 = regBank.get(4); | |
if (DO8 <= 0 && digitalRead(13) == HIGH)digitalWrite(13,LOW); | |
if (DO8 >= 1 && digitalRead(13) == LOW)digitalWrite(13,HIGH); | |
//#################################################################### | |
slave.run(); | |
} | |
} |
จากนั้นก็ทำการ upload ลงบอร์ดเลยครับ(ผมใช้บอร์ด Arduino Uno ธรรมดาครับ)
งั้นลองมาดูข้อมูลที่ส่งมาจากบอร์ดกันหน่อยดีกว่าว่ามีหน้าตาอย่างไร เริ่มมมม
เปิดโปรแกรม Modbus Poll เลยครับ จากนั้นกด Connection / Connect..
คลิกไปที่ Setup/Read write Definition
อ่านค่าใน Address 40001(ค่าที่ได้ก็จะ Random ตามใน Code)
มาลองเขียนข้อมูลเล่นกันดูครับ คลิกที่ Functions/06:White Single register
ขั้นตอนถัดไปเรามาเปิดโปรแกรม SKWorkshop กันครับ
New Project กันเลยครับ เลือก Model ละกด Next เรื่อยๆเลยครับ
Set ค่าเพื่อ Link กับบอร์ด


สร้างปุ่มเปิด/ปิด LED บนบอร์ด
ตั้งค่าตามนี้เลยนะครับ อย่าลืมเปลี่ยน ข้อความใน Label ด้วยนะ เดี่ยวจะงง ว่าเป็น On หรือ Off

ทำปุ่ม OFF ต่อเลยครับ

ลอง Simulation โล้ดดดด


เปิด/ปิด ไฟได้แล้วววว ^ ^ ถือเป็นการเริ่มต้นที่ดี

สำหรับบทความนี้ สามารถนำไปประยุกต์ใช้ในอุตสาหกรรมที่มีระบบ Modbus Protocol ของอุปกรณ์ PLC
หรือระบบต่างในอุตสาหกรรมได้ และหวังว่าบทความนี้จะเป็นประโยชน์ต่อทุกๆท่าน นะครับ
สามารถสั่งซื้อจอได้ที่ ลิ้งค์นี้เลยครับ (ผมไม่ได้ค่าโฆษณานะครับ ^^)
If you have any question?
please contact us.
Facebook : https://www.facebook.com/ThaiEmbedded
Youtube Channel : http://www.youtube.com/tesrchannel
Youtube Channel : http://www.youtube.com/tesrchannel
Blog : http://tesrteam.blogspot.com/
Email : pongpiphat.tach@gmail.com
line id : pongpiphat
Tel. 083-1858526
Email : pongpiphat.tach@gmail.com
line id : pongpiphat
Tel. 083-1858526
ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible
โปรแกรมไม่สามารถร Simulationได้ครับ
ตอบลบ