[EN] Binary Search Tree data structure programming with Python.

In the previous article, programming to implement queue-based data structures was introduced. In this article, we introduce programming to manage another type of data structure which has different storage and management methods called BST tree or Binary Search Tree, as shown in Figure 1, which is a structure that can be applied to data collection with attributes in which the data in the left branch is less than itself and the right branch is greater than itself or the opposite, i.e. the left branch has a greater value and the right branch is less. It enables searching for data in cases where the tree is balanced on the left and right in the BST structure, saving half the time or number of search times per round of available data, e.g. 100 data sets in the first round if it is not the information you are looking for will be left with a choice to find from the left or right branches which the selection causes the information of the other side is not considered or cut off approximately half. However, if the Binary Search Tree is out of balance, the search speed is not much different from the sequential search.

In this article, we use Python that works on either a Python 3 or MicroPython interpreter to store the data, adding information ,searching for information as an example of further development.

BST : Binary Search Tree
Figure 1 BST
Read More

[EN] Understand and use the ESP32-C3

We have been using the esp8266, especially the esp-01 and esp-01s modules, to manage the sensor network for quite some time and with the limitation in terms of the number of pins used, the system must be designed to work with STM32F103C8T6 or STM32F401CCU6/STM32F411CEU6. To ensure stable operation, no problems with the esp8266’s WDT were encountered, and over time, espressif released several other microcontrollers such as esp32, esp32-s2, esp32-c3 and esp32-s3.

We have tested and used esp32 almost all the time until esp32-s2 with LILYGO board made us try to order it. The main problem is that the development tools are very late. However, as of now, espressif has released a development kit for Arduino or Arduino Core for ESP32 version 2.0 with support for esp32 esp32-s2 and esp32c3, making it work with ESP32 and ESP32-S2. We got the esp-c3-32s board so this article was born.

This article is compiled from the datasheet of ESP32-C3 WROOM-02, in this article we use the board as shown in Figure 1. The example program is to drive an RGB LED on the board to work by using Arduino Core for ESP32 and the improved ESP-IDF from the article in Ep. 3

(Figure. 1 ESP32-C3)
Read More

[EN] Queue Data Structure

This article introduces the use of the list class in Micropython as a queue data structure with a limited number of members. It works according to the FIFO (First-In-First-Out) principle, which can be applied in a variety of applications, such as being used as a storage, and when the data is full but we need to insert new data, the old data must be pop out. The example in this article uses the dCore-miniML board (Figure 1) to read the temperature of the chip and store it in a Queue structure and display it in a bar graph and Micropython implemented firmware version 1.16 (2021-06-23) for the ESP Module (SPIRAM).

(Figure. 1 An example of drawing a graph with data stored in a queued data structure)
Read More

[TH] Binary Search Tree data structure programming with Python.

ในบทความก่อนหน้านี้ได้แนะนำการเขียนโปรแกรมเพื่อใช้โครงสร้างข้อมูลแบบคิวไปแล้ว ในบทความนี้จึงแนะนำการเขียนโปรแกรมจัดการโครงสร้างข้อมูล (Data Structure) อีกประเภทหนึ่งซึ่งมีวิธีการจัดเก็บและจัดการที่แตกต่างกันไปอันมีชื่อว่าต้นไม้แบบ BST หรือ Binary Search Tree ดังในภาพที่ 1 ซึ่งเป็นโครงสร้างที่สามารถนำไปประยุกต์เกี่ยวกับการเก็บข้อมูลที่มีคุณลักษณะที่ข้อมูลทางกิ่งด้านซ้ายมีค่าที่น้อยกว่าตัวเอง และกิ่งด้านขวามีค่ามากกว่าต้นเอง หรือทำตรงกันข้ามคือกิ่งซ้ายมีค่ามากกว่า และกิ่งด้านขวามีค่าน้อยกว่า ทำให้การค้นหาข้อมูลในกรณีที่ต้นไม้มีความสมดุลย์ทั้งทางซ้ายและทางขวาบนโครงสร้าง BST ประหยัดเวลาหรือจำนวนครั้งในการค้นหาลงรอบละครึ่งหนึ่งของข้อมูลที่มี เช่น มีข้อมูล 100 ชุด ในรอบแรกถ้าตัวเองยังไม่ใช่ข้อมูลที่กำลังค้นหา จะเหลือทางเลือกให้หาจากกิ่งทางซ้ายหรือขวา ซึ่งการเลือกทำให้ข้อมูลของอีกฝั่งนั้นไม่ถูกพิจารณา หรือตัดทิ้งไปครึ่งหนึ่งโดยประมาณ แต่ถ้าเป็นกรณีที่ Binary Search Tree นั้นขาดความสมดุลย์จะส่งผลให้การค้นหามีความเร็วไม่แตกต่างกับการค้นหาแบบลำดับ (Sequential Search) เท่าใดนัก

ในบทความนี้ใช้ภาษาไพธอนที่ทำงานได้ทั้งบนตัวแปลภาษา Python 3 หรือ MicroPython เพื่อจัดเก็บข้อมูล การเพิ่มข้อมูล การค้นหาข้อมูล เพื่อเป็นตัวอย่างของการนำไปพัฒนาต่อไป

BST : Binary Search Tree
ภาพที่ 1 ตัวอย่าง BST
Read More

[TH] Calculate Regression with MicroPython on esp32-C3.

บทความนี้กล่าวถึงการคำนวณค่าถดถอย (Regression) ด้วยภาษาไพธอนของ MicroPython โดยใช้บอร์ดไมโครคอนโทรลเลอร์ ESP32-C3 พร้อมทั้งแสดงผลด้วยจอแสดงผลกราฟิกแบบ 2 สี (แสดงกับไม่แสดงเม็ดสี) แบบ OLED ดังภาพที่ 1 ซึ่งค่าที่นำมาใช้เป็นตัวอย่างในการใช้งานเป็นค่าที่ได้จากการอ่านอุณหภูมิ

ภาพที่ 1 บอร์ด ESP32-C3 ที่ต่อเติมโมดูล OLED และขาสำหรับเชื่อมต่อภายนอก
Read More

[TH] How to build MicroPython for esp32-C3.

บทความนี้กล่าวถึงการคอมไพล์ (build) และใช้งาน MicroPython สำหรับไมโครคอนโทรลเลอร์ esp32-C3 ที่ได้เคยแนะนำไปแล้ว โดยขั้นตอนยังเหมือนกับการคอมไพล์สำหรับ esp32-s2 นอกจากนี้ทีมงานได้ดำเนินการแก้ไขปัญหาเรื่องของ RS232-to-USB จากที่บอร์ดใช้ CH340 ไปต่อขาภายนอกโดยใช้ CP2102 แทน และต่อโมดูลแสดงผลด้วย OLED ดังภาพที่ 1

ภาพที่ 1 บอร์ด ESP32-C3 ที่ต่อเติมโมดูล OLED และขาสำหรับเชื่อมต่อภายนอก
Read More

[TH] Understand and use the ESP32-C3

หลังจากที่พวกเราใช้งาน  esp8266 โดยเฉพาะโมดูล esp-01 และ esp-01s เพื่อเป็นตัวบริหารจัดการเครือข่ายเซ็นเซอร์มาเป็นระยะเวลาพอสมควร และด้วยขีดจำกัดในเรื่องของจำนวนขาใช้งานทำให้ต้องออกแบบระบบให้ทำงานคู่กับ  STM32F103C8T6 หรือ STM32F401CCU6/STM32F411CEU6 เพื่อให้การทำงานมีความสเถียรไม่ประสบปัญหาเกี่ยวกับ WDT ของ esp8266 และด้วยเวลาที่ผ่านไป ทาง espressif ออกไมโครคอนโทรลเลอร์ตามมาอีกหลายตัว เช่น esp32, esp32-s2, esp32-c3 และ esp32-s3

ทางเราได้ทดสอบและใช้งาน esp32 จนแทบจะเป็นตัวหลักในการทำงาน จน esp32-s2 กับบอร์ดของ LILYGO ทำให้เราลองสั่งมาใช้งาน ปัญหาหลักอยู่ที่เครื่องมือในการพัฒนานั้นออกมาล่าช้ามาก แต่อย่างไรก็ดี ณ​ ตอนนี้ทาง espressif ได้ออกชุดพัฒนาสำหรับ Arduino หรือ Arduino Core for ESP32 รุ่น 2.0 พร้อมรองรับการใช้กับ esp32 esp32-s2 และ esp32c3 ทำให้การใช้งานกับ ESP32 และ ESP32-S2 ใช้งานได้ดี และล่าสุดทางทีมงานเราได้บอร์ด esp-c3-32s มาจึงเกิดมาเป็นบทความนี้

สำหรับบทความนี้เป็นการเรียบเรียงจาก datasheet ของ ESP32-C3 WROOM-02 ซึ่งในบทความนี้เราใช้บอร์ดดังภาพที่ 1 ส่วนตัวอย่างโปรแกรมเป็นการขับหลอด LED แบบ RGB บนบอร์ดให้ทำงานโดยใช้ Arduino Core for ESP32 และ ESP-IDF ที่ปรับปรุงมาจากบทความใน Ep.3

ภาพที่ 1 บอร์ดไมโครคอนโทรลเลอร์ ESP32-C3
Read More

[TH] Queue Data Structure

บทความนี้แนะนำการใช้คลาส list ใน Micropython มาประยุกต์เป็นโครงสร้างข้อมูลคิวที่มีจำนวนสมาชิกจำกัด และทำงานตามหลักการ FIFO (First-In-First-Out) ซึ่งสามารถนำไปประยุกต์ใช้ได้หลากหลาย เช่น ใช้เป็นที่เก็บข้อมูลและเมื่อข้อมูลมีเต็มแล้วแต่ต้องการนำข้อมูลใหม่ใส่เข้าไป ดังนั้น จึงต้องนำข้อมูลเก่าอันดับที่ 1 ที่ใส่เข้ามาออกไป ซึ่งตรงกับหลักการของ FIFO เป็นต้น โดยตัวอย่างในบทความนี้ใช้บอร์ด dCore-miniML (ในภาพที่ 1) อ่านข้อมูลอุณหภูมิของชิพมาเก็บไว้ในโครงสร้างแบบคิวและแสดงผลออกมาในลักษณะของกราฟแท่ง และไมโครไพธอนที่นำมาใช้เป็นเฟิร์มแวร์รุ่น 1.16 (2021-06-23) สำหรับ ESP Module (SPIRAM)

ภาพที่ 1 ตัวอย่างการวาดกราฟด้วยข้อมูลที่เก็บในโครงสร้างข้อมูลแบบคิว
Read More