NECTO Code Assistant Manual
The NECTO Code Assistant is a powerful feature in NECTO Studio that helps users generate code for their embedded projects, especially those built with MIKROE Click boards™ and the mikroSDK v2.0 framework. This manual guides you through the practical use of the assistant, showing how to quickly set up, configure, and run your embedded project.
Practical Example: NECTO Code Assistant with Thermo 21 Click and LVGL Graphics
📌 Reference GIF:
Step 1: Set Up Your Environment
- Launch NECTO Studio.
- Navigate to the
Code Assistant
panel. - Shortcut: Press
CTRL
+8
. - In the Code Assistant prompt, type the following request:
How can I display live temperature readings from Thermo 21 Click on a TFT display using the LVGL framework in NECTO Studio?
Step 2: Connect to Your Hardware Setup
- Connect your development board (e.g., UNI-DS v8) via USB.
- Place the Thermo 21 Click on MIKROBUS 1.
- Attach a TFT display (e.g., TFT 4.3" Cap Touch) to the appropriate connector.
- (Optional) Open
Planet Debug
for remote testing.
Step 3: Generate and Insert Code
- After asking your question, NECTO Code Assistant will generate the necessary code.
- Copy the generated code to your
main.c
file.
Example generated code:
/*!
* @file main.c
* @brief Thermo 21 Click with TFT Display Example
*
* # Description
* This application reads temperature data from the Thermo 21 Click
* and displays it on a TFT display using the LVGL framework.
*/
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif
#include "board.h"
#include "log.h"
#include "thermo21.h"
#include "display_lvgl.h"
#include "lv_port_indev.h"
#include "1ms_Timer.h"
static thermo21_t thermo21; ///< Thermo 21 Click instance
static log_t logger; ///< Logger instance
lv_obj_t *thermo21_label; ///< Pointer to the label displaying the temperature
/**
* @brief Update the text of an existing label.
*
* This function updates the text content of a given label.
*
* @param label Pointer to the LVGL label object.
* @param text The new text to display on the label.
*/
void update_label(lv_obj_t *label, const char *text) {
if (label) {
lv_label_set_text(label, text);
}
}
/**
* @brief Create and align a label on the active screen.
*
* This function creates a new label, applies default styling, and aligns it on the screen.
*
* @param x The x-coordinate offset relative to the alignment.
* @param y The y-coordinate offset relative to the alignment.
* @param align The alignment option (e.g., LV_ALIGN_CENTER, LV_ALIGN_TOP_LEFT, etc.).
* @return Pointer to the created LVGL label object.
*/
lv_obj_t *create_label(int x, int y, lv_align_t align) {
lv_obj_t *label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "");
lv_obj_set_style_text_color(label, lv_color_hex(0x000000), LV_PART_MAIN);
lv_obj_align(label, align, x, y);
return label;
}
/**
* @brief Initialize the board and LVGL related peripherals.
*/
void board_init() {
lv_init();
lv_port_disp_init();
lv_port_indev_init();
timerInit();
}
/**
* @brief Application initialization routine.
*/
void application_init() {
board_init();
log_cfg_t log_cfg;
thermo21_cfg_t thermo21_cfg;
LOG_MAP_USB_UART(log_cfg);
log_init(&logger, &log_cfg);
log_info(&logger, "---- Application Init ----");
thermo21_cfg_setup(&thermo21_cfg);
THERMO21_MAP_MIKROBUS(thermo21_cfg, MIKROBUS_1);
if (SPI_MASTER_ERROR == thermo21_init(&thermo21, &thermo21_cfg)) {
log_error(&logger, "Communication init.");
for (;;);
}
// Create the temperature label centered on the screen.
thermo21_label = create_label(0, 0, LV_ALIGN_CENTER);
}
/**
* @brief Application task loop.
*/
void application_task() {
float temperature = 0;
if (!thermo21_temperature_read(&thermo21, &temperature)) {
char buffer[50];
snprintf(buffer, sizeof(buffer), "** Temperature : %.2f C", temperature);
log_printf(&logger, "%s\r\n", buffer);
update_label(thermo21_label, buffer);
}
Delay_ms(1500);
}
/**
* @brief Main entry point of the application.
*/
int main(void) {
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init();
while (1) {
lv_task_handler();
Delay_ms(5);
application_task();
}
return 0;
}
static volatile uint32_t msCount = 0;
INTERRUPT_ROUTINE
{
msCount++;
if (5 == msCount) {
msCount = 0;
lv_tick_inc(5);
process_tp();
}
CLEAR_FLAG;
}
Step 4: Install Required Libraries
- Open the
Package Manager
. - Shortcut: Press
CTRL
+5
. - Search for and install the following packages:
- Thermo 21 Click library.
- Verify and Check library installation under the Library Manager.
- Make sure Thermo 21 Click library is checked.
- Make sure Board - (Board-specific library) is checked.
- Make sure Log - (Board-specific library) is checked.
Step 5: Run and Test the Application
- Build the project.
- Shortcut: Press
CTRL
+B
. - Flash the code to your development board.
- Shortcut: Press
CTRL
+SHIFT
+P
.
Observe live readings on the TFT display!
Advanced Code Assistant Capabilities
Ask for Optimizations
You can ask for optimizations or enhancements to your code. For instance:
Ask for Additional Features
You can expand your project by adding more Click boards or GUI elements:
The assistant will generate the appropriate logic, such as:
if (temperature > 30.0) {
lv_label_set_text(alert_label, "WARNING: High Temperature!");
lv_obj_set_style_text_color(alert_label, lv_color_hex(0xFF0000), 0);
}
Why Use NECTO Code Assistant?
- Time-Saving: No need to manually browse through documentation.
- Accurate Solutions: Code is tailored to your specific board and Click modules.
- Interactive Debugging: Quickly test and refine your project with Planet Debug.
Final Thoughts
The NECTO Code Assistant transforms embedded development, enabling engineers to focus on innovation rather than boilerplate code. By integrating with the vast MIKROE ecosystem, the assistant streamlines the development of complex projects with real-time, device-specific code generation. This tool boosts productivity and makes embedded development faster, smarter, and more enjoyable.
🚀 Try it out today and bring your embedded projects to life with just a few clicks!