Exemplos do livro Microcontroladores ESP32 como projetos PlatformIO
Compilar exemplos / esp32 (push) Canceled after 21m59s
Compilar exemplos / esp32c2 (push) Canceled after 0s
Compilar exemplos / esp32c3 (push) Canceled after 0s
Compilar exemplos / esp32c5 (push) Canceled after 0s
Compilar exemplos / esp32c6 (push) Canceled after 0s
Compilar exemplos / esp32c61 (push) Canceled after 0s
Compilar exemplos / esp32h2 (push) Canceled after 0s
Compilar exemplos / esp32p4 (push) Canceled after 0s
Compilar exemplos / esp32s2 (push) Canceled after 0s
Compilar exemplos / esp32s3 (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-10 12:10:42 -03:00
commit 5f5506c55c
592 files changed
+12559

No files matched your search

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(tflm_seno)
@@ -0,0 +1,4 @@
# O modelo (2,5 KB) vem pronto no exemplo hello_world do próprio componente.
set(EXEMPLO ${CMAKE_SOURCE_DIR}/managed_components/espressif__esp-tflite-micro/examples)
idf_component_register(SRCS "main.cc" "${EXEMPLO}/hello_world/main/model.cc"
INCLUDE_DIRS "." "${EXEMPLO}/hello_world/main")
@@ -0,0 +1,2 @@
dependencies:
espressif/esp-tflite-micro: "^1.4"
@@ -0,0 +1,46 @@
#include <cmath>
#include "esp_log.h"
#include "esp_timer.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "model.h" // g_model: rede treinada para y = sen(x)
static const char *TAG = "ia";
constexpr int TAM_ARENA = 2000; // memória de trabalho do interpretador
static uint8_t arena[TAM_ARENA];
extern "C" void app_main(void)
{
const tflite::Model *modelo = tflite::GetModel(g_model);
if (modelo->version() != TFLITE_SCHEMA_VERSION) {
ESP_LOGE(TAG, "versão do modelo %lu incompatível", modelo->version());
return;
}
static tflite::MicroMutableOpResolver<1> operacoes;
operacoes.AddFullyConnected(); // a única camada que esta rede usa
static tflite::MicroInterpreter interp(modelo, operacoes, arena, TAM_ARENA);
if (interp.AllocateTensors() != kTfLiteOk) {
ESP_LOGE(TAG, "arena pequena demais");
return;
}
TfLiteTensor *ent = interp.input(0);
TfLiteTensor *sai = interp.output(0);
ESP_LOGI(TAG, "modelo: %d bytes, arena usada: %u de %d bytes", g_model_len,
(unsigned)interp.arena_used_bytes(), TAM_ARENA);
float erro_max = 0;
int64_t t0 = esp_timer_get_time();
for (int i = 0; i <= 8; i++) {
float x = i * 2 * M_PI / 8;
// int8: valor real = (inteiro - zero_point) * scale
long q = lroundf(x / ent->params.scale) + ent->params.zero_point;
ent->data.int8[0] = (int8_t)q;
interp.Invoke();
float y = (sai->data.int8[0] - sai->params.zero_point) * sai->params.scale;
erro_max = fmaxf(erro_max, fabsf(y - sinf(x)));
ESP_LOGI(TAG, "x = %4.2f rede: %6.3f sinf: %6.3f", x, y, sinf(x));
}
int64_t us = esp_timer_get_time() - t0;
ESP_LOGI(TAG, "erro máximo %.3f; 9 inferências em %lld us", erro_max, us);
}
@@ -0,0 +1,22 @@
; Projeto PlatformIO. Compile com: pio run -e <série>
; Grave e abra o monitor: pio run -e <série> -t upload -t monitor
[platformio]
default_envs = esp32
src_dir = main
[env]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.312/platform-espressif32.zip
framework = espidf
monitor_speed = 115200
[env:esp32]
board = esp32dev
[env:esp32s3]
board = esp32-s3-devkitc-1
[env:esp32c3]
board = esp32-c3-devkitm-1
[env:esp32c6]
board = esp32-c6-devkitc-1