As an embedded software engineer and consultant, time is critical in embedded systems engineering. Faster development, debugging and testing lead to greater productivity and cost savings. Over time, I’ve discovered that spending just five minutes with ChatGPT can save me hours. In this blog, I’ll share how I use ChatGPT to streamline my programming workflow and how you can too.
Why ChatGPT is a Valuable Tool for Embedded Systems Engineers
Time-Savings Benefits
Embedded systems engineers often find themselves running command-line applications repeatedly, frequently changing parameters or values. ChatGPT can help automate these workflows with Python or other scripting languages. It saves a significant amount of time by quickly generating the code. It’s particularly useful for creating easy-to-use GUIs that both you and your collaborators can interact with seamlessly. This is especially true with IOT applications that are likely to have Wi-Fi or BLE to easily interact with your computer.
Answer Obscure Questions
In embedded systems, I often encounter obscure questions that a simple Google search may not easily resolve. While the information is likely out there, it can be time-consuming to sift through multiple pages of search results. Instead, I turn to ChatGPT. It often provides a clear and concise answer in seconds to even the most obscure questions about embedded systems libraries, functionalities, or tools.
Increased Efficiency
When faced with an algorithm or calculation that would take several minutes to write manually, ChatGPT can help you save time. Describe the function in a sentence or two, and ChatGPT will generate the code including the outputs within the same function.
Important Considerations When Using ChatGPT
While ChatGPT is a great resource, it’s important to be mindful of a few key points.
1. Lack of Awareness of Your Ongoing Efforts
ChatGPT doesn’t inherently understand your project’s context unless explicitly told. For example, while working on a Python GUI using ChatGPT for a video frame analyzer, I assumed that holding down the "next frame" button would fast-forward through the video.This is something I’m accustomed to in modern interfaces. However, holding down the button simply brought me to the next frame. After I specifically asked for this feature, ChatGPT provided me with updated functional code.
2. Works Best as an Input-to-Output Solution
Think of ChatGPT as an elevator— provide a clear, specific request, and it will take you directly to your desired floor. But if you overload it with too many requests at once, you risk stopping at every floor along the way. To get the most efficient results, break your tasks into smaller, manageable chunks, test the output at each step, and refine as needed. This step-by-step approach ensures you reach your goal smoothly and effectively.
3. Requires Some Technical Knowledge for Troubleshooting
ChatGPT’s solutions are often accurate, but they may need refinement. If you encounter errors, your technical expertise becomes crucial. By providing error messages, clarifying unexpected behavior, or hypothesizing potential causes, you can guide ChatGPT to improve its suggestions effectively.
4. Falling Into Rabbit Holes
While ChatGPT is a great troubleshooting tool, its suggestions may not always work as expected. You might spend time trying multiple plausible fixes that don’t resolve the issue, leading to frustration. It’s crucial to recognize when this happens, step back, and explore alternative solutions. ChatGPT can generate helpful ideas, but it is fallible and may require you to pivot or revisit the problem from a new angle.
5. Outdated Solutions
One important thing to keep in mind when using ChatGPT for embedded systems work is that its knowledge is based on information up until its last update. This means it may sometimes suggest solutions that are outdated or no longer relevant, especially in fields like embedded systems where tools, libraries, and platforms evolve rapidly.
For example, when working with newer kernel versions on platforms like Raspberry Pi, I have seen important configuration files relocated, but ChatGPT still suggests solutions based on older configurations. This can lead to frustration if you're trying to apply outdated practices to a more recent environment. As a result, it’s essential to stay on top of the latest updates for your development tools and platforms, verifying ChatGPT's suggestions against current documentation to avoid wasting time on solutions that no longer apply.
6. Maintain Confidentiality with Proprietary Information
It’s important to understand that ChatGPT, by default, may use your data to improve its AI model. When working with code or documents under an NDA or requiring confidentiality, take steps to protect sensitive information. Replace identifiable details (e.g., project names, client specifics, or unique identifiers) with placeholders, and frame questions using generalized examples to safeguard proprietary content.
Practical Uses: How ChatGPT Accelerates Embedded Systems Development
Here are practical examples of how I leverage ChatGPT to enhance my embedded systems projects.
1. Creating Python GUIs to Save Time
Working with IoT devices often means dealing with clunky command-line interfaces requiring dozens of parameters or outdated tools that slow down development. These challenges become even more apparent when collaborating with clients or non-technical teams, where usability and clarity are key. A simple, intuitive GUI can make a world of difference.
Example:
While implementing MQTT for IoT communication, I needed an easy way to start the broker, send predefined messages, and display incoming responses in real time. Using ChatGPT, I quickly generated a Python-based GUI that achieved these goals. The interface featured buttons to trigger common commands like starting and stopping recording, fields to customize message payloads, and a real-time log for incoming messages.
This solution saved significant development time and improved usability for both me and my client. It streamlined testing and debugging by replacing a cumbersome command-line process with a user-friendly, visually intuitive interface. With this approach, I could focus on delivering results while fostering better collaboration.
2. Automating Tedious Tasks
On a recent project requiring precise camera synchronization, I needed to fetch and review numerous video files stored on separate embedded Linux devices. Doing this manually via SSH and buggy third-party tools was inefficient.
Solution:
I used ChatGPT to create a GUI that:
- Connected to remote devices via SSH
- Downloaded the latest video files
- Displayed all videos synchronously
Originally this GUI provided a start and stop button and up to four screens to view the videos. By iteratively refining the GUI with ChatGPT, I also added frame-by-frame navigation for debugging as well as up to eight screens. This greatly improved my workflow and let me iterate on my actual project much faster.
3. Writing C++ Wrappers for Libraries
One of the biggest challenges in embedded systems is dealing with the highly diverse firmware ecosystems, such as FreeRTOS, Mbed, Zephyr, and others. Each platform has its own strengths and weaknesses, and you may find yourself working in a FreeRTOS environment but wishing you had access to some of Mbed’s powerful networking stack. While the underlying architectures differ, both FreeRTOS and Mbed are well-documented, which makes it easier to bridge the gap with a wrapper.
Example:
I needed Mbed’s threading, mutex, and semaphore features in a FreeRTOS project. I used ChatGPT to generate a wrapper class that allowed me to use Mbed-like functionality within FreeRTOS. With just a simple request, I received a base implementation for the Mbed Thread class, Mutex, and Semaphore, all translated into FreeRTOS-compatible code. While some underlying issues may arise during implementation, this wrapper provided a solid foundation to build on and integrate Mbed-specific features into my FreeRTOS-based device.
My prompt:
"Write me a wrapper class that uses FreeRTOS but gives me class’s that perfectly mimics Mbed’s threading functions"
ChatGPT’s response:
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
class Thread {
public:
// Constructor: Takes a function pointer and optional argument
Thread(void (*taskFunction)(void*), void* argument = nullptr, const char* name = "Thread",
uint16_t stackSize = configMINIMAL_STACK_SIZE, UBaseType_t priority = tskIDLE_PRIORITY)
{
xTaskCreate(taskFunction, name, stackSize, argument, priority, &taskHandle);
}
// Destructor: Deletes the FreeRTOS task
~Thread() {
if (taskHandle != nullptr) {
vTaskDelete(taskHandle);
}
}
// Start the thread (already started in constructor)
void start() {
// FreeRTOS tasks start immediately upon creation, so this is typically a no-op
}
// Join function (Waits for the thread to terminate)
void join() {
while (eTaskGetState(taskHandle) != eDeleted) {
vTaskDelay(1);
}
}
// Detach function (make the thread independent)
void detach() {
taskHandle = nullptr;
}
// Static function to yield execution to another thread
static void yield() {
taskYIELD();
}
// Static function to get the thread's id
static TaskHandle_t get_id() {
return xTaskGetCurrentTaskHandle();
}
private:
TaskHandle_t taskHandle;
};
// Mbed-style Mutex wrapper using FreeRTOS
class Mutex {
public:
Mutex() {
mutexHandle = xSemaphoreCreateMutex();
}
~Mutex() {
vSemaphoreDelete(mutexHandle);
}
void lock() {
xSemaphoreTake(mutexHandle, portMAX_DELAY);
}
void unlock() {
xSemaphoreGive(mutexHandle);
}
bool trylock(uint32_t timeout_ms) {
return xSemaphoreTake(mutexHandle, pdMS_TO_TICKS(timeout_ms)) == pdTRUE;
}
private:
SemaphoreHandle_t mutexHandle;
};
// Mbed-style Semaphore wrapper using FreeRTOS
class Semaphore {
public:
Semaphore(int max_count, int initial_count) {
semaphoreHandle = xSemaphoreCreateCounting(max_count, initial_count);
}
~Semaphore() {
vSemaphoreDelete(semaphoreHandle);
}
void acquire() {
xSemaphoreTake(semaphoreHandle, portMAX_DELAY);
}
void release() {
xSemaphoreGive(semaphoreHandle);
}
bool try_acquire(uint32_t timeout_ms) {
return xSemaphoreTake(semaphoreHandle, pdMS_TO_TICKS(timeout_ms)) == pdTRUE;
}
private:
SemaphoreHandle_t semaphoreHandle;
};
This wrapper gave me a great starting point, saving hours of manual coding and research.
Key Takeaways
ChatGPT is a game-changer for embedded systems development when used wisely. Here’s how you can maximize its benefits:
- Be Specific: Define your problem clearly to guide ChatGPT effectively
- Iterate: Break complex tasks into smaller, manageable chunks
- Validate: Always test and review ChatGPT’s suggestions
- Leverage Your Expertise: Combine your technical knowledge with ChatGPT’s output for optimal results
By incorporating ChatGPT into your embedded development workflow, you can significantly enhance productivity, streamline development, and tackle tedious tasks more effectively.
Ready to take your embedded systems project to the next level? Contact us today to learn more about our solutions and how we can help you achieve your goals.