Skip to main content

Posts

Function pointer and Callback advantages

  Example: Button Interrupt with Dynamic Callbacks #include <stdio.h> #include <stdint.h> // Define a callback type typedef void (*ButtonCallback)(void); // Global variables volatile uint8_t button_pressed_flag = 0; ButtonCallback button_callback = NULL; // ISR: fast, only sets flag void BUTTON_IRQHandler(void) { button_pressed_flag = 1; } // Register a callback dynamically void register_button_callback(ButtonCallback cb) { button_callback = cb; } // Two possible actions void turn_on_led(void) { printf("LED turned ON!\n"); } void send_message(void) { printf("Message sent!\n"); } int main() { // At runtime, we can decide which action to use int user_choice; while (1) { printf("Choose action: 1=LED, 2=Message: "); scanf("%d", &user_choice); if (user_choice == 1) register_button_callback(turn_on_led); // set LED action else register_button...

Simple servo motor testing with Wemos D1, ESP8266

 Are you struggling with a board Wemos D1 (ESP8266 MOD) and testing a servo motor? If the answer is yes, it is the right place to help you out. 1. Set up the board Just follow the step-by-step instructions in this link: https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/ 2. Hardware wiring Same as Arduino Uno. Please note that the servo motor requires an external power supply. https://docs.arduino.cc/learn/electronics/servo-motors/ 3. Open an example "Servo" 4. Select the right board with the right serial port Board: NodeMCU 1.0 (ESP-12E Module) 5. Run an example and contact me if the problem isn't solved. I bet that you know how to run it

Tạo ứng dụng AI đầu tiên - a piece of cake

Thư viện ngày gió to, nhìn quanh được 4 chú sinh viên già, quen mặt. Canada dạo này nát thật. Từ 2024, chính phủ hạn chế dân tạm cư, du học sinh quốc tế thưa thớt hẳn. Tui mất 1h30 để cài đặt và configure viết ra ứng dụng đầu tiên để chọc đến các API của AI platform. Bài toàn tương đối đơn giản: "Tui hỏi bằng miệng, AI trả lời" Ơ hay, thế bình thường khi dùng AI thì không thế à? Haha, bình thường bạn dùng sẵn app của nó, còn đây tui đang tự build cái app đó để customize theo cái ý đồ riêng của tôi để chơi với con robot. Phân tích flow chương trình về mặt kỹ thuật: Bạn nói => Module chuyển từ giọng nói sang text => cho cái text này vào AI bằng cách gọi API của AI => nhận response và hiển thị lên màn hình console Okay, nghe có vẻ đơn giản, giờ ta bắt tay vào làm theo thought process 1. Chọn ngôn ngữ nào? Mình muốn ăn liền nên python là chuẩn bài = >  Python 3.8+ 2. Dùng module nào để convert? Cái nào lightweight rẻ tiền thì dùng, miễn phí càng tốt => Để truy cập ...

Nồi nước nóng AI

  Hôm nay trong lúc làm bài quiz open book ở trên lớp. Tôi để ý thấy một hiện tượng xuất hiện trong tâm lý mình lúc làm bài. Có những câu hỏi rất dễ, ai cũng có thể đoán được. Tuy nhiên tôi vẫn phải dùng AI để kiểm tra lại. Tôi tự hỏi, có phải chăng AI đang làm tôi mất tự tin và không dám nhận trách nhiệm về những quyết định của mình. Có phải tôi đang là một con ếch đang chết dần trong nồi nước nóng AI. Những tác động tiêu cực của thói quen này đến tôi như thế nào? Làm gì để hạn chế những tiêu cực của nó. Và tôi lại dùng AI để thực hiện nghiên cứu riêng của mình. Tôi muốn tìm hiểu thêm về khía cạnh tâm lý ẩn sâu trong vấn đề này, tại sao khi làm assignment, tôi đã có câu trả lời của riêng mình, mà tôi vẫn sử dụng AI như một công cụ để cheating. Nếu tiếp tục như vậy thì tâm lý của tôi sẽ diễn biến như thế nào trong khoảng thời gian dài hình thành thói quen này? Rất đáng để phân tích sâu về khía cạnh tâm lý này, vì nó liên quan trực tiếp đến cách bạn cảm nhận về bản thân, năng lực và...

Chuyện bóng đèn - Hư cấu

Ngã ba đường ở trước cửa nhà tôi, cũng là ngã ba cột điện của mấy khu tập thể gần năm mươi tuổi đời giữa lòng thủ đô. Trên cái cột điện đó có cái bóng đèn nhà nước chiếu sáng lờ mờ vàng vọt bao nhiêu ngày tháng. Từ hồi chuyển đến ở đó tôi chưa bao giờ để ý đến cái ánh sáng của nó cho đến một ngày. Trời không trăng không sao mà lại sáng rực lên cả ô cửa sổ thế này. Tôi tự hỏi các bô lão trong khu vực và được xác nhận là chiếc bóng đèn mới được thay thế sau khi tắt hẳn ngày hôm qua. Hóa ra, sống trong cái tối lờ mờ lâu ngày rồi người ta không phân biệt được đâu là "sáng bình thường" nữa. Tôi chợt nhớ đến một chiếc bóng đèn khác trong câu chuyện tôi lượm lặt trên internet xin tóm tắt lại như thế này.  Có một chiếc bóng đèn cao áp trong nhà máy, bao nhiêu năm sáng to, rõ giúp nhà máy vận hành ổn định trơn chu. Nhưng nó mãi vẫn là cái bóng đèn junior mà không được thăng hạng lên thành senior lightbulb. Nó buồn bã tìm đến mentor của nó và hỏi:  - Sao con mãi chỉ là bóng đèn junio...

Mastering Food Safety: Essential Keywords Every Food Handler Should Know

Whether you're new to the food industry or preparing for your food handler certification, knowing the key terms and concepts is crucial. These keywords aren’t just textbook terms —they’re real-world tools for keeping customers safe and maintaining high standards in food service. Before diving into the key concepts, here's what to expect when taking a food handler certification course in most provinces or states: Cost : Food handler training typically costs between $15 and $50 CAD/USD , depending on the provider, region, and whether it’s online or in person. Group discounts are often available for employers. Study Time : Most online courses take 4 to 6 hours to complete, while in-person classes may run for a full day. Many programs are self-paced, allowing flexibility based on your schedule. Exam Details : After the course, you must pass a multiple-choice exam (usually 30–60 questions). A passing score is typically 70% or higher . The exam can often be taken onlin...

[STM32] How to configure Timer 1, Channel 3 is PWM 1kHz, duty cycle 20% to control BLDC motor

 To configure Timer1 for a 1 kHz PWM signal with a 20% duty cycle on an STM32H7S3L8 microcontroller, follow these steps: 1. Understand the Timer Parameters PWM Frequency : 1 kHz → Period = 1 ms. Duty Cycle : 20% → ON time = 0.2 ms. The timer’s clock frequency is derived from the APB clock (e.g., TIMCLK). Let’s assume you know the APB clock frequency. The Timer prescaler and auto-reload register (ARR) define the PWM frequency. 2. Compute Timer Parameters Formula: PWM Frequency = Timer Clock (Prescaler + 1) * (ARR + 1) \text{PWM Frequency} = \frac{\text{Timer Clock}}{\text{(Prescaler + 1) * (ARR + 1)}} PWM Frequency = (Prescaler + 1) * (ARR + 1) Timer Clock ​ For 1 kHz PWM: A R R = Timer Clock PWM Frequency ∗ ( Prescaler + 1) − 1 ARR = \frac{\text{Timer Clock}}{\text{PWM Frequency} * (\text{Prescaler + 1)}} - 1 A RR = PWM Frequency ∗ ( Prescaler + 1) Timer Clock ​ −...

Core needed skills for embedded system engineer

  There are three main skills you need to get your hands dirty to become a master in this field: Soldering, Programming, and Electrical Prototyping 1. Core Skill: Soldering This skill defines how difficult the soldering is on a particular product. It might be a couple simple solder joints, or require special reflow tools. 1   Noob Noob  - Some basic soldering is required, but it is limited to a just a few pins, basic through-hole soldering, and couple (if any) polarized components. A basic soldering iron is all you should need. 2   Rookie Rookie  - The number of pins increases, and you will have to determine polarity of components and some of the components might be a bit trickier or close together. You might need solder wick or flux. 3   Competent Competent  - You will encounter surface mount components and basic SMD soldering techniques are required. 4   Experienced Experienced  - You might be required to do some reflow or basic rework with...

[Mentorship] First day at work - question for your co-workers (casual and friendly tone)

Summary Learn essential tips to make a positive first impression on your first day at a new job, ensuring success and connection with colleagues. Highlights⏰ Be punctual: Arrive early to show commitment. ( 15 minutes before your shift ) 🚫 Avoid gossip: Maintain professionalism and integrity. ❌ Don’t ask for time off: Show dedication to your new role. 🤝 Firm handshake: A confident greeting sets a great tone. 📚 Ask questions: Engage with your new role actively. 🗂️ Organize your workspace: Keep your area tidy for respect. ☕ Accept social invites: Build rapport with co-workers. Key Insights ⏳ First Impressions Matter: Your colleagues will form opinions quickly, so be on your best behavior right from the start. 🌟 Professional Appearance: Dressing smartly conveys seriousness about your role and can positively influence how others perceive you. 💬 Communication is Key: A warm greeting and engaging dialogue can help break the ice and make you more approachable. 📝 Active Learning: Asking ...

[Basic] C program and SRAM, flash, stack, heap ... Why microcontrollers use different types of memory like that?

Preface When you build the source code in C/C++, you might see some output messages as the blow: Flash used: 1166 of 262144 bytes (0.4%). SRAM used: 2505 of 65536 bytes (3.8%). Stack: 2048 bytes. Heap: 128 bytes. --------------- Rebuild Succeeded: 10/01/2024 17:46:40 --------------- Figure 1: The output message from PSoC Creator Figure 2: The output message from Arduino IDE Have you asked yourself what are technical jargon such as flash, stack, and heap? In short, they are kinds of memory for machines. Microcontrollers use different types of memory (Flash, SRAM, EEPROM, etc.) because each type serves a specific purpose, balancing factors like cost, speed, power consumption, and data persistence . Key Differences Between These Memory Types: The explanation for the output message in the figure 1: Flash used : 1222 of 262144 bytes (0.5%) The program's code occupies 1222 bytes of the total available 262144 bytes in Flash memory. This is a very small portion, showing efficient memory us...

[C++] Apply the primary principle of C++ for preparing a meal

  Let's apply the principle of C++ (object-based programming) to the task of preparing a meal. In object-based programming, we break down tasks into objects that represent real-world entities. These objects have attributes (data) and methods (actions they can perform). Example: Preparing a Meal in C++ Style Imagine you're preparing a meal with different objects, each responsible for a specific part of the process. For simplicity, let's define three main objects: Chef , Ingredients , and KitchenTools . 1. Chef Object : Attributes : Name, experience level. Methods : prepareMeal() , useTool() , mixIngredients() . 2. Ingredients Object : Attributes : Type (vegetables, meat, spices), quantity, freshness. Methods : chop() , cook() , serve() . 3. KitchenTools Object : Attributes : Tool type (knife, pan, oven), condition (new, used). Methods : cut() , heat() , stir() . C++-Style Meal Preparation Example: Here’s how we would code a meal preparation process in C++: Breakdown: The...

[MiniProject] Convert Vietnamese unicode strings to unaccented strings

 Recently, I embarked on an exciting Arduino project where I needed to convert Vietnamese Unicode strings into their unaccented equivalents. The goal was simple, but I quickly ran into a problem: the conversion process wasn’t working as expected. Characters like "Độc lập tự do" were returning as a string of question marks! I reached out for help and discovered that the issue was rooted in the way UTF-8 encoding was handled in my code. With some guidance, I learned how to properly decode UTF-8 characters into their Unicode equivalents before converting them. By breaking down the string into manageable arrays and thoroughly testing each case, I finally got the correct output: "Doc lap tu do." This project taught me the importance of understanding encoding and the value of community support in problem-solving. Now, my Arduino project runs smoothly, converting Vietnamese text as intended! The serial Monitor output: Unicode & Vietnamese Legacy Character Encodings htt...

[Vi] Công nghệ phát triển ngược đời - How is AI harming my world

Tiếng cười khanh khách của mấy cậu sinh viên quốc tế người Bắc Ấn sau bài kiểm tra cuối khóa (a final exam) làm gã thấy buồn một góc tâm hồn. Sự trống rỗng ngay lập tức xâm chiếm lấy tâm trí gã sau khi nộp bài môn thi cuối cùng của kỳ học. Gã hiểu gã quá mà, gã đang cố gắng giải thích cho nỗi nhục của chính bản thân ở bên trong. Đầu gã thoáng nghĩ về cái lần thi cuối kỳ một môn học ở bậc thạc sỹ nơi quê nhà hơn mười năm về trước, cái ánh mắt khinh bỉ đến ám ảnh của một anh dọn vệ sinh dành cho những học viên cao học đang quay cóp trong giờ thi của một trường đại học hàng đầu quốc gia như vết dao khứa vào lòng tự trọng của gã. Vết thương vẫn nhói đau lại khi những mùa thi đến. Một lão già sinh viên quốc tế ranh ma. Gã đang học lại cái thứ mà gã đã học từ hai mươi năm về trước với một thứ ngôn ngữ không mới và cái tâm bằng sắt nung. Kinh nghiệm làm việc chuyên môn lâu năm cộng với việc vừa được trang bị thứ vũ khí khoa học tối tân AI (Trí truệ nhân tạo) khiến lão trở thành sát thủ trong ...

[MyThought] Software design scalability, how to navigate conflicting perspectives

 Your team disagrees on software design scalability. How do you navigate conflicting perspectives? First of all, disagreements usually come from different viewpoints and personal biases. When people look at a problem, they each see it from their own perspective. To make sure everyone’s on the same page, it helps to list out the main issues before jumping into brainstorming. Remember, how scalable the software is will depend on both the project’s budget and timeline. Secondly, based on the project's budget and timeline, team members are encouraged to share their thoughts freely during the brainstorming session. Afterward, we'll gather the most outstanding ideas and compile them into a table of options. We'll then weigh these options based on several criteria, and finally, we'll select the top-ranked one. Moreover, I work in the field of embedded software. Whenever we design a new product, we must consider both the hardware and software aspects. Hardware is always the fir...

Navigating Embedded AI: A Friendly Guide for Junior Students

Embedded AI algorithms might sound complicated, but they're just a bit different from the AI you might know from general-purpose computers. These differences come from the unique needs and limitations of embedded systems, like those in your smartphone or a smart fridge. Let's explore these differences and see how they shape the way we design and use AI in these cool devices! #### 1. Working with Limited Resources **Memory and Storage:**    Embedded systems usually don't have a lot of memory or storage. Think of them like tiny apartments compared to big houses (general-purpose computers). So, when we write algorithms for them, we need to make sure they don't take up too much space. It's all about being efficient! **Processing Power:**   These devices often have less powerful processors. It's like comparing a bike to a car; you can't go as fast, but you can still get where you're going. Our algorithms need to be lightweight and quick so they can run smooth...

How to use ChatGPT to get your resume shortlisted?

How to use ChatGPT to get your resume shortlisted? Core steps: Chat GPT -> Resume Creator -> LinkedIn(Copy the job description to ChatGPT) -> Add your personal information -> Copy output from ChatGPT to Instaresume.io to make the template -> Goto SkillSyncer to check ATS(Applicant Tracking Software) score, point out the missing keywords. Detail ☑️In my pursuit of job #opportunities, I encountered a familiar challenge - my resume seemingly disappeared into oblivion, yielding no responses despite my diverse skill set and numerous applications. ☑️As I delved into my research, I uncovered the existence of ATS software, the automated gatekeeper of #resumes, which swiftly filtered out those lacking relevant keywords. ☑️The outcome? Not just one #company, but over a dozen organizations recognized the potential in my resume, resulting in multiple shortlists and promising #job prospects! 💻If you want to supercharge your resume and unlock countless opportunities, don't miss o...

Basic Math in tech

Significant digits How to determine the number of significant digits Example: Exercise Application Accuracy Example Accuracy in multiplying and dividing Degree of precision Example Application Mixing Multiplication(Division) and Subtraction (Or Addition) => Follow the rule of multiplication for the final answer