Receiving data problem via bluetooth communication

Hi !
Please help me I am beginner in arduino programming. I have 2 Nano 33 ble sense boards one is the transmitter and the other is the receiver. The problem that arises is the recovery of the data sent via bluetooth from my Nano 33 ble sense card to the other Nano 33 ble card.

With no details on the problem the best advice that I can give is to study the serial input basics tutorial.

What is sent? What is received? Have the 2 Bluetooth modules been paired?

Post the transmitter and the receiver codes. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Thanks for your help.
In the transmitter i send temperature ,pressure and humidity .In the receiver i want to retrieve the values of temperature ,pressure and humidity.

Are you going to answer the questions that I asked?

I am not going to download your code. It is a pain in the behind since I have to make a folder for your code to see it in the IDE and then remember to delete it later. If you want help here, post the code here.

Please post the code inline as described in the forum guidelines that I linked.

Also a schematic of the wiring of the sender and receiver will often be of help.

ok thanks

Hi !
Please help me I am beginner in arduino programming. I have 2 Nano 33 ble sense boards, one is the transmitter and the other is the receiver. In the transmitter, I sent temperature, humidity and pressure data via Bluetooth communication. I cannot recover the data sent by my first Nano 33 ble sense card which is the transmitter on my second Nano 33 ble card card which is the receiver.

Here is the code for the nano 33 ble sense card which sends the data

//

#include <ArduinoBLE.h>
#include <Arduino_HTS221.h>
#include <Arduino_LPS22HB.h>

// Declare the variables for reading barometric pressure, temperature, and humidity, respectively.
float p;
float t;
float h;

// Declare Bluetooth service name, and characteristics. All are standard GATT services.
BLEService environmentalSensingService("181A");

BLEUnsignedIntCharacteristic pressureCharacteristic("2A6D", BLERead); // 32-bit unsigned in Pascals, 1 decimal place.
BLEShortCharacteristic temperatureCharacteristic("2A6E", BLERead); // 16-bit signed, 2 decimal places.
BLEUnsignedIntCharacteristic humidityCharacteristic("2A6F", BLERead); // 16-bit unsigned, 2 decimal places.

// Error pulse of death. Loops forever. Only used if there are problems.
void error_pulse() {
  while (1) {
    for (int i = 0; i < 3; i++) {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(166);
      digitalWrite(LED_BUILTIN, LOW);
      delay(167);
    }
    delay(1001);
  }
}

void setup() {
  // Illuminate LED for 5sec to indicate startup.
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(5000);

  // Initialize serial for debug output.
  Serial.begin(9600);

  // Initialize atmospheric sensors.
  Serial.println("Initializing humidity and temperature sensor.");
  if (!HTS.begin()) {
    Serial.println("Failed.");
    error_pulse();
  }
  Serial.println("Initializing barometric pressure sensor.");
  if (!BARO.begin()) {
    Serial.println("Failed.");
    error_pulse();
  }

  // Initialize Bluetooth communication.
  Serial.println("Initializing Bluetooth communication.");
  if (!BLE.begin()) {
    Serial.println("Failed.");
    error_pulse();
  }

  // Set up Bluetooth Environmental Sensing service.
  Serial.println("Setting up service with characteristics for pressure, temperature, and humidity.");
  BLE.setLocalName("Nano 33 BLE(transmitter)");
  BLE.setAdvertisedService(environmentalSensingService);

  // Add characteristics for barometric pressure, temperature, and humidity.
  environmentalSensingService.addCharacteristic(pressureCharacteristic);
  environmentalSensingService.addCharacteristic(temperatureCharacteristic);
  environmentalSensingService.addCharacteristic(humidityCharacteristic);

  // Make the service available.
  BLE.addService(environmentalSensingService);
  BLE.setConnectable(true);
  Serial.println("Advertising services.");
  BLE.advertise();

  // Turn off LED to indicate startup is complete.
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {

  // Wait for a connection from a central.
  BLEDevice central = BLE.central();

  // When a connection is made, activate LED and write address to serial for debug.
  if (central) {
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.print("Incoming connection from: ");
    Serial.println(central.address());

    while (central.connected()) {
      // Get readings from sensors and update the charcteristic values.
      p = BARO.readPressure(KILOPASCAL);
      t = HTS.readTemperature(CELSIUS) - 4; // Subtract 4 deg C to compensate for heat generated by Nano 33 board.
      h = HTS.readHumidity();

      // Write values to serial port for debug.
      Serial.print("Pressure: ");
      Serial.print(p);
      Serial.println("kPa");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.println("°C");
      Serial.print("Humidity: ");
      Serial.print(h);
      Serial.println("%");

      // Update Bluetooth characteristics with new values.
      pressureCharacteristic.writeValue((uint32_t) round(p * 10000)); // Convert kPa to Pa and shift for one decimal place.
      temperatureCharacteristic.writeValue((int16_t) round(t * 100)); // Shift for two decimal places.
      humidityCharacteristic.writeValue((uint16_t) round(h * 100)); // Shift for two decimal places.

      // Delay between updates. (Don't make too long of connections start to timeout.)
      delay(1000);
    }

    // Turn off LED when connection is dropped.
    digitalWrite(LED_BUILTIN, LOW);
    Serial.println("Connection terminated.");
  }
}

Here is the code for the nano 33 ble sense card which receive the data


#include <ArduinoBLE.h>


BLEService environmentalSensingService("181A");
BLEUnsignedIntCharacteristic pressureCharacteristic("2A6D", BLERead );
BLEShortCharacteristic temperatureCharacteristic("2A6E", BLERead );
BLEUnsignedIntCharacteristic humidityCharacteristic("2A6F", BLERead );
BLEBoolCharacteristic helloCharacteristic("2A00", BLERead | BLEWrite);
void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!BLE.begin()) {
    Serial.println("* Starting Bluetooth® Low Energy module failed!");
    while (1);
  }

  BLE.setLocalName("Nano 33 BLE (receiver)");
  BLE.advertise();

  Serial.println("Arduino Nano 33 BLE Sense (receiver Device)");
  Serial.println(" ");
}

void loop() {
  connectToPeripheral();
}

void connectToPeripheral() {
  BLEDevice peripheral;

  Serial.println("- Discovering peripheral device...");

  do
  {
    BLE.scanForUuid("181A");
    peripheral = BLE.available();
  } while (!peripheral);

  if (peripheral) {
    Serial.println("* Peripheral device found!");
    Serial.print("* Device MAC address: ");
    Serial.println(peripheral.address());
    Serial.print("* Device name: ");
    Serial.println(peripheral.localName());
    Serial.print("* Advertised service UUID: ");
    Serial.println(peripheral.advertisedServiceUuid());
    Serial.println(" ");
    BLE.stopScan();
    controlPeripheral(peripheral);

  }

}

void controlPeripheral(BLEDevice peripheral) {
  Serial.println("- Connecting to peripheral device...");

  if (peripheral.connect()) {
    Serial.println("* Connected to peripheral device!");
    Serial.println(" ");
  } else {
    Serial.println("* Connection to peripheral device failed!");
    Serial.println(" ");
    return;
  }

  Serial.println("- Discovering peripheral device attributes...");
  if (peripheral.discoverAttributes()) {
    Serial.println("* Peripheral device attributes discovered!");
    Serial.println(" ");
    if (peripheral.hasService("181A")) {
      Serial.println("Peripheral has a service");
    }

    else {
      Serial.println("* Peripheral device attributes discovery failed!");
      Serial.println(" ");
      peripheral.disconnect();
      return;
    }

    while (environmentalSensingService) {
      // use the service
      // Serial.println("hello");
      byte p;
      pressureCharacteristic.readValue(p);
      Serial.println("Pressure");
      Serial.println(p);
      Serial.println("kPa");
      byte t = 10;
      temperatureCharacteristic.readValue(t);
      Serial.println("temperature: ");
      Serial.println(t);
      Serial.println("°c");
      byte h;
      humidityCharacteristic.readValue(h);
      Serial.println("Humidity");
      Serial.println(h);
      Serial.println("%");
    }


  }
}



It's best to develop the code in two stages. First, get the sender working correctly with a standard phone app. I like to use Light Blue, but there are others like nrfConnect.

Once you are sending the correct data and know that it can be read, then work on developing the central/receiver.

Thank you for your answer I did the test with the lightblue application I can see the data, the service and the characteristics. But I cannot receive these same data on the Nano 33 ble sense card. If someone have an idea please help me.

"cannot receive" is not an adequate description of the issue?

What does your Serial output tell you? Are you connecting to the peripheral? Are you finding service and the characteristics?

Have you run the library example "Peripheral Explorer" with your device, and does all look correct?

the communication seems correct by what we manage to find the service and the Mac addresses of the peripheral and the central peripheral