Connect 2 arduino nano 33 BLE

Hello, I need to connect 2 arduino nano 33 BLE so that they can send data in both directions, would you be able to help me? (sorry for english, i wrote it using google translator)

Welcome to the forum.

There are sub forums for other languages if you feel more comfortable with your native language. But English is the language for the electronic industry so you might as well stay here and use the opportunity to learn. :slight_smile:

In BLE you do not send data from an applications point of view. You have a peripheral/server and a central/client. The peripheral is usually the sensor/low power device collecting data and the client often is a smartphone or similar device but can be an Arduino and it is reading or writing data. The client is the customer. It decides what data it wants to write or read. The server can control access, but it cannot force the client to do anything.

Download the ArduinoBLE library and have a look at the Examples. There are peripheral and client examples. Some work together. Start with the following:

File -> Examples -> ArduinoBLE -> Peripheral -> LED
File -> Examples -> ArduinoBLE -> Peripheral -> BatteryMonitor

Download a generic BLE app. I use BLE Scanner from bluepixel technologies on iPhone. There are many others on iOS and Android. Connect and look at the services and characteristics. See if you can find the data from the sketch and switch the led.

Next disconnect your phone and use the following example on your second Arduino.

File -> Examples -> ArduinoBLE -> Central -> LEDControl

Try to get them to work together and understand the code. You are almost done.

Please have a look at the "How to post" it is at the beginning of each sub forum. Let me know what kind of data you want to send. If you have some code, please use code tags. And if you use any non-Arduino modules or components please add a link to the datasheet.

There are lots of additional information and examples in the forum. If you feel like browsing around have a go. This sub forum is quite specific to BLE, so you will find interesting stuff.

Hi, could you write me an example of how to use arduino nano 33 BLE to read File -> Examples -> ArduinoBLE -> Peripheral -> BatteryMonitor. Thanks.

martindebnar:
Hi, could you write me an example of how to use arduino nano 33 BLE to read File -> Examples -> ArduinoBLE -> Peripheral -> BatteryMonitor. Thanks.

Have a look in the following post reply #3.

The example is for reading multiple BatteryMonitor devices. When I wrote the example, only the Arduino Nano 33 IoT was able to read multiple devices. There was an issue with the Nano 33 BLE, it could only read one.

#include <ArduinoBLE.h> //BLE Library.

const char* BLE_UUID_BATTERY_SERVICE1 = "180F";
const char* BLE_UUID_BATTERY_SERVICE2 = "190F";
const char* BLE_UUID_PRESSURE1 = "2A19";
const char* BLE_UUID_PRESSURE2 = "2A6E";



boolean updatePeripheral = false;
boolean updateNow = false;
boolean bleActive = false;

int prvyLoop = 0;
int premena = 0;
int sensorCount = 0;

void setup() {
  Serial.begin(9600); //Serial monitor to display all sensor values

  pinMode(LED_BUILTIN, OUTPUT); //Built-in LED.
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
#define UPDATE_INTERVAL 5 * 1000

  if (updatePeripheral == false) {
    static unsigned long previousMillis = 0;
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis > UPDATE_INTERVAL) {
      previousMillis = currentMillis;
      //sensorsCheck();
      sensorCount ++;
      Serial.print("Sensor Count = "); Serial.println(sensorCount);
    }
  }

  if (sensorCount == 7) {
    updateNow = false;
    updatePeripheral = true;
    sensorCount = 0;
  }

    bleTask();

}




void bleTask() {
  const char* BLE_UUID_BATTERY_SERVICE;
  const char* BLE_UUID_PRESSURE;
   if (premena == 0) {
    BLE_UUID_BATTERY_SERVICE = BLE_UUID_BATTERY_SERVICE1;
    BLE_UUID_PRESSURE = BLE_UUID_PRESSURE1;
  }
  else {
    BLE_UUID_BATTERY_SERVICE = BLE_UUID_BATTERY_SERVICE2;
    BLE_UUID_PRESSURE = BLE_UUID_PRESSURE2;
  }
  enum BLE_STATE_TYPE { BLE_STATE_OFF,
                        BLE_STATE_BEGIN,
                        BLE_STATE_START_SCAN,
                        BLE_STATE_SCAN,
                        BLE_STATE_STOP_SCAN,
                        BLE_STATE_PERIPHERAL_CONNECT,
                        BLE_STATE_PERIPHERAL_DISCOVER,
                        BLE_STATE_PERIPHERAL_WRITE,
                        BLE_STATE_END,
                        BLE_STATE_RESTART = 255
                      };

#define BLE_SCAN_TIMEOUT 10000
 
  static int state = BLE_STATE_OFF;
  static unsigned long previousMillis = 0;
  static BLEDevice peripheral;
  BLECharacteristic tlak = peripheral.characteristic( BLE_UUID_PRESSURE );
  switch (state) {
    case BLE_STATE_OFF:
      if (updatePeripheral) {
        bleActive = true;
        //updatePeripheral = false;
        Serial.print("BLE Active.");
        Serial.print(BLE_UUID_BATTERY_SERVICE);
        Serial.println(BLE_UUID_PRESSURE);
        state++;
        break;
      }
      break;
    case BLE_STATE_BEGIN:
      if (prvyLoop == 0) {
        if (!BLE.begin()) {
          Serial.println("Starting BLE Failed.");
          break;
        }

        BLE.setDeviceName("Weather Station");
        BLE.setLocalName("Weather Station");
      }
      prvyLoop++;
      digitalWrite(LED_BUILTIN, HIGH);
      state++;
      break;


    case BLE_STATE_START_SCAN:

      BLE.scanForUuid( BLE_UUID_BATTERY_SERVICE );
      previousMillis = millis();
      Serial.println("State BLE Start Scan");
      state++;
      break;

    case BLE_STATE_SCAN:
      if (millis() - previousMillis > BLE_SCAN_TIMEOUT) {
        BLE.stopScan();
        state = BLE_STATE_END;
        break;
      }
      peripheral = BLE.available();
      if (!peripheral) {
        break;
      }
      if (peripheral.localName() != "BatteryMonitor") {
        break;
      }
      state++;
      Serial.println("Weather Satelite found.");
      break;


    case BLE_STATE_STOP_SCAN:
      BLE.stopScan();
      Serial.println("State BLE Scan Stop");
      state++;
      break;
    case BLE_STATE_PERIPHERAL_CONNECT:
      if (!peripheral.connect()) {
        state = BLE_STATE_START_SCAN;
      }
      Serial.println("State Peripheral Connect");
      state++;
      break;
    case BLE_STATE_PERIPHERAL_DISCOVER:
      if (!peripheral.discoverAttributes()) {
        peripheral.disconnect();
        state = BLE_STATE_START_SCAN;
      }
      Serial.println("State Peripheral Discover");
      state++;
      break;
    case BLE_STATE_PERIPHERAL_WRITE: {
        uint8_t tlakout;

        tlak.readValue( tlakout );

        Serial.print("pressure is  ");
        Serial.println(tlakout);
      }
      state++;
      break;
    case BLE_STATE_END:
      state = BLE_STATE_OFF;
      updatePeripheral = false;
      digitalWrite(LED_BUILTIN, LOW);
      peripheral.disconnect();
      if (premena == 0) premena = 1;
      else premena = 0;
      bleActive = false;
      Serial.println("BLE End.1");
      break;
    default:
      state = BLE_STATE_OFF;
      updatePeripheral = false;
      digitalWrite(LED_BUILTIN, LOW);
      peripheral.disconnect();
      if (premena == 0) premena = 1;
      else premena = 0;
      bleActive = false;
      Serial.println("BLE End.2");
      break;
  }
}

my program for 2 pheriperals

Hello, please I have two arduino nano ble 33 sense, I would like to know how to send the data of the first ARDUINO NANO BLE SENSE and receive it on the 2nd card

Please do not hijack other posts and create your own. This will give you more attention from everyone. Many users do not read older posts which already have a lot of answers. They try to help new posts first.

Did you read my reply #2 and played with the examples as I described?

Please create a new post and describe a bit more what you would like to do? What does not work? What part of BLE might be unclear?

When you answer here with a link to your new post I will get a notification and look at your post. We can continue there.

Hello, Thank you for telling me, I will reformulate my message :slightly_smiling_face:

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