### Create Your First Application with Arduino IDE Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/quickstart.mdx This snippet guides users through creating and uploading a "Hello World" application to the kode dot using the Arduino IDE. It covers selecting the correct board, opening the example sketch, and the process of uploading the code and creating a new application on the device. ```arduino #include void setup() { // Initialize the kode dot. kode.begin(); // Print "Hello World" to the console. Serial.println("Hello World"); } void loop() { // Your code here. } ``` -------------------------------- ### Start Local Mintlify Development Server Source: https://github.com/kodediy/docs/blob/main/README.md Starts the local development server for Mintlify. This command should be run at the root of the documentation project, where the 'docs.json' file is located. ```bash mintlify dev ``` -------------------------------- ### Install Mintlify CLI Source: https://github.com/kodediy/docs/blob/main/README.md Installs the Mintlify Command Line Interface globally using npm. This tool is necessary for local development and previewing documentation changes. ```bash npm i -g mintlify ``` -------------------------------- ### LVGL with Arduino on Kode Dot: Setup and Label Display Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/display.mdx This C++ code snippet initializes the LVGL graphics library on a Kode Dot device using the Arduino framework. It sets up the display, touch panel, configures LVGL's display and input devices, and renders a simple 'Hello Arduino, I'm LVGL!' text label on the screen. It also includes commented-out sections for integrating LVGL examples and demos. ```cpp /** * Example of using LVGL with Arduino on Kode Dot. * Sets up the display, touch panel, and draws a simple label. * More info: https://docs.lvgl.io/master/integration/framework/arduino.html */ /* ├─── KODE | docs.kode.diy ─── └ */ #include #include #include #include /*To use the built-in examples and demos of LVGL uncomment the includes below respectively. *You also need to copy lvgl/examples to lvgl/src/examples. Similarly for the demos lvgl/demos to lvgl/src/demos. *Note that the lv_examples library is for LVGL v7 and you shouldn't install it for this version (since LVGL v8) *as the examples and demos are now part of the main LVGL library. */ // #include // #include /* Display resolution and rotation */ #define DSP_HOR_RES 410 #define DSP_VER_RES 502 #define DSP_ROTATION LV_DISPLAY_ROTATION_0 /* LVGL draw buffer size */ #define DRAW_BUF_SIZE (DSP_HOR_RES * DSP_VER_RES / 10 * (LV_COLOR_DEPTH / 8)) static uint8_t *lv_buf1; static uint8_t *lv_buf2; /* Objects to handle display bus and panel */ static Arduino_DataBus *gfxBus; static Arduino_CO5300 *gfx; static BBCapTouch touch; /* Callback for LVGL to push rendered image to the display */ void my_disp_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) { uint32_t w = lv_area_get_width(area); uint32_t h = lv_area_get_height(area); gfx->startWrite(); gfx->writeAddrWindow(area->x1, area->y1, w, h); gfx->writePixels((uint16_t *)px_map, w * h); gfx->endWrite(); /* Tell LVGL flushing is done */ lv_display_flush_ready(disp); } /* Read data from the touch panel */ void my_touchpad_read(lv_indev_t *indev, lv_indev_data_t *data) { TOUCHINFO ti; if (touch.getSamples(&ti) && ti.count > 0) { data->state = LV_INDEV_STATE_PRESSED; data->point.x = ti.x[0]; data->point.y = ti.y[0]; } else { data->state = LV_INDEV_STATE_RELEASED; } } /* Use Arduino's millis() as LVGL tick source */ static uint32_t my_tick(void) { return millis(); } void setup() { Serial.begin(115200); Serial.println("LVGL with Arduino on Kode Dot"); /* ─── Display configuration ─── */ gfxBus = new Arduino_ESP32QSPI(9, 17, 15, 14, 16, 10); gfx = new Arduino_CO5300(gfxBus, 8, 0, 0, DSP_HOR_RES, DSP_VER_RES, 22, 0, 0, 0); if (!gfx->begin()) { Serial.println("Display initialization failed"); while (true) delay(1000); } gfx->setRotation(0); gfx->setBrightness(255); gfx->fillScreen(BLACK); Serial.println("Display initialized"); /* ─── Touch panel configuration ─── */ if (touch.init(48, 47, -1, -1, 400000) == CT_SUCCESS) { touch.setOrientation(0, DSP_HOR_RES, DSP_VER_RES); Serial.printf("Touch OK. Type=%d\n", touch.sensorType()); } else { Serial.println("Touch initialization failed"); } /* ─── Initialize LVGL ─── */ lv_init(); lv_tick_set_cb(my_tick); /* Set tick source */ lv_display_t *disp = lv_display_create(DSP_HOR_RES, DSP_VER_RES); lv_display_set_flush_cb(disp, my_disp_flush); /* Allocate buffers in PSRAM */ lv_buf1 = (uint8_t *)heap_caps_malloc(DRAW_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); lv_buf2 = (uint8_t *)heap_caps_malloc(DRAW_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); lv_display_set_buffers(disp, lv_buf1, lv_buf2, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL); /* Configure input device as a pointer (touch) */ lv_indev_t *indev = lv_indev_create(); lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); lv_indev_set_read_cb(indev, my_touchpad_read); /* ******************* * Create a simple label ******************** */ lv_obj_t *label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello Arduino, I'm LVGL!"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); /* ******************* * Try an example. See all the examples * - Online: https://docs.lvgl.io/master/examples.html * - Source codes: https://github.com/lvgl/lvgl/tree/master/examples ******************** */ // lv_example_btn_1(); /* ******************* * Or try out a demo. Don't forget to enable the demos in lv_conf.h. E.g. LV_USE_DEMO_WIDGETS ******************** */ // lv_demo_music(); } void loop() { lv_timer_handler(); /* Let LVGL handle the GUI */ delay(5); } ``` -------------------------------- ### Arduino RGB Cycle Example for Addressable LED Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/addresable-led.mdx This Arduino code demonstrates controlling a single addressable WS2812B LED connected to GPIO 4. It cycles the LED through red, green, and blue colors, with a half-second duration for each color and a brief off period between color changes. It utilizes the Adafruit_NeoPixel library. The code initializes the NeoPixel strip, sets the color, and updates the display. ```cpp /** * Controls a single NeoPixel connected to GPIO 4, lighting it in red, green, and blue. * Each color stays on for half a second, turning off between changes. * Uses the Adafruit_NeoPixel library to control RGB LEDs. */ /* ────── KODE | docs.kode.diy ────── */ #include /* Library to control NeoPixel strips and LEDs */ #define NEOPIXEL_PIN 4 /* GPIO pin where the NeoPixel is connected */ #define NUMPIXELS 1 /* Number of connected NeoPixels */ #define PIXEL_FORMAT (NEO_GRB + NEO_KHZ800) /* Color format and data speed */ Adafruit_NeoPixel *pixels; #define DELAYVAL 500 /* Delay time between changes (ms) */ void setup() { Serial.begin(115200); /* Start serial communication for debugging */ /* Create the NeoPixel object with the defined parameters */ pixels = new Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, PIXEL_FORMAT); pixels->begin(); /* Initialize the NeoPixel */ pixels->clear(); /* Ensure the LED starts off */ pixels->show(); /* Apply the change */ } void loop() { /* Turn on red */ pixels->setPixelColor(0, pixels->Color(150, 0, 0)); pixels->show(); delay(DELAYVAL); /* Turn off */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); /* Turn on green */ pixels->setPixelColor(0, pixels->Color(0, 150, 0)); pixels->show(); delay(DELAYVAL); /* Turn off */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); /* Turn on blue */ pixels->setPixelColor(0, pixels->Color(0, 0, 150)); pixels->show(); delay(DELAYVAL); /* Turn off */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); } ``` -------------------------------- ### Placeholder for Loop Function Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/microsd.mdx The loop function is intentionally left empty with a brief delay to yield CPU resources. This indicates that all primary operations are handled during the setup phase. ```c++ void loop() { /* Nothing to do in the main loop; brief delay to yield CPU */ delay(10); } ``` -------------------------------- ### Arduino: Motor and Servo Sequential Control Example Source: https://github.com/kodediy/docs/blob/main/en/external-modules/inventor.mdx This Arduino code demonstrates sequential control of two motors (Motor A and Motor B) and a servo. It includes functions for motor direction, braking, coasting, and servo sweeping. The code also includes a sampling mechanism for the Serial Plotter and fault checking. ```Arduino /* Optional header for Serial Plotter */ Serial.println("IA(A)\tIB(A)\tITRIP(A)"); /* Servo setup (50 Hz, constrained to given pulse widths) */ servo.setPeriodHertz(50); servo.attach(PIN_SERVO, SERVO_MIN_US, SERVO_MAX_US); servo.write(SERVO_CENTER); /* 1) Motor A forward then reverse with sampling */ motorA_fwd(); waitWithSampling(T_MOTOR_DIR); motorA_rev(); waitWithSampling(T_MOTOR_DIR); motorA_brake(); delay(100); motorA_coast(); checkFault("Sequence 1 (Motor A)"); /* 2) Motor B forward then reverse with sampling */ motorB_fwd(); waitWithSampling(T_MOTOR_DIR); motorB_rev(); waitWithSampling(T_MOTOR_DIR); motorB_brake(); delay(100); motorB_coast(); checkFault("Sequence 2 (Motor B)"); /* 3) Servo sweep: +90°, -90° (1 s each segment) */ servo.write(SERVO_RIGHT); waitWithSampling(T_SERVO_TRAMO); servo.write(SERVO_LEFT); waitWithSampling(T_SERVO_TRAMO); servo.write(SERVO_CENTER); /* 4) Concurrent sequences */ seqA.start(); seqB.start(); seqS.start(); } ``` -------------------------------- ### Re-install Mintlify Dependencies Source: https://github.com/kodediy/docs/blob/main/README.md Re-installs project dependencies for Mintlify. This command is useful for troubleshooting issues where the 'mintlify dev' command is not running correctly. ```bash mintlify install ``` -------------------------------- ### Read GNSS data via UART Source: https://github.com/kodediy/docs/blob/main/en/external-modules/radio.mdx Example of using the GNSS module via UART. Retrieves latitude, longitude, and altitude using the PVT message. Requires SparkFun_u-blox_GNSS_v3 library. Initializes UART1 on specified pins and sets output to UBX protocol. ```cpp #include /* GNSS object for serial communication */ SFE_UBLOX_GNSS_SERIAL myGNSS; /* ─── GNSS UART pin mapping ─── * GNSS_RX_PIN → MCU pin that receives data from GNSS TX * GNSS_TX_PIN → MCU pin that sends data to GNSS RX */ static const int GNSS_RX_PIN = 44; // MCU receives on GPIO44 static const int GNSS_TX_PIN = 43; // MCU transmits on GPIO43 /* Hardware serial instance (UART1) */ HardwareSerial GNSSSerial(1); void setup() { Serial.begin(115200); delay(1000); Serial.println("u-blox GNSS via UART1 (GPIO44/43)"); /* ─── Initialize UART1 on the specified pins ─── * Baud rate: 38400 * Format: 8 data bits, no parity, 1 stop bit (SERIAL_8N1) */ GNSSSerial.begin(38400, SERIAL_8N1, GNSS_RX_PIN, GNSS_TX_PIN); /* Enable GNSS debug messages on main Serial (optional) */ myGNSS.enableDebugging(Serial); /* Configure UART1 output → UBX protocol only (disable NMEA messages) */ myGNSS.setUART1Output(COM_TYPE_UBX); /* Attempt to connect to the GNSS module until successful */ while (!myGNSS.begin(GNSSSerial)) { Serial.println(F("u-blox GNSS not detected. Retrying...")); delay(1000); } } void loop() { /* If PVT (Position, Velocity, Time) data is available, read and display it */ if (myGNSS.getPVT()) { int32_t lat = myGNSS.getLatitude(); // Latitude in degrees * 10^-7 int32_t lon = myGNSS.getLongitude(); // Longitude in degrees * 10^-7 int32_t alt = myGNSS.getAltitudeMSL(); // Altitude MSL in millimeters Serial.print(F("Lat: ")); Serial.print(lat); Serial.print(F(" Long: ")); Serial.print(lon); Serial.print(F(" (deg*1e-7) Alt: ")); Serial.print(alt); Serial.println(F(" (mm)")); } } ``` -------------------------------- ### Basic Arduino Display Test Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/display.mdx This Arduino code snippet demonstrates how to initialize the CO5300 display using the Arduino_GFX library. It configures the QSPI bus, sets up the display with a specific resolution and orientation, and prints 'Hello World!' to the screen with custom colors. Dependencies include Arduino_GFX_Library, and it utilizes ESP32-S3 specific pins for communication. ```cpp /** * Simple display demo with Arduino_GFX: initializes the panel and draws “Hello World!”. * Uses ESP32-S3 QSPI bus, 410x502 resolution, and max brightness. * Renders large text roughly centered on a blue background. */ /* ────── KODE | docs.kode.diy ────── */ #include #define DSP_HOR_RES 410 #define DSP_VER_RES 502 #define DSP_SCLK 17 #define DSP_SDIO0 15 #define DSP_SDIO1 14 #define DSP_SDIO2 16 #define DSP_SDIO3 10 #define DSP_RST 8 #define DSP_CS 9 /* Objects to handle the graphics bus and display */ static Arduino_DataBus *gfxBus; static Arduino_CO5300 *gfx; void setup() { Serial.begin(115200); delay(100); Serial.println("Simple Display Demo"); /* ── Display configuration ── QSPI bus: CS, SCLK, D0, D1, D2, D3 */ gfxBus = new Arduino_ESP32QSPI(DSP_CS, DSP_SCLK, DSP_SDIO0, DSP_SDIO1, DSP_SDIO2, DSP_SDIO3); /* Panel constructor: bus, RST, rotation offset (0), x/y offset (0,0), width/height, backlight pin (22), options (0,0,0) */ gfx = new Arduino_CO5300(gfxBus, DSP_RST, 0, 0, DSP_HOR_RES, DSP_VER_RES, 22, 0, 0, 0); if (!gfx->begin()) { Serial.println("Error: display init failed"); while (true) /* halt on failure */ ; } gfx->setRotation(0); gfx->setBrightness(255); gfx->displayOn(); Serial.println("Display initialized"); /* Print Hello World! */ gfx->fillScreen(BLUE); gfx->setTextSize(4); gfx->setTextColor(ORANGE); gfx->setCursor(65, 250); gfx->print("Hello World!"); } void loop() { delay(1000); } ``` -------------------------------- ### Read GNSS data via I2C Source: https://github.com/kodediy/docs/blob/main/en/external-modules/radio.mdx Example of using the GNSS module via I2C. Retrieves latitude, longitude, and altitude using the PVT message. Requires SparkFun_u-blox_GNSS_v3 and Wire libraries. Initializes I2C on specified pins and sets output to UBX protocol. ```cpp /** * Example: Reading GNSS (GPS) data from a Kode Radio Module via I2C. * Retrieves latitude, longitude, and altitude from the u-blox module. * Uses the PVT (Position, Velocity, Time) message for data retrieval. */ /* ───────── KODE | docs.kode.diy ───────── */ #include #include /* GNSS module object */ SFE_UBLOX_GNSS myGNSS; void setup() { Serial.begin(115200); delay(1000); Serial.println("Kode Radio Module Example"); /* ─── Initialize I2C with SDA = GPIO48, SCL = GPIO47 ─── */ Wire.begin(48, 47); /* Enable GNSS debug messages on Serial (optional) */ myGNSS.enableDebugging(); // Comment this line to disable debug messages /* Try to connect to the u-blox GNSS module until successful */ while (myGNSS.begin() == false) { Serial.println(F("u-blox GNSS not detected. Retrying...")); delay(1000); } /* Set I2C output to UBX protocol only (disable NMEA messages) */ myGNSS.setI2COutput(COM_TYPE_UBX); } void loop() { /* If PVT data is available, read and display it */ if (myGNSS.getPVT() == true) { /* Get and print latitude */ int32_t latitude = myGNSS.getLatitude(); Serial.print(F("Lat: ")); Serial.print(latitude); /* Get and print longitude */ int32_t longitude = myGNSS.getLongitude(); Serial.print(F(" Long: ")); Serial.print(longitude); Serial.print(F(" (degrees * 10^-7)")); /* Get and print altitude (MSL) */ int32_t altitude = myGNSS.getAltitudeMSL(); Serial.print(F(" Alt: ")); Serial.print(altitude); Serial.print(F(" (mm)")); Serial.println(); } } ``` -------------------------------- ### LVGL 9.3 con Arduino y pantalla CO5300 Source: https://github.com/kodediy/docs/blob/main/es/kode-dot/display.mdx Este código de ejemplo para Arduino configura la librería LVGL 9.3 para su uso con la placa Kode Dot y una pantalla CO5300. Se inicializa el bus gráfico ESP32 QSPI, la pantalla, el controlador táctil y se configuran las funciones de callback para el dibujo y la lectura táctil. El código crea una etiqueta simple y muestra cómo habilitar ejemplos o demos de LVGL. ```cpp /** * Ejemplo de uso de LVGL con Arduino en Kode Dot. * Configura la pantalla, el táctil y dibuja una etiqueta simple. * Más info: https://docs.lvgl.io/master/integration/framework/arduino.html */ /* ╠═════ KODE | docs.kode.diy ╠═════ */ #include #include #include #include /*Para usar los ejemplos y demos de LVGL descomenta los includes de abajo respectivamente. *También necesitas copiar lvgl/examples a lvgl/src/examples. De la misma manera para las demos lvgl/demos a lvgl/src/demos. *Ten en cuenta que la librería lv_examples es para LVGL v7 y no deberías instalarla para esta versión (ya que LVGL v8) *ya que los ejemplos y demos ahora forman parte de la librería principal de LVGL. */ // #include // #include /* Resolución y rotación de la pantalla */ #define DSP_HOR_RES 410 #define DSP_VER_RES 502 #define DSP_ROTATION LV_DISPLAY_ROTATION_0 /* Tamaño del buffer de dibujo de LVGL */ #define DRAW_BUF_SIZE (DSP_HOR_RES * DSP_VER_RES / 10 * (LV_COLOR_DEPTH / 8)) static uint8_t *lv_buf1; static uint8_t *lv_buf2; /* Objetos para manejar el bus gráfico y la pantalla */ static Arduino_DataBus *gfxBus; static Arduino_CO5300 *gfx; static BBCapTouch touch; /* Función de callback para que LVGL dibuje en la pantalla */ void my_disp_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) { uint32_t w = lv_area_get_width(area); uint32_t h = lv_area_get_height(area); gfx->startWrite(); gfx->writeAddrWindow(area->x1, area->y1, w, h); gfx->writePixels((uint16_t *)px_map, w * h); gfx->endWrite(); /* Avisar a LVGL que se ha terminado de refrescar */ lv_display_flush_ready(disp); } /* Lectura del panel táctil */ void my_touchpad_read(lv_indev_t *indev, lv_indev_data_t *data) { TOUCHINFO ti; if (touch.getSamples(&ti) && ti.count > 0) { data->state = LV_INDEV_STATE_PRESSED; data->point.x = ti.x[0]; data->point.y = ti.y[0]; } else { data->state = LV_INDEV_STATE_RELEASED; } } /* Fuente de ticks para LVGL usando millis() */ static uint32_t my_tick(void) { return millis(); } void setup() { Serial.begin(115200); Serial.println("LVGL con Arduino en Kode Dot"); /* ─── Configuración de la pantalla ─── */ gfxBus = new Arduino_ESP32QSPI(9, 17, 15, 14, 16, 10); gfx = new Arduino_CO5300(gfxBus, 8, 0, DSP_HOR_RES, DSP_VER_RES, 0, 22, 0, 0); if (!gfx->begin()) { Serial.println("Error al iniciar la pantalla"); while (true) delay(1000); } gfx->setRotation(0); gfx->setBrightness(255); gfx->fillScreen(BLACK); Serial.println("Pantalla inicializada"); /* ─── Configuración del panel táctil ─── */ if (touch.init(48, 47, -1, -1, 400000) == CT_SUCCESS) { touch.setOrientation(0, DSP_HOR_RES, DSP_VER_RES); Serial.printf("Táctil OK. Tipo=%d\n", touch.sensorType()); } else { Serial.println("No se pudo iniciar el táctil"); } /* ─── Inicializar LVGL ─── */ lv_init(); lv_tick_set_cb(my_tick); /* Fuente de ticks */ lv_display_t *disp = lv_display_create(DSP_HOR_RES, DSP_VER_RES); lv_display_set_flush_cb(disp, my_disp_flush); /* Asignar buffers en PSRAM */ lv_buf1 = (uint8_t *)heap_caps_malloc(DRAW_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); lv_buf2 = (uint8_t *)heap_caps_malloc(DRAW_BUF_SIZE, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); lv_display_set_buffers(disp, lv_buf1, lv_buf2, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL); /* Configurar entrada táctil como puntero */ lv_indev_t *indev = lv_indev_create(); lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); lv_indev_set_read_cb(indev, my_touchpad_read); /* ******************* * Crear una etiqueta simple ******************** */ lv_obj_t *label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello Arduino, I\'m LVGL!"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); /* ******************* * Probar un ejemplo. Ver todos los ejemplos * - En línea: https://docs.lvgl.io/master/examples.html * - Códigos fuente: https://github.com/lvgl/lvgl/tree/master/examples ******************** */ // lv_example_btn_1(); /* ******************* * O probar una demo. No olvides habilitar las demos en lv_conf.h. Por ejemplo, LV_USE_DEMO_WIDGETS ******************** */ // lv_demo_music(); Serial.println("Configuración finalizada"); } void loop() { lv_timer_handler(); /* Procesar eventos de LVGL */ delay(5); } ``` -------------------------------- ### Arduino: Ciclo de colores en LED Direccionable Source: https://github.com/kodediy/docs/blob/main/es/kode-dot/addresable-led.mdx Controla un único LED NeoPixel (WS2812B) conectado al pin GPIO 4 del ESP32-S3. El código enciende el LED en rojo, verde y azul, con una pausa de 500ms entre cada color y un apagado intermedio. Utiliza la librería Adafruit_NeoPixel. ```cpp /** * Controla un único NeoPixel conectado al GPIO 4, encendiéndolo en rojo, verde y azul. * Cada color se mantiene encendido durante medio segundo y se apaga entre cambios. * Usa la librería Adafruit_NeoPixel para el control de LEDs RGB. */ /* ───────── KODE | docs.kode.diy ───────── */ #include /* Librería para controlar tiras y LEDs NeoPixel */ #define NEOPIXEL_PIN 4 /* Pin GPIO donde está conectado el NeoPixel */ #define NUMPIXELS 1 /* Número de NeoPixels conectados */ #define PIXEL_FORMAT (NEO_GRB + NEO_KHZ800) /* Formato de color y velocidad de datos */ Adafruit_NeoPixel *pixels; #define DELAYVAL 500 /* Tiempo de espera entre cambios (ms) */ void setup() { Serial.begin(115200); /* Inicia la comunicación serie para depuración */ /* Crea el objeto NeoPixel con los parámetros definidos */ pixels = new Adafruit_NeoPixel(NUMPIXELS, NEOPIXEL_PIN, PIXEL_FORMAT); pixels->begin(); /* Inicializa el NeoPixel */ pixels->clear(); /* Asegura que el LED empiece apagado */ pixels->show(); /* Aplica el cambio */ } void loop() { /* Enciende en rojo */ pixels->setPixelColor(0, pixels->Color(150, 0, 0)); pixels->show(); delay(DELAYVAL); /* Apaga */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); /* Enciende en verde */ pixels->setPixelColor(0, pixels->Color(0, 150, 0)); pixels->show(); delay(DELAYVAL); /* Apaga */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); /* Enciende en azul */ pixels->setPixelColor(0, pixels->Color(0, 0, 150)); pixels->show(); delay(DELAYVAL); /* Apaga */ pixels->setPixelColor(0, pixels->Color(0, 0, 0)); pixels->show(); delay(DELAYVAL); } ``` -------------------------------- ### Plant Store API Endpoints Source: https://github.com/kodediy/docs/blob/main/api-reference/introduction.mdx This section outlines the available endpoints for interacting with the Plant Store API, including details on authentication and data formats. ```APIDOC ## Plant Store API Endpoints ### Description This API allows users to interact with the Plant Store, enabling operations such as retrieving plant information and managing orders. Authentication is handled via Bearer tokens. ### Method GET, POST, PUT, DELETE (specific methods depend on the endpoint details from the OpenAPI spec) ### Endpoint /api/plants, /api/orders (example endpoints, actual paths are defined in the OpenAPI specification) ### Parameters Parameters (path, query, and body) are defined in the OpenAPI specification file linked below. ### Request Example (Request examples will vary based on the specific endpoint and are detailed in the OpenAPI specification.) ### Response #### Success Response (200) (Success responses will vary based on the specific endpoint and are detailed in the OpenAPI specification.) #### Response Example (Response examples will vary based on the specific endpoint and are detailed in the OpenAPI specification.) **Reference:** [OpenAPI Specification](https://github.com/mintlify/starter/blob/main/api-reference/openapi.json) ``` -------------------------------- ### Arduino Libraries for Power Management Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/power.mdx Lists recommended Arduino libraries for interacting with the PMIC (BQ25896) and Fuel Gauge (BQ27220) components on the kode dot. ```markdown - **PMIC_BQ25896**: [https://github.com/sqmsmu/PMIC_BQ25896](https://github.com/sqmsmu/PMIC_BQ25896) - **kode_bq27220**: [https://github.com/kodediy/kode_bq27220](https://github.com/kodediy/kode_bq27220) ``` -------------------------------- ### ESP-IDF Libraries for Power Management Source: https://github.com/kodediy/docs/blob/main/en/kode-dot/power.mdx Provides links to ESP-IDF components for the PMIC (BQ25896) and Fuel Gauge (BQ27220), facilitating their integration into ESP-IDF projects. ```markdown - **PMIC_BQ25896**: [https://components.espressif.com/components/kodediy/kode_bq25896](https://components.espressif.com/components/kodediy/kode_bq25896) - **Fuel Gauge (BQ27220)**: [https://components.espressif.com/components/kodediy/kode_bq27220/versions/1.0.0](https://components.espressif.com/components/kodediy/kode_bq27220/versions/1.0.0) ``` -------------------------------- ### ESP32 Camera Web Server - Arduino Source: https://github.com/kodediy/docs/blob/main/en/external-modules/camera.mdx This Arduino sketch configures the ESP32-S3 to connect to a WiFi network and stream live video from the OV5640 camera via a web server. It includes pin mappings, camera configuration (resolution, pixel format, JPEG quality), WiFi credentials, and essential ESP32 camera library functions. ```cpp /** * ESP32-S3 Camera Web Server Example. * Configures the camera, connects to WiFi, and serves an MJPEG stream. * Access URL after connection: http:// */ /* ──── KODE | docs.kode.diy ──── */ #include "esp_camera.h" #include /* =========================== WiFi credentials =========================== */ const char *ssid = "**********"; /* WiFi network name */ const char *password = "**********"; /* WiFi network password */ /* External function declarations (implemented elsewhere) */ void startCameraServer(); void setupLedFlash(); void setup() { Serial.begin(115200); Serial.setDebugOutput(true); /* Enable debug output on Serial */ Serial.println(); /* ─── Camera pin mapping and parameters ─── */ camera_config_t config; config.ledc_channel = LEDC_CHANNEL_0; config.ledc_timer = LEDC_TIMER_0; config.pin_d0 = 12; config.pin_d1 = 11; config.pin_d2 = 1; config.pin_d3 = 2; config.pin_d4 = 3; config.pin_d5 = 39; config.pin_d6 = 40; config.pin_d7 = 41; config.pin_xclk = -1; config.pin_pclk = 13; config.pin_vsync = 42; config.pin_href = 43; config.pin_sccb_sda = 48; config.pin_sccb_scl = 47; config.pin_pwdn = -1; config.pin_reset = 44; config.xclk_freq_hz = 20000000; /* XCLK frequency */ config.frame_size = FRAMESIZE_UXGA; /* Initial resolution */ config.pixel_format = PIXFORMAT_JPEG; /* Format for streaming */ //config.pixel_format = PIXFORMAT_RGB565; // Option for face detection config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; config.fb_location = CAMERA_FB_IN_PSRAM; config.jpeg_quality = 12; /* JPEG quality (lower number = higher quality) */ config.fb_count = 1; /* Adjust configuration if PSRAM is available */ if (config.pixel_format == PIXFORMAT_JPEG) { if (psramFound()) { config.jpeg_quality = 10; config.fb_count = 2; config.grab_mode = CAMERA_GRAB_LATEST; } else { /* If PSRAM is not available, reduce resolution to save RAM */ config.frame_size = FRAMESIZE_SVGA; config.fb_location = CAMERA_FB_IN_DRAM; } } else { /* Best settings for face detection/recognition */ config.frame_size = FRAMESIZE_240X240; #if CONFIG_IDF_TARGET_ESP32S3 config.fb_count = 2; #endif } #if defined(CAMERA_MODEL_ESP_EYE) pinMode(13, INPUT_PULLUP); pinMode(14, INPUT_PULLUP); #endif /* ─── Camera initialization ─── */ esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf("Camera init failed with error 0x%x", err); return; } /* Access the camera sensor for extra configuration */ sensor_t *s = esp_camera_sensor_get(); /* Reduce frame size for higher initial frame rate */ if (config.pixel_format == PIXFORMAT_JPEG) { s->set_framesize(s, FRAMESIZE_QVGA); } /* Flip image vertically */ s->set_vflip(s, 1); /* ─── WiFi connection ─── */ WiFi.begin(ssid, password); WiFi.setSleep(false); /* Prevent WiFi from entering sleep mode */ Serial.print("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nWiFi connected"); /* ─── Start the camera web server ─── */ startCameraServer(); Serial.print("Camera Ready! Access at: http://"); Serial.println(WiFi.localIP()); } void loop() { /* Web server handles streaming; main loop is idle */ delay(10000); } ``` -------------------------------- ### ESP32 SD_MMC Initialization and Card Info Source: https://github.com/kodediy/docs/blob/main/es/kode-dot/microsd.mdx Initializes the SD_MMC card in 1-bit mode, sets custom pins, and retrieves card type and size. Includes error handling for pin configuration and card mounting. ```cpp void setup() { Serial.begin(115200); /* Asigna pines personalizados para SD_MMC en modo 1-bit */ if (!SD_MMC.setPins(clk, cmd, d0)) { Serial.println("Pin change failed!"); return; } /* Monta la tarjeta SD vía SD_MMC (path y busWidth=1 para 1-bit) */ if (!SD_MMC.begin("/sdcard", 1)) { Serial.println("Card Mount Failed"); return; } /* Revisa el tipo de tarjeta */ uint8_t cardType = SD_MMC.cardType(); if (cardType == CARD_NONE) { Serial.println("No SD_MMC card attached"); return; } Serial.print("SD_MMC Card Type: "); if (cardType == CARD_MMC) Serial.println("MMC"); else if (cardType == CARD_SD) Serial.println("SDSC"); else if (cardType == CARD_SDHC) Serial.println("SDHC"); else Serial.println("UNKNOWN"); /* Tamaño de la tarjeta en MB */ uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize); /* Imprime espacio total y usado en MB */ Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024)); Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024)); } void loop() { /* Bucle principal sin trabajo: breve retardo para ceder CPU */ delay(10); } ``` -------------------------------- ### Bucle principal para control concurrente y muestreo (Arduino) Source: https://github.com/kodediy/docs/blob/main/es/external-modules/inventor.mdx Implementa el bucle principal (`loop`) que maneja la ejecución concurrente de secuencias para dos motores y un servo. Incluye muestreo continuo de datos para el Serial Plotter y la lógica de finalización de secuencias. ```cpp void loop() { /* Muestreo continuo para el Plotter (~50 Hz) */ static uint32_t tNext = 0; uint32_t now = millis(); if ((int32_t)(now - tNext) >= 0) { sampleAndPrintCurrents(); tNext = now + 20; } /* Secuencia concurrente Motor A */ if (seqA.enabled) { if (seqA.phase == Phase::FWD) { motorA_fwd(); if ((int32_t)(now - seqA.tEnd) >= 0) { seqA.phase = Phase::REV; seqA.tEnd = now + T_MOTOR_DIR; } } else if (seqA.phase == Phase::REV) { motorA_rev(); if ((int32_t)(now - seqA.tEnd) >= 0) { seqA.phase = Phase::DONE; motorA_brake(); delay(50); motorA_coast(); } } } /* Secuencia concurrente Motor B */ if (seqB.enabled) { if (seqB.phase == Phase::FWD) { motorB_fwd(); if ((int32_t)(now - seqB.tEnd) >= 0) { seqB.phase = Phase::REV; seqB.tEnd = now + T_MOTOR_DIR; } } else if (seqB.phase == Phase::REV) { motorB_rev(); if ((int32_t)(now - seqB.tEnd) >= 0) { seqB.phase = Phase::DONE; motorB_brake(); delay(50); motorB_coast(); } } } /* Secuencia concurrente Servo (DERECHA -> IZQUIERDA -> CENTRO) */ if (seqS.enabled) { if (seqS.step == 0) { if ((int32_t)(now - seqS.tEnd) >= 0) { servo.write(SERVO_LEFT); seqS.step = 1; seqS.tEnd = now + T_SERVO_TRAMO; } } else if (seqS.step == 1) { if ((int32_t)(now - seqS.tEnd) >= 0) { servo.write(SERVO_CENTER); seqS.step = 2; } } } /* Condición de fin: ambos motores terminados y servo centrado */ if (seqA.phase == Phase::DONE && seqB.phase == Phase::DONE && seqS.step == 2) { checkFault("Secuencia 4 (concurrente)"); seqA.enabled = seqB.enabled = false; seqS.enabled = false; motorA_coast(); motorB_coast(); while (true) { delay(1000); } /* Mantener aquí tras finalizar */ } } ```