Hello everyone, I am a starting arduino programmer and I have not so much experience as the most of u guys but in project that I am making I need to connect The arduino Nano's to each other Using BLE. I have done some research in the arduino nano ble forums but without succes.
These are my codes for the central and the peripheral:
Central:
//central device
#include <ArduinoBLE.h>
void beginBLE() // zet BLE aan
{
if (!BLE.begin()) // als BLE niet werkt stuur deze tekst door
{
Serial.println("starting BLE failed!");
while (1); // tot hij wel werkt
}
}
void setup()
{
Serial.begin(9600);
beginBLE(); // functie beginBLE voor begin BLE connectie
BLE.setDeviceName("central"); // naam aan de arduino toe kennen
}
void adres() // BLE adres van de arduino nano 33 IOT
{
String address = BLE.address(); // address = BLE adres
Serial.print("central Local address is : ");
Serial.println(address);
}
void loop()
{
// adres(); // functie adres voor het het adres van de BLE component
BLE.scan(); // scan naar een peripheral
BLEDevice peripheral = BLE.available(); // als er een peripheral arduino ontdekt is
if (peripheral)
{
Serial.println("Connecting ..."); // stuur conecting naar seriƫle monitor
if (peripheral.connect()) // als de periphal geconnecteerd is -->
{
Serial.println("Connected"); // stuur dat hij geconnecteerd is
} else // indien niet,
{
Serial.println("Failed to connect!"); // stuur failed to connect
return;
}
}
}
pheripheral:
// peripheral device
#include <ArduinoBLE.h>
void beginBLE() // zet BLE aan
{
if (!BLE.begin()) // als BLE niet werkt stuur deze tekst door
{
Serial.println("starting BLE failed!");
while (1); // tot hij wel werkt
}
}
void setup()
{
pinMode(2, OUTPUT);
Serial.begin(9600);
beginBLE(); // functie beginBLE voor begin BLE connectie
BLE.setDeviceName("peripheral"); // naam aan de arduino toe kennen
}
void adres() // BLE adres van de arduino nano 33 IOT
{
String address = BLE.address(); // address = BLE adres
Serial.print("peripheral Local address is: ");
Serial.println(address);
}
void loop()
{
digitalWrite(2, HIGH);
adres(); // functie adres voor het het adres van de BLE component
BLE.setConnectable(true); // zet de connectiviteit true
BLE.advertise(); // sta open voor connectie
}
They are able to use the BLE and they print there adresses but won't connect to each other and I don't know what to do next. I hope you guys help me and thanks on forward.