Can't get Nano 33 IOT or Sense to communicate on BLE

I have both an IOT and a Sense board and while I can connect them to other BLE devices, I have been unable to get any of the example sketche like LED or a recent one posted under another topic to transfer any data. Have used BLE examples under App Inventor 2 as well as nRF Connect and Light Blue to no avail. Hope someone can tell me what I’m doing wrong or what else I should try.

Here is the code I’ve used from another forum post:

/*
  This example creates a BLE peripheral with a service that contains String
  characteristics that can be read and written.
  The length of the String characteristic needs to be fixed.

  The circuit:
  - Arduino Nano 33 BLE Sense board.

  You can use a generic BLE central app, like LightBlue (iOS and Android) or
  nRF Connect (Android), to interact with the services and characteristics
  created in this sketch.

  This example code is in the public domain.
*/

#include <ArduinoBLE.h>


//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------

#define BLE_UUID_TEST_SERVICE               "9A48ECBA-2E92-082F-C079-9E75AAE428B1"
#define BLE_UUID_FILE_NAME                  "2D2F88C4-F244-5A80-21F1-EE0224E80658"

//----------------------------------------------------------------------------------------------------------------------
// BLE
//----------------------------------------------------------------------------------------------------------------------

BLEService testService( BLE_UUID_TEST_SERVICE );
BLEStringCharacteristic fileNameCharacteristic( BLE_UUID_FILE_NAME, BLERead | BLEWrite, 20 );

String fileName = "";


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

  BLE.begin();
 
  // set advertised local name and service UUID:
  BLE.setDeviceName( "Arduino Nano 33 BLE" );
  BLE.setLocalName( "Arduino Nano 33 BLE" );
  BLE.setAdvertisedService( testService );

  // BLE add characteristics
  testService.addCharacteristic( fileNameCharacteristic );

  // add service
  BLE.addService( testService );

  // set the initial value for the characeristic:
  fileNameCharacteristic.writeValue( fileName );

  // start advertising
  BLE.advertise();

}

void loop()
{
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

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

    while ( central.connected() )
    {
      if ( fileNameCharacteristic.written() )
      {
        fileName = fileNameCharacteristic.value();
        Serial.print( "New file name: " );
        Serial.println( fileName );
      }
    }

    Serial.print( F( "Disconnected from central: " ) );
    Serial.println( central.address() );
  }
}

If you answer a few question I would be happy to modify the example for you.

What kind of data would you like to transfer? e.g. a temperature, some int or float value ...

With BLE one device will be the server/peripheral and and one will be the client/central. Which of the two boards do you want to be one or the other?

Do you want the client to read or write data from/to the server. Or both?

Just in case. The sketch will only work when you connect the Serial Monitor. If you don't want to connect the Serial Monitor comment the while ( !Serial );

I need the client (?), a smart phone to send a simple signal to the server (?) to trigger an action by the server. Pretty much exactly what the LED example from the BLE library is supposed to do. However, I have been unable to coax any kind of response from the arduino code when I have used the BLE apps on my phone. I get a connection and the MAC address on the serial monitor, but nothing happens when the data is sent from the phone.

Here is the LED example code that I have also tried without success. Again, it connects to my smart phone with both nRF Connect and Light Blue apps, but gives no indication that transmissions are received by the Nano 33s.

/*
  LED

  This example creates a BLE peripheral with service that contains a
  characteristic to control an LED.

  The circuit:
  - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
    Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.

  You can use a generic BLE central app, like LightBlue (iOS and Android) or
  nRF Connect (Android), to interact with the services and characteristics
  created in this sketch.

  This example code is in the public domain.
*/

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

const int ledPin = LED_BUILTIN; // pin to use for the LED

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

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);

  // add service
  BLE.addService(ledService);

  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(0);

  // start advertising
  BLE.advertise();

  Serial.println("BLE LED Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}
1 Like

Mmmm strange. The example works on both boards and with both apps (I use an iPhone).

I find that the nRF Connect is a little unresponsive when I try to touch on the little up arrow icon at the characteristic. But then I can basically write any value except 0 to it and light the yellow LED (and prints in the Serial Monitor). Even the bool true/false button can be used. The LightBlue app is very responsive and both write and read work just fine.

Because you can see the MAC address in the Monitor, the connection is working fine.

Since I have both a IOT and a Sense I think I'll try the Button LED sketch on one and the LED example on the other. Maybe something about my Samsung Galaxy is the problem. I've always used it as the sending device. Will post back what I find.

Hello, could you find out whats wrong?
I have 2 ble nanos, i upload the same sketch on both (arduinoBLE, LED) and i can connect via nrf connect, and i get the MAC adress on the serial monitor.
But when i try to send "1" to one of the nanos the led turns on and i get the "LED ON" on serial monitor. I turn off that nano and do exactly the same with the second, but it seems that is not recieving anything, but i still get the MAC adress.
tried with different sketches and cant recieve nothing. Is something wrong with one of my boards? Or how can i fix this?
Hope some can help, thanks

@huge

Please do not post in old posts when you need help. Create your own post. This will give you a better chance of somebody answering. Read the "How to post .." its at the beginning of each sub forum.

I have seen some posts where on some BLE boards components on the BLE module antenna PCB area (green) have been missing. There should be 5. Compare your two boards.

Ok, will open a new one. All 5 pieces are present.