'writeValue(char [20], int&)' is ambiguous

Hello :slight_smile:

With my friend, we want to connect an Arduino and a phone with BLE connection. we have already managed to do it on his mac, but when I try to do it on my computer (on windows), I have a problem with "writeValue" function. I’m can’t understand why it doesn’t work for me.

I’m using an Arduino BLE sense with and IMU (BNO055).

Here is my code :

#include <Arduino.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <ArduinoBLE.h>

#define BLE_BUFFER_SIZES             20
/* Device name which can be scene in BLE scanning software. */
#define BLE_DEVICE_NAME                "Arduino Nano 33 BLE Sense"
/* Local name which should pop up when scanning for BLE devices. */
#define BLE_LOCAL_NAME                "IMU Euler Angles"
/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
//                                   id, address
Adafruit_BNO055 bno = Adafruit_BNO055(-1, 0x28);

BLEService BLEuler("590d65c7-3a0a-4023-a05a-6aaf2f22441c");
BLECharacteristic YawBLE("0004", BLERead | BLENotify /*| BLEBroadcast */, BLE_BUFFER_SIZES);
BLECharacteristic PitchBLE("0005", BLERead | BLENotify /*| BLEBroadcast*/, BLE_BUFFER_SIZES);
BLECharacteristic RollBLE("0006", BLERead | BLENotify /*| BLEBroadcast*/, BLE_BUFFER_SIZES);

/* Common global buffer will be used to write to the BLE characteristics. */
char bleBuffer[BLE_BUFFER_SIZES];


void setup() {
  
  Serial.begin(115200);
  while(!Serial);

  pinMode(LED_BUILTIN, OUTPUT);
  
  BLE.begin();
  bno.begin();
    
  BLE.setDeviceName(BLE_DEVICE_NAME);
  BLE.setLocalName(BLE_LOCAL_NAME);
  BLE.setAdvertisedService(BLEuler);
  /* A seperate characteristic is used for each X, Y, and Z axis. */
  BLEuler.addCharacteristic(YawBLE);
  BLEuler.addCharacteristic(PitchBLE);
  BLEuler.addCharacteristic(RollBLE);

  BLE.addService(BLEuler);
  BLE.advertise();
  /* 
   * Initialises the IMU sensor, and starts the periodic reading of the 
   * sensor using a Mbed OS thread. The data is placed in a circular 
   * buffer and can be read whenever.
   */
  bno.setExtCrystalUse(true);
  
}

void loop() {

  

  BLEDevice central = BLE.central();
    if(central)
    {
        int writeLength;
        /* 
         * If a BLE device is connected, gyroscope data will start being read, 
         * and the data will be written to each BLE characteristic. The same 
         * data will also be output through serial so it can be plotted using 
         * Serial Plotter. 
         */
        while(central.connected())
        {            
            digitalWrite(LED_BUILTIN, HIGH);
            imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
            /* 
             * sprintf is used to convert the read float value to a string 
             * which is stored in bleBuffer. This string is then written to 
             * the BLE characteristic. 
             */
            writeLength = sprintf(bleBuffer, "%f", euler.x());
            YawBLE.writeValue(bleBuffer, writeLength); 
            
            writeLength = sprintf(bleBuffer, "%f", euler.y());
            PitchBLE.writeValue(bleBuffer, writeLength);   
               
            writeLength = sprintf(bleBuffer, "%f", euler.z());
            RollBLE.writeValue(bleBuffer, writeLength);      

            Serial.print("Yaw: ");
            Serial.print(euler.x());
            Serial.print(" Pitch: ");
            Serial.print(euler.y());
            Serial.print(" Roll: ");
            Serial.print(euler.z());
            Serial.print("\t\t\n");

            delay(BNO055_SAMPLERATE_DELAY_MS);
        }

        digitalWrite(LED_BUILTIN, LOW);
        Serial.print("Disconnected from central");
    }
}

Here is my error :

Arduino : 1.8.13 (Windows 10), Carte : "Arduino Nano 33 BLE"
D:\Raccourci Bureau\Cours\E5\Projet Fil Rouge\Walking-Analysis-Project-main\Arduino\BNO055_BLE\BNO055_BLE.ino: In function 'void loop()':
BNO055_BLE:81:53: error: call of overloaded 'writeValue(char [20], int&)' is ambiguous
             YawBLE.writeValue(bleBuffer, writeLength);
                                                     ^
In file included from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEService.h:23:0,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEDevice.h:25,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/local/BLELocalDevice.h:23,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/ArduinoBLE.h:23,
                 from D:\Raccourci Bureau\Cours\E5\Projet Fil Rouge\Walking-Analysis-Project-main\Arduino\BNO055_BLE\BNO055_BLE.ino:5:
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:72:7: note: candidate: int BLECharacteristic::writeValue(const void*, int, bool)
   int writeValue(const void* value, int length, bool withResponse = true);
       ^~~~~~~~~~
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:73:7: note: candidate: int BLECharacteristic::writeValue(const char*, bool)
   int writeValue(const char* value, bool withResponse = true);
       ^~~~~~~~~~
BNO055_BLE:84:55: error: call of overloaded 'writeValue(char [20], int&)' is ambiguous
             PitchBLE.writeValue(bleBuffer, writeLength);
                                                       ^
In file included from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEService.h:23:0,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEDevice.h:25,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/local/BLELocalDevice.h:23,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/ArduinoBLE.h:23,
                 from D:\Raccourci Bureau\Cours\E5\Projet Fil Rouge\Walking-Analysis-Project-main\Arduino\BNO055_BLE\BNO055_BLE.ino:5:
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:72:7: note: candidate: int BLECharacteristic::writeValue(const void*, int, bool)
   int writeValue(const void* value, int length, bool withResponse = true);
       ^~~~~~~~~~
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:73:7: note: candidate: int BLECharacteristic::writeValue(const char*, bool)
   int writeValue(const char* value, bool withResponse = true);
       ^~~~~~~~~~
BNO055_BLE:87:54: error: call of overloaded 'writeValue(char [20], int&)' is ambiguous
             RollBLE.writeValue(bleBuffer, writeLength);
                                                      ^
In file included from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEService.h:23:0,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLEDevice.h:25,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/local/BLELocalDevice.h:23,
                 from C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/ArduinoBLE.h:23,
                 from D:\Raccourci Bureau\Cours\E5\Projet Fil Rouge\Walking-Analysis-Project-main\Arduino\BNO055_BLE\BNO055_BLE.ino:5:
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:72:7: note: candidate: int BLECharacteristic::writeValue(const void*, int, bool)
   int writeValue(const void* value, int length, bool withResponse = true);
       ^~~~~~~~~~
C:\Users\Arthu\OneDrive\Documents\Arduino\libraries\ArduinoBLE\src/BLECharacteristic.h:73:7: note: candidate: int BLECharacteristic::writeValue(const char*, bool)
   int writeValue(const char* value, bool withResponse = true);
       ^~~~~~~~~~
exit status 1
call of overloaded 'writeValue(char [20], int&)' is ambiguous

Thank your for your help and answers :wink:

Welcome,

Here are all the prototypes for this function :

  int writeValue(const uint8_t value[], int length, bool withResponse = true);
  int writeValue(const void* value, int length, bool withResponse = true);
  int writeValue(const char* value, bool withResponse = true);
  int writeValue(uint8_t value, bool withResponse = true);
  int writeValue(int8_t value, bool withResponse = true);
  int writeValue(uint16_t value, bool withResponse = true);
  int writeValue(int16_t value, bool withResponse = true);
  int writeValue(uint32_t value, bool withResponse = true);
  int writeValue(int32_t value, bool withResponse = true);

You can see that when the first parameter is a pointer to a char array (the third prototype in this list), you don’t need the length parameter

it looks like writeValue () has two prototypes

int BLECharacteristic::writeValue(const void*, int, bool)

and

int BLECharacteristic::writeValue(const char*, bool)

your attempt to pass an array and length is not one of them

'writeValue(char [20], int&)' is ambiguous

looks like you're missing a boolean 3rd arg

looks like you're missing a boolean 3rd arg

Those all have default values.
I think the issue is that YawBLE.writeValue(bleBuffer, writeLength);you pass a char-array, which can be a char* but for that it has to be null-terminated (which the compiler doesn't know), or it can be a 'signed' int8_t, with which you pass the length, as you do. But then the function takes the unsigned version. So either remove the length if you are sure that the array is null-terminated, or leave the length, but change the array to an 'unsigned char' or uint8_t.

Compiler is confused because bleBuffer could be interpreted as void*, and writeLength could be interpreted as bool, so it can't guess which one of these two prototypes must be used :slight_smile:

int writeValue(const void* value, int length, bool withResponse = true);
int writeValue(const char* value, bool withResponse = true);

or this oneint writeValue(const uint8_t value[], int length, bool withResponse = true);

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.