Go Down

Topic: connect 2 arduinos 101 with BLE (Read 78 times) previous topic - next topic


Mar 14, 2018, 04:21 am Last Edit: Mar 14, 2018, 04:30 am by drkmr92
Hi, i'm triying to make a simple program to communicate 2 arduinos as subject says, i already try LedControl Central example in the first arduino and CallbackLed peripheral example in the second, and it works, but i want something a little more complex for my application, i want to transmit and receive in continuous mode, so i write 2 sketch for central and peripheral role respectively based on the given examples, for peripheral role there's no problem, i tested with nrf connect for android and it works perfect, the problem is the central role im stuck with the transmit mode, and i have no idea how to receive data, here's what i have so far:

Code: [Select]
#include <CurieBLE.h>
#include <CurieTimerOne.h>

int time = 100000;
// variables for button
//#define buttonPin 4
#define buff_len 20

int oldButtonState = LOW;
uint8_t cont=0, buff[buff_len];

bool Cflag=false, Rflag=false;

BLEDevice peripheral;// create peripheral device

//BLECharacteristic ledCharacteristic("0000FFE2-0000-1000-8000-00805F9B34FB", BLEWrite, buff_len);
BLECharacteristic ledCharacteristic;// = peripheral.characteristic("0000FFE2-0000-1000-8000-00805F9B34FB");

void setup() {

  // configure the button pin as input
  pinMode(buttonPin, INPUT);

  // initialize the BLE hardware
  CurieTimerOne.start(time, &Timer_ISR);

  Serial.println("BLE Central - LED control");

  // start scanning for peripherals

void loop() {
 //BLECharacteristic ledCharacteristic;
  // check if a peripheral has been discovered
 peripheral = BLE.available();

 if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
 Serial.print("Found ");
 Serial.print(" '");
 Serial.print("' ");

    // stop scanning
 Serial.println("Connecting ...");

 if (peripheral.connect()) {
 } else {
 Serial.println("Failed to connect!");
 //ledCharacteristic = peripheral.characteristic("0000FFE2-0000-1000-8000-00805F9B34FB");
 ledCharacteristic = peripheral.characteristic("0000FFE2-0000-1000-8000-00805F9B34FB");
 if (!ledCharacteristic) {
 Serial.println("Peripheral does not have LED characteristic!");
 } else if (!ledCharacteristic.canWrite()) {
 Serial.println("Peripheral does not have a writable LED characteristic!");

    // peripheral disconnected, start scanning again

void Timer_ISR(){
 buff1[i]=cont; cont++;

if i run that sketch the ledcharacteristic doesn't work, it connect to the peripheral, but the central can't find any characteristics and it disconnect, i tried the original example but with my own UUID and it works, but with this changes it doesn't, i also give the code for the peripheral.

thanks in advance.

Go Up