Pular para o conteúdo principal

Laboratório 02

TarefaTemplateInícioFimConteúdo
LAB0203-09-202610-09-2026A Internet na IoT;

Checklist — Configuração do Ambiente ESP32 (Parte 02)​

  • Verificar git --version
  • Abrir o VS Code
  • Abrir a extensão PlatformIO IDE
  • Instalar a extensão Wokwi
  • Ativar/configurar o Wokwi
  • Criar um projeto ESP32
  • Selecionar o framework Arduino
  • Executar o primeiro Build
  • Criar wokwi.toml
  • Criar diagram.json
  • Executar a simulação
  • Verificar o Serial Monitor
  • Atualizar o repositório no GitHub
  • Executar git push
  • Confirmar que o projeto está disponível no GitHub
  • Logout

Antes de começar

Confira o ambiente (faça a configuração uma vez por máquina; a verificação, a cada aula):

  1. Instalar as ferramentas — git, GitHub CLI e VS Code
  2. Configurar o git — nome, e-mail e editor padrão (uma vez)
  3. Verificar git, gh e VS Code — deve mostrar as versões e Logged in to github.com

Verificação rápida de versão instalada:

git -v && gh --version && code -v && pio --version && wokwi-cli -V && wsl --version && docker --version

Verificação rápida de autenticação:

git config --get-regexp ^user\. && gh auth status && code --list-extensions --profile "ESP32IO"

Ao terminar — máquina de laboratório

Antes de sair, faça logout para não deixar sua conta do GitHub ativa na máquina (limpa a credencial salva do git e encerra a sessão do gh).


Clone o repositório inicial do LAB02​

Escolha o Grupo e entre com o comando abaixo para criar o repositório no GitHub:

1. Crie e entre na pasta-mãe da disciplina:

mkdir "%USERPROFILE%\ELT85BN21" & cd /d "%USERPROFILE%\ELT85BN21"

2. Clone e entre no repositório do laboratório:

git clone https://github.com/ELT85B-N21-2026-2/lab02-grupo-a.git && cd lab02-grupo-a

3. Verifique status e abra o conteúdo do repositório no perfil ESP32IO do VS Code :

git status && code . --profile "ESP32IO"
Estrutura organizacional dos repositórios
ELT73A-S22-2026-2
├── Times
│ ├── Grupo-A
│ ├── ...
│ ├── Grupo-P # (Professor)
│ └── Grupo-N # (Notas)
└── Repositórios
├── lab02-template
├── lab02-grupo-a
├── ...
├── lab02-grupo-p # (Professor)
└── lab02-grupo-n # (Notas)

Repositório do Grupo A para Laboratório 02:

  1. Copie o link do repositório acima.
  2. Abra a página de envio da atividade no Moodle (botão abaixo).
  3. Clique em Adicionar envio.
  4. Cole o link no campo Texto online.
  5. Clique em Salvar mudanças.
  6. Confira se o status mudou para Enviado para avaliação.
Abrir envio no Moodle
Avaliação por commits

Cada cartão Ponto de commit é uma tarefa: faça-a, copie o comando do cartão e rode. A mensagem começa com o código (T1:, T2:…) — é como a correção identifica sua entrega. Um commit por tarefa; pode refazer (vale o mais recente); e não esqueça o git push. Detalhes em Como funciona a avaliação.


Crie um novo projeto no PlatformIo​

pio project init -b esp32dev -O "framework=arduino" -O "monitor_speed=115200" --sample-code
include - Put project header files here
lib - Put project specific (private) libraries here
src - Put project source files here
platformio.ini - Project Configuration File
Resolving esp32dev dependencies...
Already up-to-date.
Project has been successfully initialized!

Crie ou edite o arquivo src/main.cpp com a seguinte estrutura:

📂 lab02-grupo-x (git repo)/
  • └── 📂src
    • └── 📄main.cpp
#include <Arduino.h>

// Definição de pinos
#define LED_PIN 2

// Protótipos de funções (obrigatório em C/C++ padrão)
void blinkLed(uint8_t pin, uint16_t delayMs);

void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
Serial.println("ESP32 Inicializado!");
}

void loop() {
blinkLed(LED_PIN, 500);
}

// Implementação de funções auxiliares
void blinkLed(uint8_t pin, uint16_t delayMs) {
digitalWrite(pin, HIGH);
delay(delayMs);
digitalWrite(pin, LOW);
delay(delayMs);
}

4. Simulação com Wokwi​

Objetivo: validar lógica sem depender da bancada.

Opção A — Extensão Wokwi no VS Code​

  1. Instale Wokwi Simulator
  2. No projeto, use/crie:
    • diagram.json — circuito (ESP32, LED, fios)
    • wokwi.toml — liga o firmware do PlatformIO ao simulador (conforme docs do template)
  3. Comando típico da extensão: Start Simulator
  4. Abra o monitor serial do Wokwi e veja o mesmo Serial.println

A basic wokwi.toml file looks like this:

[wokwi]
version = 1
firmware = '.pio\build\esp32dev\firmware.bin'
elf = '.pio\build\esp32dev\firmware.elf'

Opção B — Wokwi no navegador​

  1. Acesse wokwi.com
  2. Novo projeto → ESP32
  3. Cole o conteúdo de src/main.cpp
  4. Monte LED no GPIO do LED_BUILTIN (ou no GPIO que o template usar)
  5. Start e observe LED + serial

Exemplo mínimo de ideia de diagram.json (LED no GPIO 2)​

Muitos DevKit tratam LED embutido no GPIO 2 — confirme no template.

Checklist Wokwi

  • Projeto simula e imprime no serial a mensagem do grupo
  • LED pisca conforme o loop()
  • Você não precisou da placa física para esta parte
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-esp32-devkit-v1",
"id": "esp",
"top": 0,
"left": 0,
"attrs": {}
},
{
"type": "wokwi-led",
"id": "led1",
"top": -3.33,
"left": 153.33,
"attrs": { "color": "red" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 64,
"left": 149.33,
"rotate": 90,
"attrs": {}
}
],
"connections": [
["esp:TX0", "$serialMonitor:RX", "", []],
["esp:RX0", "$serialMonitor:TX", "", []],
["esp:GND.1", "led1:C", "black", ["h0"]],
["led1:A", "r1:1", "green", ["v0"]],
["r1:2", "esp:D2", "green", ["h0", "v38"]]
]
}

5. Placa real (opcional, se houver ESP32)​

  1. Conecte o USB
  2. Selecione a porta no PlatformIO (ou pio device list)
  3. Upload + monitor:
pio device list
pio run -t upload
pio device monitor
ProblemaO que tentar
Porta não apareceCabo, driver, outro USB
Upload failSegurar BOOT na gravação (algumas placas)
Serial sem textomonitor_speed = 115200 igual ao Serial.begin

6. Git: salvar o trabalho e entregar​

Depois de build ok (e, se possível, Wokwi ok):

git status
git add src/main.cpp README.md
git commit -m "lab02: mensagem serial do grupo + LED"
git push

README — seção mínima:

## Integrantes

- Nome 1
- Nome 2

## Como rodar

- Build: `pio run`
- Simulação: Wokwi (extensão ou site)
- Placa: `pio run -t upload` && `pio device monitor`

2. Daily workflow​

# Update from remote
git pull

# See status
git status

# Stage changes
git add .
# or specific files:
git add src/main.cpp

# Commit
git commit -m "Implement exercise 2"

# Push to GitHub
git push

If git push asks for a remote branch the first time:

git push -u origin main

3. Useful gh commands for students​

# Open the repo in the browser
gh repo view --web

# View repo info
gh repo view

# List issues
gh issue list

# Create an issue
gh issue create --title "Doubt about exercise 3" --body "..."

# List PRs
gh pr list

# Create a pull request (if you work on a branch)
gh pr create --title "Solution lab00" --body "..."

# Check Actions / CI status
gh run list
gh run view

# Create and switch to a branch
git checkout -b feature/ex2

# Work, commit, push
git add .
git commit -m "Exercise 2"
git push -u origin feature/ex2

# Open a PR into main
gh pr create --base main --title "Exercise 2" --body "Done"

After the PR is merged:

git checkout main
git pull
git branch -d feature/ex2

5. PlatformIO / embedded labs (if applicable)​

# Build
pio run

# Upload to board
pio run -t upload

# Serial monitor
pio device monitor

# Run tests
pio test

6. What you can and cannot do​

ActionAllowed?
Clone / pull / push to your group repoYes (if team has push)
Create branches / commitsYes
Open issues / PRs in your repoYes
Edit other groups’ repos (lab00-grupo-b, …)No
Delete the repositoryNo (usually)
Change team / org settingsNo
Access lab00-template (if private)Only if granted

Your access comes from the team (grupo-a, etc.), not from being repo admin.


7. Quick reference by lab​

LabRepository
LAB00ELT85B-N21-2026-2/lab00-grupo-a
LAB05ELT85B-N21-2026-2/lab05-grupo-a
ProjetoELT85B-N21-2026-2/projeto-grupo-a

Replace a with your group letter (b, c, …).

Clone pattern:

gh repo clone ELT85B-N21-2026-2/lab05-grupo-a

8. Common problems​

Permission denied on push

  • Confirm you are logged in: gh auth status
  • Confirm you are in the right team/repo
  • Ask the instructor to check team access (push on the repo)

Repo not found

gh repo view ELT85B-N21-2026-2/lab00-grupo-a

If 404: wrong name, or you are not a member of the org/team yet.

Merge conflicts

git pull
# fix conflicted files
git add .
git commit -m "Resolve merge conflicts"
git push

Undo local changes (destructive)

git checkout -- .
git clean -fd

9. Minimal “start of lab” checklist​

  1. gh auth status (logged in)
  2. gh repo clone ELT85B-N21-2026-2/labXX-grupo-y
  3. cd labXX-grupo-y
  4. code .
  5. Work → git add → git commit → git push
  6. Check CI: gh run list

10. One-liner cheat card​

clone → gh repo clone ORG/lab00-grupo-a
update → git pull
save → git add . && git commit -m "msg" && git push
web → gh repo view --web
ci → gh run list

Example workflow (.github/workflows/grade.yml):

.github/workflows/grade.yml
name: Build & Test

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Cache PlatformIO
uses: actions/cache@v5
with:
path: |
~/.cache/pip
~/.platformio/.cache
~/.platformio/packages
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"

- name: Install PlatformIO
run: pip install platformio

- name: Build project
run: pio run

# Uncomment if you want native/unit tests in CI
# - name: Run tests
# run: pio test -e native

Logout do seu ambiente dev, git e gh​

Para o git "esquecer" suas informações salvas:

git credential-manager erase && cmdkey /list | findstr "github" && gh auth logout