How to perform read and write between Raspberry Pi 4 and Arduino Nano BLE?

I can able to connect Raspberry pi 4 and Arduino Nano BLE through bluepy for Rpi4 and ArduinoBLE.h for Arduino Nano BLE. Unfortunately when I try to write from Rpi4 to Arduino Nano BLE, Im not seeing the expected output for Read and Write. I dont see any perfect example for Arduino Nano BLE since it is a recently released hardware with built in BLE. It would be very helpful if anyone help me to achieve communication between them. Thanks in Advance. Below is my code for Raspberry pi,

import bluepy.btle as btle
p = btle.Peripheral("de:fc:54:87:b0:04")
s = p.getServiceByUUID(list(services)[2].uuid)
c = s.getCharacteristics()[0]
c.write(bytes("2", "utf-8"))

And Im using Ardunino Built in Example from the Arduino Nano BLE Library

#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() {
  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:

  // add the characteristic to the service

  // add service

  // set the initial value for the characeristic:

  // start advertising

  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: ");
    //prints the centrals MAC 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: "));


I figured out myself, it was the value in the write which was going wrong all this time. Below is the right one. I hope now you can find this as a perfect solution to connect raspberry Pi 4 and Arduino Nano BLE wirelessly Via Bluetooth.