Arduino UNO R4 WiFi Bluetooth Tabel Voorbeeld - Gestructureerde Gegevensweergave via BLE Tutorial
Overzicht
Het Bluetooth Tabel voorbeeld biedt gestructureerde gegevensweergave via de DIYables Bluetooth STEM app. Ontworpen voor Arduino UNO R4 WiFi met BLE (Bluetooth Low Energy) om sensorwaarden, systeemstatus en alle gegevens in een overzichtelijk tabelformaat op uw smartphone weer te geven. Ondersteunt benoemde rijen met real-time waarde-updates. Perfect voor dashboards, systeembewaking en multi-sensor displays.
Opmerking: De Arduino UNO R4 WiFi ondersteunt alleen BLE (Bluetooth Low Energy). Het ondersteunt geen Classic Bluetooth. De DIYables Bluetooth App ondersteunt zowel BLE als Classic Bluetooth op Android, en BLE op iOS. Omdat dit board BLE gebruikt, werkt de app op zowel Android als iOS.
Functies
Benoemde Rijen: Definieer rijen met labels (bijv. "Temperatuur", "Luchtvochtigheid")
Openbaarmaking: Sommige van de links in deze sectie zijn Amazon-affiliate links. We kunnen een commissie ontvangen voor aankopen die via deze links worden gedaan, zonder extra kosten voor u. We waarderen uw steun.
Verbind het Arduino UNO R4 WiFi board met uw computer via een USB-kabel.
Start de Arduino IDE op uw computer.
Selecteer Arduino UNO R4 WiFi board en de juiste COM-poort.
Navigeer naar het Libraries pictogram in de linkerbalk van de Arduino IDE.
Zoek "DIYables Bluetooth", vind dan de DIYables Bluetooth bibliotheek van DIYables
Klik op de Install knop om de bibliotheek te installeren.
U wordt gevraagd om enkele andere bibliotheek-afhankelijkheden te installeren
Klik op de Install All knop om alle bibliotheek-afhankelijkheden te installeren.
BLE Code
Ga in Arduino IDE naar File Examples DIYables Bluetooth ArduinoBLE_Table voorbeeld, of kopieer de bovenstaande code en plak deze in de editor van 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 Configurationconst 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 instancesDIYables_ArduinoBLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID);DIYables_BluetoothServer bluetoothServer(bluetooth);// Create Table app instanceDIYables_BluetoothTable bluetoothTable;// Variables for demo dataunsignedlong lastUpdate = 0;constunsignedlong UPDATE_INTERVAL = 1000; // Update every secondint counter = 0;voidsetup() {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)unsignedlong 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");}voidloop() {// 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);}
Klik op de Upload knop in Arduino IDE om de code naar de Arduino UNO R4 WiFi te uploaden
Open de Serial Monitor
Bekijk het resultaat in de Serial Monitor. Het ziet er als volgt uit:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.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
Mobiele App
Installeer de DIYables Bluetooth App op uw smartphone: Android | iOS
Opmerking: De DIYables Bluetooth App ondersteunt zowel BLE als Classic Bluetooth op Android, en BLE op iOS. Omdat de Arduino UNO R4 WiFi BLE gebruikt, werkt de app op zowel Android als iOS. Handmatige koppeling is niet nodig voor BLE — scan gewoon en verbind.
Open de DIYables Bluetooth App
Bij het eerste gebruik van de app worden machtigingen gevraagd. Verleen de volgende machtigingen:
Nearby Devices machtiging (Android 12+) / Bluetooth machtiging (iOS) - vereist om Bluetooth apparaten te scannen en er verbinding mee te maken
Location machtiging (alleen Android 11 en lager) - vereist door oudere Android versies om BLE apparaten te scannen
Zorg ervoor dat Bluetooth is ingeschakeld op uw telefoon
Tik op het hoofdscherm op de Connect knop. De app scant naar BLE apparaten.
Zoek en tik op "Arduino_Table" in de scanresultaten om verbinding te maken.
Zodra verbonden, gaat de app automatisch terug naar het hoofdscherm. Selecteer de Table app uit het app-menu.
Opmerking: U kunt op het instellingenpictogram op het hoofdscherm tikken om apps op het hoofdscherm te verbergen/tonen. Voor meer details, zie de DIYables Bluetooth App Gebruikershandleiding.
U ziet een tabel met rijen die Temperatuur, Luchtvochtigheid, Druk, Teller, Uptime, Vrij Geheugen en Status tonen — allemaal real-time updates
Kijk nu terug naar de Serial Monitor in Arduino IDE. U ziet:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.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
Creatieve Aanpassingen - Pas de Code aan voor Uw Project
Tabelstructuur Definiëren
// Voeg rijen toe tijdens setupbluetoothTable.addRow("Temperature", "-- °C");bluetoothTable.addRow("Humidity", "-- %");bluetoothTable.addRow("Pressure", "-- hPa");bluetoothTable.addRow("Status", "Initializing...");
Waarden Updaten
// Update op rijnaambluetoothTable.sendValueUpdate("Temperature", "25.5 °C");bluetoothTable.sendValueUpdate("Status", "Running");// Update op rijindex (0-gebaseerd)bluetoothTable.sendValueUpdate(0, "25.5 °C");bluetoothTable.sendValueUpdate(3, "Running");
Tabelstructuur Verzenden
// Verzend de volledige tabelstructuur opnieuw naar de appbluetoothTable.sendTableStructure();// Behandel gegevensverzoek van appbluetoothTable.onDataRequest([]() { bluetoothTable.sendTableStructure();});
U bent welkom om de link naar deze tutorial te delen. Gebruik onze inhoud echter niet op andere websites. We hebben veel moeite en tijd gestoken in het maken van de inhoud, respecteer alstublieft ons werk!