Hello,
I am trying to send image data captured using Arduino nano BLE 33 sense to Raspberry pi using BLE.
I storing image pixels values in a String variable then I want to send this string to Pi.
when I try to write value to characteristic using writeValue() function, it does not work for string variable but if I write a string in quotation marks it does not show errors.
This code:
imgChar.writeValue(img);
shows this error:
Note: img is the string that I use to store image data
CaptureImgSendPiBle:102:28: error: no matching function for call to
'BLECharacteristic::writeValue(arduino::String&)'
imgChar.writeValue(img);
This is part of the image data that I am trying to send
0x905B, 0x905B, 0xB05B, 0xB05B, 0xB05B, 0xB05B, 0xB05B, 0xD05B, 0xD05B, 0xD05B, 0xD05B, 0xD05B, 0xD05B, 0xB063, 0xB05B, 0xB05B, 0xD05B, 0xD05B, 0xD05B, 0xD05B, 0xB05B, 0xD063, 0xB063, 0xB15B, 0xD163, 0xD063, 0xD063, 0xD163, 0xD163, 0xD163, 0xF163, 0xF163, 0xD163, 0xD163, 0xD163, 0xD163, 0xD16B, 0xF16B, 0xF16B, 0xF16B, 0xF16B, 0xF16B, 0xF16B, 0xF16B ....
How can I send these data through BLE?
The full code:
#include <ArduinoBLE.h>
#include <Arduino_OV767X.h>
// BLE Battery Service
BLEService imgService("66CCBD0A-4051-43E9-8298-C1BD33088331");
// BLE Battery Level Characteristic
BLECharacteristic imgChar("3B4ED73A-7853-4CA8-AED2-AEB6F68F39A3", BLERead, ""); // remote clients will be able to get notifications if this characteristic changes
byte image[176 * 144 * 2]; // QCIF: 176x144 X 2 bytes per pixel (RGB565)
int bytesPerFrame;
bool c = true;
String img = "";
void setup() {
Serial.begin(9600); // initialize serial communication
// while (!Serial);
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected
// 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("Nano");
BLE.setAdvertisedService(imgService); // add the service UUID
imgService.addCharacteristic(imgChar); // add the battery level characteristic
BLE.addService(imgService); // Add the battery service
imgChar.setValue(0); // 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...");
Serial.println(BLE.address());
//init camera
if (!Camera.begin(QCIF, RGB565, 1)) {
Serial.println("Failed to initialize camera!");
while (1);}
bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel();
}
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:
digitalWrite(LED_BUILTIN, HIGH);
// check the battery level every 200ms
// while the central is connected:
while (central.connected()) {
// Take a photo
if (c){
Camera.readFrame(image);
for (int i = 0; i < bytesPerFrame - 1; i += 2) {
Serial.print("0x");
Serial.print(image[i+1], HEX);
Serial.print(image[i], HEX);
if (i != bytesPerFrame - 2) {
Serial.print(", ");
}
img += "0x" + String(image[i+1], HEX) + String (image[i], HEX) + ", ";
}
c = false;
}
imgChar.writeValue(img);
}
// when the central disconnects, turn off the LED:
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
Thank you.