sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
464 stars 180 forks source link

How to connect Arduino Zero to nrf51822 (via SPI) #209

Closed Gius-8 closed 6 years ago

Gius-8 commented 6 years ago

Hello, I'm trying to connect an Arduino zero to a Raytech MDBT40 module (32KB RAM) via SPI, but I can not make it work.

First of all I was able to load softdevice on nrf51. Loading on nrf51 this sketch everything works:

// Import libraries (BLEPeripheral depends on SPI)
#include <SPI.h>
#include <BLEPeripheral.h>

//////////////
// Hardware //
//////////////
#define LED_PIN    13
#define LED_ACTIVE LOW
#define LED_DEFAULT LOW

///////////////////////
// BLE Advertisments //
///////////////////////
const char * localName = "nRF51822 LED";
BLEPeripheral blePeriph;
BLEService bleServ("1207");
BLECharCharacteristic ledChar("1207", BLERead | BLEWrite);

void setup()
{
  Serial.begin(115200); // Set up serial at 115200 baud

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, !LED_ACTIVE);

  setupBLE();
}

void loop()
{
  blePeriph.poll();

  if (ledChar.written())
  {
    int ledState = ledChar.value();
    if (ledState)
      digitalWrite(LED_PIN, LED_ACTIVE);
    else
      digitalWrite(LED_PIN, !LED_ACTIVE);
  }
}

void setupBLE()
{
  // Advertise name and service:
  blePeriph.setDeviceName(localName);
  blePeriph.setLocalName(localName);
  blePeriph.setAdvertisedServiceUuid(bleServ.uuid());

  // Add service
  blePeriph.addAttribute(bleServ);

  // Add characteristic
  blePeriph.addAttribute(ledChar);

  // Now that device6, service, characteristic are set up,
  // initialize BLE:
  blePeriph.begin();

  // Set led characteristic to default value:
  ledChar.setValue(!LED_ACTIVE);
}

I tried to connect Arduino zero to nrf51 like this:

nRF51       Zero
P0.22        MISO
P.023        MOSI
P.024        SCK
P.025        NC (it is necessary?)
GND         GND

But the sketch "starter.ino" hangs on blePeripheral.begin ();

I would like to manage the BLE module via an arduino zero. it's possible?

Thanks so much.

sandeepmistry commented 6 years ago

Hi @Gius-8,

This configuration is not supported. Only connecting an nRF8001 to the Arduino via SPI is supported. nRF51 is only supported in stand alone mode.