I ve made a thread before , when i was using esp32 , but decided to swap to portenta since esp32 was giving me fatal error in uploading and i had to spam the boot key all the time.
Anyway ,using portenta, i downloaded all neessary libs and currently using ArduinoBLE to send sensor data to my phone .
code is here:
/*
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
#define SERVICE_UUID "my uuid here"
#define CHARACTERISTIC_UUID_TX "and here another one for the characteristic"
#define sensorvalue A0
BLEService ECGservice(SERVICE_UUID );
BLEUnsignedIntCharacteristic ECGchar( CHARACTERISTIC_UUID_TX, BLERead | BLENotify );
long previousMillis = 0;
void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(10, INPUT); // Setup for leads off detection LO +
pinMode(11, INPUT); // Setup for leads off detection LO -
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
/* Set a local name for the BLE device
This name will appear in advertising packets
and can be used by remote devices to identify this BLE device
The name can be changed but maybe be truncated based on space left in advertisement packet
*/
BLE.setLocalName("Ecg Rose");
BLE.setAdvertisedService(ECGservice); // add the service UUID
ECGservice.addCharacteristic(ECGchar); // add the battery level characteristic
BLE.addService(ECGservice); // Add the battery service
ECGchar.writeValue(sensorvalue); // set initial value for this characteristic
/* Start advertising BLE. It will start continuously transmitting BLE
advertising packets and will be visible to remote BLE central devices
until it receives a new connection */
// start advertising
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}
void loop() {
// wait for a BLE central
BLEDevice central = BLE.central();
// if a central is connected to the peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's BT address:
Serial.println(central.address());
// turn on the LED to indicate the connection:
// while the central is connected:
while (central.connected()) {
long currentMillis = millis();
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
ECGchar.writeValue(analogRead(A0));
Serial.println("sensor value : " + String(analogRead(A0)));
}
}
// when the central disconnects, turn off the LED:
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
Problem , as u can see i have these two lines ECGchar.writeValue(analogRead(A0));
Serial.println("sensor value : " + String(analogRead(A0)));
this one ECGchar.writeValue(analogRead(A0)); is to send data , though it doesnt send anything when i got to services in NRF app value is N/A.
this one Serial.println("sensor value : " + String(analogRead(A0))); prints me nicely the values of analog0 .
Whats the problem ? My guess is i had to put this into a char array and dtostrf , but its integer , why it doesnt read it ??