[TH] Draw an analog clock using MicroPython.

บทความก่อนหน้านี้ได้กล่าวถึงการปรับปรุงปรับปรุงความเร็วในการแสดงผลด้วยการใช้เทคนิคดับเบิลบัฟเฟอร์ (double buffer) จึงนำมาประยุกต์ใช้สำหรับการแสดงผลเป็นนาฬิกาแบบแอนาล็อกดังภาพที่ 1 ซึ่งวิธีการวาดนั้นใช้การคำนวณตรีโกณมิติเพื่อหาค่าพิกัด (x,y) ของปลายเข็มวินาที นาที และชั่วโมง โดยการทำงานของแต่ละวินาทีจะใช้ตัวตั้งเวลาหรือไทเมอร์ (Timer) เพื่อให้การทำงานนั้นใกล้เคียงกับเวลาจริงมากกว่าการวนรอบหรือการหน่วงเวลา

ภาพที่ 1 ตัวอย่างผลลัพธ์ของการวาดนาฬิกาแบบแอนาล็อก
Read More

[EN] Using ESP32’s ADC and DAC with Micropython.

This article describes the implementation of the ESP32 microcontroller’s ADC (Analog-to-Digital Converter) and DAC (Digital-to-Analog Convertor) with MicroPython’s Python subclasses ADC and DAC, which fall under the machine class to learn both subclasses along with an example program to use the class as shown in Figure 1 as a basis for further development.

(Figure. 1 ADC/DAC’s example of use)
Read More

[TH] MicroPython : pyb USB_HID/USB_VCP

บทความนี้กล่าวถึงการใช้ความสามารถเกี่ยวกับ USB HID ของบอร์ดไมโครคอนโทรลเลอร์ STM32F411CEU6 ผ่านทาง MicroPython ในคลาส pyb ซึ่งทีมงานเราได้แรงบันดาลใจจากบทความ MicroPython for STM32F411 Black Pill: Embedded Programming Style ของอาจารย์ดร.เรวัต ศิริโภคาภิรมย์ ว่าแล้วมาเริ่มคอมไพล์และอัพโหลดเฟิร์มแวร์กันได้เลยครับ (อ่านรายละเอียดได้จากบทความของอาจารย์ดร.เรวัต ศิริโภคาภิรมย์ ได้เลยครับ) โดยเราใช้บอร์ดเลียนแบบ WeAct STM32F411CEU6 ดังภาพที่ 1 ซึ่งเมื่อติดตั้ง MicroPython จะมีคลาส pyb ให้ใช้งาน

ภาพที่ 1 บอร์ดสำหรับการทดลองในบทความนี้
Read More

[EN] _thread

This article is about using the _thread class with an ESP32 microcontroller with 2 cores. However, the thread class is a subset of the cython module and at the time of writing it is not yet fully available. The class structure is as shown in Figure 1 and the LockType subclass is as shown in Figure 2.

Read More

[EN] random

Random numbers in Python use the random class, but microcontrollers don’t support as much randomness as in computer systems, so Micropython supports different commands depending on the chip type. This article discusses how to use random with esp8266 and esp32 microcontrollers, which are instructed to just generate random numbers and configure the random seed as follows.

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

[EN] machine.RTC

This article takes a detailed look at the Micropython machine.RTC class. The main function of this class is designed to be an RTC (Real-Time Clock) inside the microcontroller for storing date and time. It is more convenient when used with ESP8266 or ESP32 chip because NTP can be accessed to read the date and time from the internet and then store the value into the RTC to enable the accuracy and do not require frequent internet access to read the values ​​again. This saves the use of external RTC circuits as well.

Read More

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

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

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