Hi,
I am using an Arduino Nano BLE sense for my project and require data to be stored on a file in the SD card. Data for multiple subjects will need to be recorded with the same device and SD card, however, we need to be able to identify what data refers to each subject. I thought a potential way to do this would be to ask the user to input a name (either to be used as the name of a new file or just to print to the same file before each subject).
I'm struggling to set this up to take in a string input for BLE that can be used in either of those manners, Below is the code I was attempting to use (adapted from examples as i only have very basic arduino coding knowledge) Any input of how i can do this would be appreciated.
/*
LED
This example creates a BLE peripheral with service that contains a
characteristic to control an LED.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
You can use a generic BLE central app, like LightBlue (iOS and Android) or
nRF Connect (Android), to interact with the services and characteristics
created in this sketch.
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
BLEService BLEStrService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEWordCharacteristic StringCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = LED_BUILTIN; // pin to use for the LED
void setup() {
Serial.begin(9600);
while (!Serial);
// set LED pin to output mode
pinMode(ledPin, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("BLE String");
BLE.setAdvertisedService(BLEStrService);
// add the characteristic to the service
BLEStrService.addCharacteristic(StringCharacteristic);
// add service
BLE.addService(BLEStrService);
// set the initial value for the characeristic:
StringCharacteristic.writeValue("Begin");
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for BLE peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's MAC address:
Serial.println(central.address());
// while the central is still connected to peripheral:
while (central.connected()) {
// if the remote device wrote to the characteristic,
// use the value to control the LED:
if (StringCharacteristic.written()) {
/*
if (StringCharacteristic.value()) { // any value other than 0
Serial.println("LED on");
digitalWrite(ledPin, HIGH); // will turn the LED on
} else { // a 0 value
Serial.println(F("LED off"));
digitalWrite(ledPin, LOW); // will turn the LED off
}
*/
String FileName =StringCharacteristic.value;
Serial.println(FileName);
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}