ทฤษฏี เนื้อหาที่เกี่ยวข้อง
1. ESP8266 on NodeMCUDeaware เอา NodeMCU devkit มาให้ลองเล่น บอร์ดตัวนี้เป็นบอร์ดที่รวมเอา ESP8266 (ESP-12) + USB to Serial + NodeMCU firmware เข้าไว้ด้วยกัน ทาให้การใช้งานง่ายมากขึ้น ไม่ต้องมีอุปกรณ์ต่อพ่วงเยอะ แถมมี GPIO เพิ่มเป็น 10 พอร์ท เพียงพอต่อการใช้งาน สาหรับ NodeMCU devkit ที่ได้มาเป็นบอร์ดเปล่าๆ ใช้ AT Command ในการสั่งงาน ชีวิตไม่อิสระเท่าไร แต่ทางผู้พัฒนา Board ก็มี NodeMCU Firmware ให้คุณสามารถเขียน Lua ใส่ลงไปได้ ทาให้การใช้งานง่ายมากขึ้น
ตัว devkit มี port GPIO มาให้อยู่ 10 port เป็นแบบ Digital และที่สาคัญมี Wifi Serial มาให้ด้วย เพราะฉนั้นขอให้มี Wifi Router ต่ออินเตอร์เน็ตได้ คุณก็สามารถสร้างโครงงาน Internet of Thing ได้ง่ายๆ จบในบอร์ดเดียว
ปัจจุบันสามารถเขียน Software ด้วย Arduino IDE ยิ่งทาให้ผู้พัฒนาทุกคนเริ่มจะสนใจเป็นอีกหลายเท่าตัว โดย I/O ของบอร์ด มีดังนี้
• GPIO 13 ขา
• ADC (10 bit) 1 ขา
• WiFi a/b/g
• การสื่อสารแบบ Serial (Tx,Rx)
2. MAX7219 Display
- ใช้แรงดันไฟเลี้ยงได้ในช่วง 4V ถึง 5.5V
- ขา LOAD (/CS), CLK, DIN, DOUT เป็นขาสำหรับการเลื่อนบิตข้อมูลตามจังหวะสัญญาณ CLK เข้าที่ขา DIN และมีข้อมูลออกที่ขา DOUT
- ขา DIG0, ..., DIG7 สามารถรับกระแสได้สูง (Current Sink) และนำไปใช้ต่อกับขา Common Cathode เพื่อเลือก DIGIT (เลือกให้หลักใดแสดงผล หรือ "active")
- ขา SEG_A, .., SEG_G, SEG_DP เป็นขาสำหรับกำหนดสถานะติด-ดับของ LED ที่ตรงกับแต่ละ Segment
- ขา ISET ให้ต่อตัวต้านทาน (เช่น 10k โอห์ม) ไปยัง VCC ใช้กำหนดกระแสสูงสุดของแต่ละ Segment (LED)
- library สำหรับ MAX7219 Display MAX7219DISPLAY(จำเป็นต้องติดตั้ง)
3. HDC1080 High Accuracy Humidity-Temperature Sensor Module
Description
The HDC1080 is a digital humidity sensor with integrated temperature sensor that provides excellent
measurement accuracy at very low power. The HDC1080 operates over a wide supply range, and is a low
cost, low power alternative to competitive solution in a wide range of common applications. The humidity and
temperature sensors are factory calibrated.
Features
• Relative Humidity Accuracy ±2% (typical)
• Temperature Accuracy ±0.2°C (typical)
• Excellent Stability at High Humidity
• 14 Bit Measurement Resolution
• 100 nA Sleep Mode Current
• Average Supply Current:
o 710 nA @ 1sps, 11 bit RH Measurement
o 1.3 μA @ 1sps, 11 bit RH and Temperature Measurement
• Supply Voltage 2.7 V to 5.5 V
• Small 3 mm × 3 mm Device Footprint
• I2C Interface
4. Lua Scrip
ภาษา Lua (pronounced 'LOO-ah' หรือออกเสียงว่า 'ลัว' หรือ 'ลู อ่า' ในภาษาโปรตุเกส) อาจไม่เป็นที่รู้จักสำหรับโปรแกรมเมอร์ทั่วไปในวงกว้าง แต่ก็เป็นภาษาคอมพิวเตอร์ที่น่าสนใจ และสามารถนามาใช้งานได้ ลองมาทำ ความรู้จักกับภาษานี้ โดยเขียนสรุปเป็นข้อๆ ดังนี้
• Lua เป็นภาษาประเภท Scripting / Interpreted Language หรือภาษาสคริปต์ (อยู่ในประเภทเดียวกับภาษา อย่างเช่น Python)
• มีต้นกำเนิดมาจากทีมพัฒนาในสถาบันการศึกษาแห่งหนึ่งในประเทศบราซิล (Pontifical Catholic University of Rio de Janeiro, Brazil) ในราวปีค.ศ. 1993
• Lua script จะถูกแปลงให้เป็น Bytecode ตามรูปแบบคำสั่งของคอมพิวเตอร์เสมือน (Virtual Machine)
สำหรับภาษานี้ (เช่นเดียวกับกรณีของ Python และ Java ที่มีการทา งานในลักษณะนี้)
• เป็นภาษาที่ชนิดของข้อมูลสำหรับตัวแปรปรับเปลี่ยนได้ (Dynamically-typed language)
• มีชนิดข้อมูลพื้นฐานคือ boolean (true,false), numbers (integer & double-precision floating point) และstring
• มีโครงสร้างข้อมูลอย่างเช่น อาร์เรย์(array) ตาราง(table) ซึ่งเป็น associative array และ เซต(set)
• มีการจัดการหน่วยความจำ เช่น การจองและคืนหน่วยความจำในขณะทำงาน (automatic memory
management & garbage collection)
• ตัวแปลคำสั่ง ของภาษา Lua (Lua Interpreter) มีขนาดเล็ก(small & light-weight) และเขียนด้วยภาษา C
• เป็นซอฟต์แวร์ประเภท Opensource (MIT license สำหรับเวอร์ชัน 5.x) ดังนั้นจึงใช้งานได้ฟรี
• ใช้ได้หลายแพลตฟอร์ม(multi-platform programming language)อย่างเช่น Windows,Linux, Mac,OSX
• มีการใช้งานกับบอร์ดไมโครโทรลเลอร์ได้ อย่างเช่น ESP8266/NodeMCU, WiFiMCU/EMW3165 เป็นต้น
• สามารถเรียกใช้จากภาษาอื่นได้ (embeddable) มีการนำไปใช้ในการพัฒนาเกมส์ หรือการพัฒนา Mobile Apps อย่างเช่น Corona SDK
• อุปกรณ์เครือข่าย อย่างเช่น Wireless Router ที่ใช้ระบบปฏิบัติการ OpenWrt ซึ่งเป็น Linux และมีการใช้โปรแกรม Luci ซึ่งพัฒนาด้วยภาษา Lua สำหรับการจัดการผ่านหน้าเว็บเพื่อตั้งค่าต่างๆ ของระบบ (Web
configuration interface)
1.Node MCU
1.1 ติดตั้ง Arduino IDE บน ESP8266 ตามลิงค์นี้ →link
1.2 ทดสอบ โปรแกรมด้วย file→example→basic→blink
1.3. วิธีเชื่อมต่อ Node MCU เข้ากับระบบ Network →link
1.4. การใช้งาน TCP/IP → link
1.5.การใช้งาน GPIO → link
1.6.web server →link
2. Node MCU + DISPLAY
2.1 Add Lib : https://github.com/squix78/MAX7219LedMatrix
2.2 Wiring MAX7219_7segment {Vcc, GND, DIN, CS, CLK} {3.3V, GND, D7, D8, D5}
2.3 Open File → Example → MAX7219LedMatrix-master → AnimateText
2.4 Change { NUMBER_OF_DEVICES 1, CS_PIN D8 } and Click Upload
2.5 Using Test Code for TestMax7219_1
2.6 Using Test Code for TestMax7219_2
3. NodeMCU + HDC1080 Sensor
3.1 Add Lib : https://github.com/closedcube/ClosedCube_HDC1080_Arduino
3.2 ทดสอบโปรแกรม File >> Example >> ClosedCube HDC1080 >>hdc1080demo
Description
The HDC1080 is a digital humidity sensor with integrated temperature sensor that provides excellent
measurement accuracy at very low power. The HDC1080 operates over a wide supply range, and is a low
cost, low power alternative to competitive solution in a wide range of common applications. The humidity and
temperature sensors are factory calibrated.
Features
• Relative Humidity Accuracy ±2% (typical)
• Temperature Accuracy ±0.2°C (typical)
• Excellent Stability at High Humidity
• 14 Bit Measurement Resolution
• 100 nA Sleep Mode Current
• Average Supply Current:
o 710 nA @ 1sps, 11 bit RH Measurement
o 1.3 μA @ 1sps, 11 bit RH and Temperature Measurement
• Supply Voltage 2.7 V to 5.5 V
• Small 3 mm × 3 mm Device Footprint
• I2C Interface
4. Lua Scrip
ภาษา Lua (pronounced 'LOO-ah' หรือออกเสียงว่า 'ลัว' หรือ 'ลู อ่า' ในภาษาโปรตุเกส) อาจไม่เป็นที่รู้จักสำหรับโปรแกรมเมอร์ทั่วไปในวงกว้าง แต่ก็เป็นภาษาคอมพิวเตอร์ที่น่าสนใจ และสามารถนามาใช้งานได้ ลองมาทำ ความรู้จักกับภาษานี้ โดยเขียนสรุปเป็นข้อๆ ดังนี้
• Lua เป็นภาษาประเภท Scripting / Interpreted Language หรือภาษาสคริปต์ (อยู่ในประเภทเดียวกับภาษา อย่างเช่น Python)
• มีต้นกำเนิดมาจากทีมพัฒนาในสถาบันการศึกษาแห่งหนึ่งในประเทศบราซิล (Pontifical Catholic University of Rio de Janeiro, Brazil) ในราวปีค.ศ. 1993
• Lua script จะถูกแปลงให้เป็น Bytecode ตามรูปแบบคำสั่งของคอมพิวเตอร์เสมือน (Virtual Machine)
สำหรับภาษานี้ (เช่นเดียวกับกรณีของ Python และ Java ที่มีการทา งานในลักษณะนี้)
• เป็นภาษาที่ชนิดของข้อมูลสำหรับตัวแปรปรับเปลี่ยนได้ (Dynamically-typed language)
• มีชนิดข้อมูลพื้นฐานคือ boolean (true,false), numbers (integer & double-precision floating point) และstring
• มีโครงสร้างข้อมูลอย่างเช่น อาร์เรย์(array) ตาราง(table) ซึ่งเป็น associative array และ เซต(set)
• มีการจัดการหน่วยความจำ เช่น การจองและคืนหน่วยความจำในขณะทำงาน (automatic memory
management & garbage collection)
• ตัวแปลคำสั่ง ของภาษา Lua (Lua Interpreter) มีขนาดเล็ก(small & light-weight) และเขียนด้วยภาษา C
• เป็นซอฟต์แวร์ประเภท Opensource (MIT license สำหรับเวอร์ชัน 5.x) ดังนั้นจึงใช้งานได้ฟรี
• ใช้ได้หลายแพลตฟอร์ม(multi-platform programming language)อย่างเช่น Windows,Linux, Mac,OSX
• มีการใช้งานกับบอร์ดไมโครโทรลเลอร์ได้ อย่างเช่น ESP8266/NodeMCU, WiFiMCU/EMW3165 เป็นต้น
• สามารถเรียกใช้จากภาษาอื่นได้ (embeddable) มีการนำไปใช้ในการพัฒนาเกมส์ หรือการพัฒนา Mobile Apps อย่างเช่น Corona SDK
• อุปกรณ์เครือข่าย อย่างเช่น Wireless Router ที่ใช้ระบบปฏิบัติการ OpenWrt ซึ่งเป็น Linux และมีการใช้โปรแกรม Luci ซึ่งพัฒนาด้วยภาษา Lua สำหรับการจัดการผ่านหน้าเว็บเพื่อตั้งค่าต่างๆ ของระบบ (Web
configuration interface)
การทดลอง
1.1 ติดตั้ง Arduino IDE บน ESP8266 ตามลิงค์นี้ →link
1.2 ทดสอบ โปรแกรมด้วย file→example→basic→blink
1.3. วิธีเชื่อมต่อ Node MCU เข้ากับระบบ Network →link
1.4. การใช้งาน TCP/IP → link
1.5.การใช้งาน GPIO → link
1.6.web server →link
2. Node MCU + DISPLAY
2.1 Add Lib : https://github.com/squix78/MAX7219LedMatrix
2.2 Wiring MAX7219_7segment {Vcc, GND, DIN, CS, CLK} {3.3V, GND, D7, D8, D5}
2.3 Open File → Example → MAX7219LedMatrix-master → AnimateText
2.4 Change { NUMBER_OF_DEVICES 1, CS_PIN D8 } and Click Upload
2.5 Using Test Code for TestMax7219_1
2.6 Using Test Code for TestMax7219_2
3. NodeMCU + HDC1080 Sensor
3.2 ทดสอบโปรแกรม File >> Example >> ClosedCube HDC1080 >>hdc1080demo
คำถามท้ายการทดลอง
1. ต้องการแสดงข้อความ
2.ใช้ Arduino IDE ในการพัฒนาโปรแกรมให้อ่านอุณหภูมิจากเซ็นเซอร์แล้วแสดงผลที่ MAX7219_7Segment Display โดยมีรูปแบบดังรูป
เอกสาร แหล่งข้อมูลอ้างอิง
ref: ThaiEasyElec
ref: EmbendedSheet
|
ความคิดเห็น
แสดงความคิดเห็น