Exemplo de Tabela Bluetooth com Arduino UNO R4 WiFi - Tutorial de Exibição de Dados Estruturados via BLE

Visão Geral

O exemplo de Tabela Bluetooth oferece a exibição de dados estruturados pelo app DIYables Bluetooth STEM. Feito para o Arduino UNO R4 WiFi usando BLE (Bluetooth Low Energy) para exibir leituras de sensores, o status do sistema e quaisquer dados em um formato de tabela limpo no seu smartphone. Suporta linhas com nome e atualizações de valores em tempo real. Perfeito para painéis, monitoramento de sistemas e exibição de vários sensores.

Nota: O Arduino UNO R4 WiFi só suporta BLE (Bluetooth Low Energy). Ele não suporta Bluetooth Clássico. O app DIYables Bluetooth suporta BLE e Bluetooth Clássico no Android, e BLE no iOS. Como esta placa usa BLE, o app funciona no Android e no iOS.

Exemplo de Tabela Bluetooth com Arduino UNO R4 WiFi - Tutorial de Exibição de Dados Estruturados via BLE

Recursos

  • Linhas com Nome: defina linhas com rótulos (por exemplo, "Temperature", "Humidity")
  • Atualizações em Tempo Real: envie atualizações de valores individuais de forma eficiente
  • Sincronização da Estrutura: envia a estrutura da tabela automaticamente ao conectar
  • Dados Flexíveis: exiba qualquer texto ou dado numérico
  • Até 20 Linhas: suporte para vários campos de dados
  • Funciona no Android e no iOS: o BLE é suportado nas duas plataformas
  • Sem Necessidade de Pareamento: o BLE conecta automaticamente, sem pareamento manual

Código Arduino UNO R4 WiFi

Passos Rápidos

Siga estas instruções passo a passo:

  • Se esta é a primeira vez que você usa o Arduino UNO R4 WiFi, consulte o guia de primeiros passos do Arduino UNO R4 WiFi.
  • Conecte a placa Arduino UNO R4 WiFi ao seu computador usando um cabo USB.
  • Abra o Arduino IDE no seu computador.
  • Selecione a placa Arduino UNO R4 WiFi e a porta COM apropriada.
  • Vá até o ícone Libraries na barra lateral esquerda do Arduino IDE.
  • Pesquise "DIYables Bluetooth" e encontre a biblioteca DIYables Bluetooth, da DIYables
  • Clique no botão Install para instalar a biblioteca.
Arduino UNO R4 DIYables Bluetooth library
  • Será pedido que você instale algumas outras dependências da biblioteca
  • Clique no botão Install All para instalar todas as dependências da biblioteca.
Arduino UNO R4 DIYables Bluetooth dependency

Código BLE

  • No Arduino IDE, vá em File Examples DIYables Bluetooth ArduinoBLE_Table para abrir o exemplo, ou copie o código acima e cole no editor do Arduino IDE
/* * DIYables Bluetooth Library - Bluetooth Table Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Table feature: * - Display structured data in a two-column table * - Real-time value updates for each row * - Perfect for sensor dashboards and status displays * * Compatible Boards: * - Arduino UNO R4 WiFi * - Arduino Nano 33 BLE / BLE Sense * - Arduino Nano 33 IoT * - Arduino MKR WiFi 1010 * - Arduino Nano RP2040 Connect * - Any board supporting the ArduinoBLE library * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status * 3. Use DIYables Bluetooth App to connect and view the table * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothTable.h> #include <platforms/DIYables_ArduinoBLE.h> // BLE Configuration const char* DEVICE_NAME = "Arduino_Table"; const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214"; const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214"; const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214"; // Create Bluetooth instances DIYables_ArduinoBLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create Table app instance DIYables_BluetoothTable bluetoothTable; // Variables for demo data unsigned long lastUpdate = 0; const unsigned long UPDATE_INTERVAL = 1000; // Update every second int counter = 0; void setup() { Serial.begin(9600); while (!Serial); Serial.println("DIYables Bluetooth - Table Example"); // Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin(); // Add table app to server bluetoothServer.addApp(&bluetoothTable); // Define table structure (add rows with attribute names) bluetoothTable.addRow("Temperature"); bluetoothTable.addRow("Humidity"); bluetoothTable.addRow("Pressure"); bluetoothTable.addRow("Counter"); bluetoothTable.addRow("Uptime"); bluetoothTable.addRow("Free Memory"); bluetoothTable.addRow("Status"); Serial.print("Table rows defined: "); Serial.println(bluetoothTable.getRowCount()); // Set up connection event callbacks bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send table structure bluetoothTable.sendTableStructure(); // Send initial values updateTableValues(); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); // Optional: Handle requests for table data bluetoothTable.onDataRequest([]() { Serial.println("App requested table data"); bluetoothTable.sendTableStructure(); updateTableValues(); }); Serial.println("Waiting for Bluetooth connection..."); } void updateTableValues() { // TODO: Replace with actual sensor readings // Simulated temperature (20-30°C) float temperature = 20.0 + random(0, 100) / 10.0; bluetoothTable.sendValueUpdate("Temperature", String(temperature, 1) + " °C"); // Simulated humidity (40-60%) int humidity = 40 + random(0, 21); bluetoothTable.sendValueUpdate("Humidity", String(humidity) + " %"); // Simulated pressure (1000-1020 hPa) int pressure = 1000 + random(0, 21); bluetoothTable.sendValueUpdate("Pressure", String(pressure) + " hPa"); // Counter value bluetoothTable.sendValueUpdate("Counter", String(counter)); counter++; // Uptime (in seconds) unsigned long uptime = millis() / 1000; String uptimeStr = String(uptime / 3600) + "h " + String((uptime % 3600) / 60) + "m " + String(uptime % 60) + "s"; bluetoothTable.sendValueUpdate("Uptime", uptimeStr); // Free memory (simulated) int freeMemory = 2048 - random(0, 512); bluetoothTable.sendValueUpdate("Free Memory", String(freeMemory) + " bytes"); // Status bluetoothTable.sendValueUpdate("Status", counter % 2 == 0 ? "Running" : "Active"); // Alternative: Update by index instead of attribute name // bluetoothTable.sendValueUpdate(0, String(temperature, 1) + " °C"); // bluetoothTable.sendValueUpdate(1, String(humidity) + " %"); Serial.println("Table values updated"); } void loop() { // Handle Bluetooth server communications bluetoothServer.loop(); // Update table values periodically (only when connected) if (bluetooth.isConnected() && millis() - lastUpdate >= UPDATE_INTERVAL) { lastUpdate = millis(); updateTableValues(); } delay(10); }
  • Clique no botão Upload no Arduino IDE para carregar o código no Arduino UNO R4 WiFi
  • Abra o Serial Monitor
  • Veja o resultado no Serial Monitor. Ele deve ficar parecido com o abaixo:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
DIYables Bluetooth - Table Example Waiting for Bluetooth connection...
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

App para Celular

  • Instale o app DIYables Bluetooth no seu smartphone: Android | iOS

Nota: O app DIYables Bluetooth suporta BLE e Bluetooth Clássico no Android, e BLE no iOS. Como o Arduino UNO R4 WiFi usa BLE, o app funciona no Android e no iOS. Não é preciso pareamento manual para o BLE — basta procurar e conectar.

  • Abra o app DIYables Bluetooth
  • Ao abrir o app pela primeira vez, ele vai pedir permissões. Conceda as seguintes:
    • Permissão de Dispositivos por Perto (Android 12+) / permissão de Bluetooth (iOS) - necessária para procurar e conectar dispositivos Bluetooth
    • Permissão de Localização (somente Android 11 e anteriores) - exigida por versões mais antigas do Android para procurar dispositivos BLE
  • Verifique se o Bluetooth está ligado no seu celular
  • Na tela inicial, toque no botão Connect. O app vai procurar dispositivos BLE.
DIYables Bluetooth App - Home Screen with Scan Button
  • Encontre e toque em "Arduino_Table" nos resultados da busca para conectar.
  • Depois de conectado, o app volta automaticamente para a tela inicial. Selecione o app Table no menu de apps.
DIYables Bluetooth App - Home Screen with Table App

Nota: Você pode tocar no ícone de configurações na tela inicial para ocultar/mostrar apps na tela inicial. Para mais detalhes, veja o Manual do Usuário do DIYables Bluetooth App.

  • Você verá uma tabela com linhas mostrando Temperature, Humidity, Pressure, Counter, Uptime, Free Memory e Status — todas atualizando em tempo real
DIYables Bluetooth App - Table Screen

Agora volte ao Serial Monitor no Arduino IDE. Você verá:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Bluetooth connected! Sending table updates... Temperature: 25.30 °C Humidity: 55.70 %
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

Personalização Criativa - Adapte o Código ao Seu Projeto

Definir a Estrutura da Tabela

// Add rows during setup bluetoothTable.addRow("Temperature", "-- °C"); bluetoothTable.addRow("Humidity", "-- %"); bluetoothTable.addRow("Pressure", "-- hPa"); bluetoothTable.addRow("Status", "Initializing...");

Atualizar os Valores

// Update by row name bluetoothTable.sendValueUpdate("Temperature", "25.5 °C"); bluetoothTable.sendValueUpdate("Status", "Running"); // Update by row index (0-based) bluetoothTable.sendValueUpdate(0, "25.5 °C"); bluetoothTable.sendValueUpdate(3, "Running");

Enviar a Estrutura da Tabela

// Re-send the full table structure to the app bluetoothTable.sendTableStructure(); // Handle data request from app bluetoothTable.onDataRequest([]() { bluetoothTable.sendTableStructure(); });

Exemplos de Programação

Painel de Estação Meteorológica

DIYables_BluetoothTable bluetoothTable(bluetoothServer); void setup() { bluetoothTable.addRow("Temperature", "-- °C"); bluetoothTable.addRow("Humidity", "-- %"); bluetoothTable.addRow("Pressure", "-- hPa"); bluetoothTable.addRow("Wind Speed", "-- m/s"); bluetoothTable.addRow("Rain", "None"); bluetoothTable.onDataRequest([]() { bluetoothTable.sendTableStructure(); }); } void loop() { bluetoothServer.loop(); static unsigned long lastTime = 0; if (millis() - lastTime >= 2000) { lastTime = millis(); bluetoothTable.sendValueUpdate("Temperature", String(readTemp(), 1) + " °C"); bluetoothTable.sendValueUpdate("Humidity", String(readHumidity(), 1) + " %"); bluetoothTable.sendValueUpdate("Pressure", String(readPressure(), 0) + " hPa"); } }

Monitor de Status do Sistema

void setup() { bluetoothTable.addRow("Uptime", "0s"); bluetoothTable.addRow("Free RAM", "-- bytes"); bluetoothTable.addRow("WiFi RSSI", "-- dBm"); bluetoothTable.addRow("IP Address", "N/A"); bluetoothTable.addRow("Status", "Starting..."); } void loop() { bluetoothServer.loop(); static unsigned long lastTime = 0; if (millis() - lastTime >= 1000) { lastTime = millis(); unsigned long uptime = millis() / 1000; String uptimeStr = String(uptime / 3600) + "h " + String((uptime % 3600) / 60) + "m " + String(uptime % 60) + "s"; bluetoothTable.sendValueUpdate("Uptime", uptimeStr); bluetoothTable.sendValueUpdate("Status", "Running"); } }

Tutorial em Vídeo

O vídeo de demonstração abaixo usa o código abaixo:

/* * Este código de Arduino UNO R4 foi desenvolvido por pt.newbiely.com * Este código de Arduino UNO R4 é disponibilizado ao público sem nenhuma restrição. * Para tutoriais completos e diagramas de ligação, visite: * https://pt.newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-diyables-bluetooth-app-table */ /* * DIYables Bluetooth Library - Bluetooth Table Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Table feature: * - Display structured data in a two-column table * - Real-time value updates for each row * - Perfect for sensor dashboards and status displays * * Compatible Boards: * - Arduino UNO R4 WiFi * - Arduino Nano 33 BLE / BLE Sense * - Arduino Nano 33 IoT * - Arduino MKR WiFi 1010 * - Arduino Nano RP2040 Connect * - Any board supporting the ArduinoBLE library * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status * 3. Use DIYables Bluetooth App to connect and view the table * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothTable.h> #include <platforms/DIYables_ArduinoBLE.h> #include <DHT.h> // BLE Configuration const char* DEVICE_NAME = "Arduino_Table"; const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214"; const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214"; const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214"; // Create Bluetooth instances DIYables_ArduinoBLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create Table app instance DIYables_BluetoothTable bluetoothTable; // Variables for demo data #define DHTPIN 3 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); unsigned long lastUpdate = 0; const unsigned long UPDATE_INTERVAL = 1000; // Update every second bool ledState = false; int counter = 0; void setup() { Serial.begin(9600); while (!Serial); Serial.println("DIYables Bluetooth - Table Example"); // Initialize built-in LED pinMode(LED_BUILTIN, OUTPUT); dht.begin(); // Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin(); // Add table app to server bluetoothServer.addApp(&bluetoothTable); // Define table structure (add rows with attribute names) bluetoothTable.addRow("Temperature"); bluetoothTable.addRow("Humidity"); bluetoothTable.addRow("LED Status"); bluetoothTable.addRow("Pressure"); bluetoothTable.addRow("Counter"); bluetoothTable.addRow("Uptime"); bluetoothTable.addRow("Free Memory"); bluetoothTable.addRow("Status"); Serial.print("Table rows defined: "); Serial.println(bluetoothTable.getRowCount()); // Set up connection event callbacks bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send table structure bluetoothTable.sendTableStructure(); // Send initial values updateTableValues(); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); // Optional: Handle requests for table data bluetoothTable.onDataRequest([]() { Serial.println("App requested table data"); bluetoothTable.sendTableStructure(); updateTableValues(); }); Serial.println("Waiting for Bluetooth connection..."); } void updateTableValues() { // TODO: Replace with actual sensor readings // Simulated temperature (20-30°C) //float temperature = 20.0 + random(0, 100) / 10.0; float temperature = dht.readTemperature(); bluetoothTable.sendValueUpdate("Temperature", String(temperature, 1) + " °C"); // Simulated humidity (40-60%) //int humidity = 40 + random(0, 21); int humidity = dht.readHumidity(); bluetoothTable.sendValueUpdate("Humidity", String(humidity) + " %"); // Simulated pressure (1000-1020 hPa) int pressure = 1000 + random(0, 21); bluetoothTable.sendValueUpdate("Pressure", String(pressure) + " hPa"); // Counter value bluetoothTable.sendValueUpdate("Counter", String(counter)); counter++; // Uptime (in seconds) unsigned long uptime = millis() / 1000; String uptimeStr = String(uptime / 3600) + "h " + String((uptime % 3600) / 60) + "m " + String(uptime % 60) + "s"; bluetoothTable.sendValueUpdate("Uptime", uptimeStr); // Free memory (simulated) int freeMemory = 2048 - random(0, 512); bluetoothTable.sendValueUpdate("Free Memory", String(freeMemory) + " bytes"); // Status bluetoothTable.sendValueUpdate("Status", counter % 2 == 0 ? "Running" : "Active"); // Alternative: Update by index instead of attribute name // bluetoothTable.sendValueUpdate(0, String(temperature, 1) + " °C"); // bluetoothTable.sendValueUpdate(1, String(humidity) + " %"); Serial.println("Table values updated"); } void loop() { // Handle Bluetooth server communications bluetoothServer.loop(); // Update table values periodically (only when connected) if (bluetooth.isConnected() && millis() - lastUpdate >= UPDATE_INTERVAL) { lastUpdate = millis(); updateTableValues(); } // Toggle LED every 3 seconds static unsigned long lastLedToggle = 0; if (millis() - lastLedToggle > 3000) { ledState = !ledState; digitalWrite(LED_BUILTIN, ledState); // Send LED status update to web interface bluetoothTable.sendValueUpdate("LED Status", ledState ? "ON" : "OFF"); lastLedToggle = millis(); } delay(10); }

Solução de Problemas

Problemas Comuns

1. Não consigo encontrar o dispositivo no app

  • Verifique se o Arduino UNO R4 WiFi está ligado e se o sketch foi carregado
  • Verifique se o Bluetooth do seu celular está ativado
  • No Android 11 e anteriores, ative também os serviços de Localização

2. A tabela está vazia ou as linhas não aparecem

  • Garanta que addRow() seja chamado em setup() antes de conectar
  • Implemente o callback onDataRequest para reenviar a estrutura
  • Confirme que sendTableStructure() está sendo chamado

3. Os valores não atualizam

  • Verifique se sendValueUpdate() está sendo chamado no loop
  • Confirme que o nome da linha é exatamente igual (diferencia maiúsculas de minúsculas)
  • Garanta que bluetoothServer.loop() seja chamado a cada iteração do loop

4. Os nomes das linhas não coincidem

  • Os nomes das linhas diferenciam maiúsculas de minúsculas — "Temperature" ≠ "temperature"
  • Use o índice da linha (começando em 0) como alternativa aos nomes das linhas

5. O upload falha ou a placa não é reconhecida

  • Instale o pacote de placas Arduino UNO R4 mais recente pelo Board Manager
  • Tente outro cabo ou outra porta USB

Ideias de Projetos

  • Painel de estação meteorológica
  • Monitor de recursos do sistema
  • Exibição de dados de vários sensores
  • Painel de configuração de dispositivo
  • Quadro de status de dispositivos IoT

Próximos Passos

Depois de dominar o exemplo de Tabela Bluetooth, experimente:

  1. Bluetooth Plotter - Para visualização gráfica de dados
  2. Bluetooth Monitor - Para interação em texto
  3. Bluetooth Temperature - Para exibição em estilo de medidor
  4. Multiple Bluetooth Apps - Combinando a tabela com outros apps

Suporte

Para ajuda adicional:

  • Consulte a documentação de Referência da API
  • Fóruns da comunidade Arduino

※ NOSSAS MENSAGENS

  • Fique à vontade para compartilhar o link deste tutorial. Porém, por favor, não use nosso conteúdo em outros sites. Investimos muito esforço e tempo para criar este conteúdo, por favor respeite nosso trabalho!