How to receive data via BLE on an Arduino 101

The tutorials and code examples that can be found for the 101 all seem to be about transmitting data, but I can't find anything about receiving data. I've tried to go through the source code of the CurieBle library to find some hints but I feel a little overwhelmed/lost. Could someone point me to a code example which demonstrates how to do this?

Context: I was previously using a HC-05 module paired with an Arduino Nano in order to receive data. In this case it is quite easy to connect the HC-05 to the Nano's digital pins and receive data like so:

#define RxD 7 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD)
#define TxD 8 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)

SoftwareSerial blueToothSerial(RxD,TxD);

void setup() { 
  blueToothSerial.begin(9600);
  Serial.begin(9600); // Allow Serial communication via USB cable to computer
  pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the HC-05 on Digital Pin 7
  pinMode(TxD, OUTPUT); // Setup the Arduino to send OUTPUT to the HC-05 on Digital Pin 8
} 

void loop() { 
  char recvChar;
  while(1) {
    if(blueToothSerial.available()) {
      recvChar = blueToothSerial.read();
      Serial.print("Read character: ");
      Serial.println(recvChar); // Print the character received to the Serial Monitor
    }
  }
}

Is there some equivalent, and equally simple code available which would do the same thing via the BLE built into the Arduino 101?

I guess you are looking for Central mode, rather than asking if you can write to the Arduino 101.

https://forum.arduino.cc/index.php?topic=384963.0

http://forum.arduino.cc/index.php?topic=370579.0

BLE Central mode is not available yet.

If you are asking if you can write to the 101 from a central device (smartphone, PC, etc) then yes, that is possible as is.

DaveOR:
If you are asking if you can write to the 101 from a central device (smartphone, PC, etc) then yes, that is possible as is.

Yes, that is what I'm asking :slight_smile: Basically I want to know how can you write to the 101 from a smart phone? (What do you need to do in the Arduino code in order to receive the transmission?)

You need a writeable characteristic and an event handler for that characteristic to catch updates to the value from a smartphone.

switchChar.setEventHandler(BLEWritten, switchCharacteristicWritten);

See CallbackLED example :slight_smile:

Apologies, I didn't explain the smartphone side of interfacing with the CallbackLED example!

If you want to test writing to the Arduino

  1. I recommend the Nordic android app "nRF Master Control Panel BLE"
  2. Scan and connect to the "LEDCB" device.
  3. Open unknown service, unknown characteristic.
  4. To the right of the screen you will see 2 arrows - clicking on the down arrow allows you to read, up arrow allows write.
  5. The write format I have used to interface with the LED callback is UINT 8.
  6. Send non zero value to turn on LED, write 0 to turn it off.

Have fun!