Arduino UNO R4 WiFi, BLE: only one characteristic of 3 is shown

I'm testing my new arduino uno r4 wifi and i decided to try BLE.
I'm trying to change the value of 3 variables inside the arduino from my smartphone.
I'm trying assigning one characteristic to each variable, but when trying with one characteristic it works and the characteristic shows on the smartphone but when I increase the characteristic number the new characteristics does't show on the connected smartphone.
Here is the code, as you can see is going to be used for a line follower robot:

#include <ArduinoBLE.h>

BLEService mainService("12345678-1234-5678-1234-56789abcdef0");
BLEIntCharacteristic kpCharacteristic("abcdef01-1234-5678-1234-56789abcdef0", BLERead | BLEWrite);
BLEIntCharacteristic kdCharacteristic("abcdef02-1234-5678-1234-56789abcdef0", BLERead | BLEWrite);
BLEIntCharacteristic kiCharacteristic("abcdef03-1234-5678-1234-56789abcdef0", BLERead | BLEWrite);

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

  delay(5000);

  if (!BLE.begin()) {
    Serial.println("error initializing BLE!");
    while (1);
  }

  BLE.setLocalName("ArduinoR4");
  BLE.addService(mainService);
  mainService.addCharacteristic(kpCharacteristic);
  mainService.addCharacteristic(kdCharacteristic);
  mainService.addCharacteristic(kiCharacteristic);
  BLE.setAdvertisedService(mainService);

  kpCharacteristic.writeValue(0);
  kdCharacteristic.writeValue(0);
  kiCharacteristic.writeValue(0);

  BLE.setAdvertisingInterval(100);

  BLE.advertise();
  Serial.println("Ready for BLE connection");

}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to: ");
    Serial.println(central.address());

    while (central.connected()) {
      if (kpCharacteristic.written()) {
        int val = kpCharacteristic.value();
        Serial.print("Kp set to: ");
        Serial.println(val);
        }
      
      if (kdCharacteristic.written()) {
        int val = kdCharacteristic.value();
        Serial.print("KD set to: ");
        Serial.println(val);
        }
      if (kiCharacteristic.written()) {
        int val = kiCharacteristic.value();
        Serial.print("KI set to: ");
        Serial.println(val);
        }

      }
    if (central.disconnect()){
      Serial.print("Disconnected from: ");
      Serial.println(central.address());
      }
    }
  }

I can't try but may be try inverting where you use setAdvertisedService and addService

  BLE.setDeviceName("ArduinoR4");
  BLE.setLocalName("PidMonitor");
  BLE.setAdvertisedService(mainService);                    // <===== setAdvertisedService here
  mainService.addCharacteristic(kpCharacteristic);
  mainService.addCharacteristic(kdCharacteristic);
  mainService.addCharacteristic(kiCharacteristic);
  BLE.addService(mainService);                              // <===== addService here

Sorry it didn't work, but thanks anyway.

ok... thanks for trying. I don't have access to a board compatible with ArduinoBLE.h at the moment...

I agree with @J-M-L .

When I change your code to look like this, I can see and write all three characteristics with LightBlue on an Android phone.

BLE.setLocalName("ArduinoR4");
  //BLE.addService(mainService);
  BLE.setAdvertisedService(mainService);
  mainService.addCharacteristic(kpCharacteristic);
  mainService.addCharacteristic(kdCharacteristic);
  mainService.addCharacteristic(kiCharacteristic);
  //BLE.setAdvertisedService(mainService);
  BLE.addService(mainService);
Kp set to: 10
KD set to: 11
KI set to: 12

EDIT:
I ran your code on a Nano33BLE and not a UNO R4 WiFi.

I have tried both lightblue and nrf connect, but on lighblue I connect, I can see the service, but associated with that service there is only one characteristic.
I also tried making a simple app with mit app inventor, but when I try to write to a characteristic that is not the first one the app crashes and in the error it says it can't find the characteristic.
And even with the modified code, as @J-M-L suggested, there is no change.

Edit:


As you can see from the screenshot the service UUID is correct, but there is only the first characteristic.

On my phone, I can scroll up from what you posted and see two additional characteristics.

I, on the other hand, cannot scroll past the first characteristic.
Just as if the other two do not exist.
I hope it's not a problem with the arduino that it's stuck on tests done previously.

EDIT:
I tried again by changing all the uuids with an online generator, reloaded the new code on the arduino, but on lightblue I kept seeing the old uuids, both for the service and for the one characteristic I can see.

I have seen this behaviour with LightBlue, and I don't recall what I did to reset LightBlue. Maybe turn off the BLE Arduino, make certain that its not showing in Light Blue, reconnect the Arduino, reopen the sketch and then rescan?

What do you see with nrfConnect? When you tap on the service, I see three characteristics open up.

I tried uninstalling lightblue after removing all data from it and then reinstalling it thus starting over, reloaded the code in the arduino, but nothing changed.

here what i can see on nrfconnect:

I don't have an uno r4 wifi so can't replicate

May be it's a bug as it seems to work on the Nano33BLE

I have just tried with the attached sketch on my R4-wifi and it works without problems with my Android / nrfconnect. I have used ArduinoBLE 1.3.7 (latest at this moment).
sketch_aug18a-r4.ino (1.9 KB)

I tried loading @paulvha's sketch and completely at random it worked.
I have no idea how, but with your sketch it works.
this is what i can see now:


I don't know how, but now it works.
So can say thanks.
Edit:
now on every time i connect i delete lightblue's data and then upload the sketch.
So, i think, my arduino got bugged somehow and somehow the problem solved itself changing sketch

Now i'll tell thanks to everyone who writed in this chat trying to help me, so thank you :heart:.

Good — have fun!

Thanks