Hello All,
I am currently working on a project in school where my team and I are trying to use an Arduino Nano 33 BLE to record an analog signal from an electrocardiogram we have constructed, and send this data to an android phone using BLE.
For data input, we are currently using a function generator connected to an Arduino UNO R3 in Tinkercad Circuits to simulate the input of a sine function with frequency 10, amplitude 3.3 V, and DC offset of 1.65 V. Here is the code that we have written for this portion:
int out[100];
void setup()
{
Serial.begin(9600);
// pinMode(13, OUTPUT);
// pinMode(A0, INPUT//);
// analogReadResolution(12)
}
void loop()
{
// analogReadResolution(12);
for( int i = 0; i < 100; i++){
out[i] = analogRead(A0);
//delayMicro(int) ds(100); //microseconds
Serial.println(out[i]);
}
}
The main hurdle now is sending the data using BLE. I am trying to use code, written by Klaus_K, but I do not know how to adapt it to fit the previous code. Here is the BLE code, written by Klaus_K:
#include <ArduinoBLE.h>
//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------
#define BLE_UUID_TEST_SERVICE "9A48ECBA-2E92-082F-C079-9E75AAE428B1"
#define BLE_UUID_FILE_NAME "2D2F88C4-F244-5A80-21F1-EE0224E80658"
//----------------------------------------------------------------------------------------------------------------------
// BLE
//----------------------------------------------------------------------------------------------------------------------
BLEService testService( BLE_UUID_TEST_SERVICE );
BLECharacteristic fileNameCharacteristic( BLE_UUID_FILE_NAME, BLERead | BLEWrite, 20 );
String fileName = "";
void setup()
{
Serial.begin( 9600 );
while ( !Serial );
BLE.begin();
// set advertised local name and service UUID:
BLE.setDeviceName( "Arduino Nano 33 BLE" );
BLE.setLocalName( "Arduino Nano 33 BLE" );
BLE.setAdvertisedService( testService );
// BLE add characteristics
testService.addCharacteristic( fileNameCharacteristic );
// add service
BLE.addService( testService );
// set the initial value for the characeristic:
fileNameCharacteristic.writeValue( fileName );
// start advertising
BLE.advertise();
}
void loop()
{
// listen for BLE peripherals to connect:
BLEDevice central = BLE.central();
if ( central )
{
Serial.print( "Connected to central: " );
Serial.println( central.address() );
while ( central.connected() )
{
if ( fileNameCharacteristic.written() )
{
fileName = fileNameCharacteristic.value();
Serial.print( "New file name: " );
Serial.println( fileName );
}
}
Serial.print( F( "Disconnected from central: " ) );
Serial.println( central.address() );
}
}
Any help would be greatly appreciated and I apologize if the answer is simple; I have little to no experience with programming Arduinos.
Thanks,
Tgab1000