[EN] Using the DHT22/DHT11 Temperature and Humidity Sensor Module with ESP8266

This article uses the DHT22 and DHT11 temperature and humidity measurer modules with Python. They are sensor modules that operate using a single signal cable which will save the microcontroller’s port connection. In addition, MicroPython has a library prepared for DHT22 and DHT11 implementation, making it convenient, time-saving and reduce errors that may be caused by manual programming.

There are 3 examples in this article: code17-1 is a normal reading of values, but code17-2 is a loop to read again. By finding the highest and lowest values and display on the LCD module as shown in Figure 8 and example code17-3 showing the average value of temperature and humidity.

Figure 1 Result from code17-1
Read More

[TH] สร้างและอ่าน QR Code

บทความนี้เป็นแล็บหนึ่งในการเรียนการสอนวิชาปัญญาประดิษฐ์เพื่อประยุกต์ใช้การสร้าง QR Code จากไลบรารี segno การถอดรหัส QR Code จากไลบนรารี OpenCV การตรวจสอบข้อความว่าเป็น URL หรือไม่ และการเปิดเว็บบราวเซอร์เพื่อเข้าถึง URL ที่ถอดรหัสได้ด้วยไลบรารี webbrowser

Read More

[TH] Unity Ep6 เขียนโค้ดเดินหน้า ถอยหลัง และกระโดด

บทความนี้เป็นตัวอย่างการเขียนโค้ด C# เพื่อขยับวัตถุวงกลมในหน้าจอให้เดินหน้า ถอยหลัง และกระโดด ตามลักษณะพื้นฐานของเกมแบบแพลตฟอร์ม ซึ่งเป็นหนึ่งในหลายตัวอย่างที่นำมาใช้ในการสอนวิชาการสื่อสารข้อมูลฯ สำหรับพัฒนาเกมแบบผู้เล่นหลายคน

Read More

[TH] Godot: C# Script Ep.1

          เกมเอนจิน Godot มี 2 ระบบ คือ ระบบที่ใช้งาน GDScript ที่มีหลักภาษาคล้ายกับภาษาไพธอนเป็นภาษาสำหรับควบคุมการทำงาน กับระบบที่ใช้ภาษา C# ในการทำงาน โดยขั้นตอนพื้นฐานในการใช้งานจะเป็นดังนี้

                    1. สร้างโครงงานใหม่ด้วยการคลิกเลือก New Project

                    2. กำหนดที่เก้บโครงงาน และตั้งชื่อโครงงาน หลังจากนั้นคลิกที่ Create Folder แล้วคลิกที่ปุ่ม Create&Edit เพื่อเข้าสู่โหมดการแก้ไขโครงงาน

                    3. เลือกการสร้าง Scene เป็น Node2D และบันทึกไฟล์ฉาก (Scene) เอาไว้

                    4. ใน Tab ชื่อ Inspector ให้เลือกสร้างสคริปต์ด้วยการคลิกที่ Script และเลือก New Script

                    5. เลือกภาษาเป็น C# และคลิก Create เพื่อสร้างไฟล์ที่มีนามสกุลเป็น .cs

                    6. โครงสร้างของไฟล์เป็นดังโปรแกรม 1-10 จะพบรายการทรัพยากรดังในภาพที่ 1-4 อันประกอบไปด้วยภาพไอคอนของโปรแกรม ไฟล์ฉากที่สร้างขึ้น (ในภาพตั้งชื่อเป็น MainScene.tscn) และไฟล์ภาษา C# (ชื่อ MainScene.cs)

Read More

[TH] พื้นฐาน C#

บทความมนี้กล่าวถึงพื้นฐานการเขียนโปรแกรมภาษา C# ที่นำไปใช้ในการเรียนการสอนในรายวิชา การพัฒนาเกม และคณิตร์ศาสตร์คอมพิวเตอร์ โดยเริ่มจากเรื่องของจำนวน การดำเนินการกับจำนวน เงื่อนไข การทำซ้ำ โปรแกรมย่อย อันนำไปสู่การประยุกต์ใช้คณิตศาสตร์เข้ากับเกมหรือนำไปใช้กับการเขียนโปรแกรมด้วย Unity ต่อไป ด้วยเครื่องมือการเขียนโปรแกรมอย่าง Visual Studio, Unity หรือ Godot mono เป็นต้น

Read More

[TH] PyTk

บทความนี้กล่าวถึง pytk อันเป็นไลบรารีเชื่อมประสานกับผู้ใช้แบบกราฟิกส์ หรือ GUI (Graphics User Interface) ของภาษาไพธอนที่เรียกใช้ tkinter (TK Interface) ทำให้สามารถเขียนโปรแกรม GUI ที่ทำงานได้ทั้งระบบปฏิบัติการ Windows, Linux และ macOS โดยการทำงานของ tkinter ของไพธอนเป็นการเชื่อมประสานกับไลบรารี Tcl/Tk อีกชั้นหนึ่ง และบทความนี้ใช้ Thonny เป็น IDE ในการเขียนโปรแกรมตัวอย่าและติดตั้งไลบรารี (อ่านบทความการใช้ Thonny)

การใช้งานจะต้องมีไลบรารี pytk ซึ่งสามารถเขียนโค้ดเพื่อทดสอบการติดตั้งไลบรารีด้วยโค้ดโปรแกรมภาษาไพธอนดังต่อไปนี้

try:
    import tkinter as tk
except ImportError:
    import sys
    print("ไม่พบไลบรารี tkinter!!!")
    sys.exit(0)
print("พร้อมสำหรับ tkinter")
Read More

[TH] Thonny 4

Thonny เป็นเครื่องมือประเภทสภาพแวดล้อมแบบบูรณาการ หรือ IDE (Integrated development environment) ที่พัฒนาโดยชาวอสโตเนียชื่อ Aivar Annamaa ในปี ค.ศ. 2015 ภายใต้สิทธิ์การใช้งานแบบเปิดเผยรหัสโปรแกรม (Open Source) แบบ MIT และคุณสมบัติของโปรแกรมนั้นครอบคลุมการเขียนโค้ด ตรวจสอบโค้ด บริหารจัดการไลบรารีของภาษาไพธอน และรันโปรแกรมภาษาไพธอนที่เขียนขึ้นทำให้เป็นซอฟต์แวร์ที่ทำงานในส่วนของการเขียนและทดสอบการทำงานที่ใช้งานง่ายเหมาะสมกับผู้เริ่มต้น

          การติดตั้ง Thonny ทำได้โดยดาวน์โหลดไฟล์ชื่อ thonny-xxl-4.1.1.exe จากเว็บไซต์ thonny.org ดังภาพที่ ก-1

ภาพที่ ก-1 หน้าจอเว็บไซต์ thonny.org

Read More

[EN] Binary Search Tree

This article is about programming C/C++ language with Arduino Nano, Arduino Uno, LGT8F328P [NANO F328P-C] and ET-BASE AVR EASY32U4 (Figure 1) or other boards and platforms using C language for learning to code another type of data structure management program that has different storage and management methods, called BST or Binary Search Tree, as in Figure 2, which is a structure that can be applied to collecting data with attributes in which the data on the left node is less than current node and the right node is greater than current node or the opposite, the left node is greater and the right noe is less. Thus, searching for data in the event that the tree is balanced both left and right on the BST structure saves time or number of searches per round by half of available data, for example, there are 100 data sets in the first round, if the current node is not what you’re looking for it, the choice left is to find from the left or right node. This selection causes the data of the other side to be ignored or cut it in half approximately but if the Binary Search Tree is unbalanced, the search speed will not be much different from the Sequential Search.

ET-BASE AVR EASY32U4
Figure 1 ET-BASE AVR EASY32U4
Read More

[EN] Doubly Linked-List

This article is about programming C/C++ language with Arduino Nano, Arduino Uno, LGT8F328P [NANO F328P-C], ET-BASE AVR EASY32U4 or other boards and platforms that use C language to store temperature/humidity data from the DHT11 sensor (Figure 1) with a dual linked list data structure. The basics of memory reservation, access, memory deallocation can be read in the previous article (Singly Linked List).

Figure 1 Arduino Uno and DHT11
Read More

[TH] Binary Search Tree

บทความนี้เป็นการเขียนโปรแกรมภาษา C/C++ กับบอร์ด Arduino Nano, Arduino Uno, LGT8F328P [NANO F328P-C] และ ET-BASE AVR EASY32U4 (ภาพที่ 1) หรือบอร์ดอื่น ๆ และแพล็ตฟอร์มอื่น ๆ ที่ใช้ภาษา C เพื่อเรียนรู้การเขียนโปรแกรมจัดการโครงสร้างข้อมูล (Data Structure) อีกประเภทหนึ่งซึ่งมีวิธีการจัดเก็บและจัดการที่แตกต่างกันไปอันมีชื่อว่าต้นไม้แบบ BST หรือ Binary Search Tree ดังในภาพที่ 2 ซึ่งเป็นโครงสร้างที่สามารถนำไปประยุกต์เกี่ยวกับการเก็บข้อมูลที่มีคุณลักษณะที่ข้อมูลทางกิ่งด้านซ้ายมีค่าที่น้อยกว่าตัวเอง และกิ่งด้านขวามีค่ามากกว่าต้นเอง หรือทำตรงกันข้ามคือกิ่งซ้ายมีค่ามากกว่า และกิ่งด้านขวามีค่าน้อยกว่า ทำให้การค้นหาข้อมูลในกรณีที่ต้นไม้มีความสมดุลย์ทั้งทางซ้ายและทางขวาบนโครงสร้าง BST ประหยัดเวลาหรือจำนวนครั้งในการค้นหาลงรอบละครึ่งหนึ่งของข้อมูลที่มี เช่น มีข้อมูล 100 ชุด ในรอบแรกถ้าตัวเองยังไม่ใช่ข้อมูลที่กำลังค้นหา จะเหลือทางเลือกให้หาจากกิ่งทางซ้ายหรือขวา ซึ่งการเลือกทำให้ข้อมูลของอีกฝั่งนั้นไม่ถูกพิจารณา หรือตัดทิ้งไปครึ่งหนึ่งโดยประมาณ แต่ถ้าเป็นกรณีที่ Binary Search Tree นั้นขาดความสมดุลย์จะส่งผลให้การค้นหามีความเร็วไม่แตกต่างกับการค้นหาแบบลำดับ (Sequential Search) เท่าใดนัก

ET-BASE AVR EASY32U4
ภาพที่ 1 บอร์ด ET-BASE AVR EASY32U4
Read More