shadeydave
Published © LGPL

Arduino 101 BLE Rover Remote Control

I couldn't find an existing BLE Remote Control for an Arduino 101 Rover - this is my novel solution!

IntermediateFull instructions provided5,094
Arduino 101 BLE Rover Remote Control

Things used in this project

Story

Read more

Schematics

Arduino 101 Schematic

Arduino 101 Schematic

Code

RoverRemote

C/C++
Arduino Sketch that sets up the Nordic Semiconductor UART BLE service as a RC rover remote control
/*
  This Sketch creates a simple Remote Control for an Arduino 101
  based Rover. It can be easily modified for other purposes.
  Author: Dave Shade

  It is intended to be paired with the UART sample in the 
  nRF Toolbox available for the Android and IOS platforms
  
  The Nordic Semiconductor UART profile for Bluetooth Low Energy
  is implemented in the CallbackLED sample for the Arduino 101 
  which is: 
  
  Copyright (c) 2015 Intel Corporation. All rights reserved. 

  Both that sample and this sketch are covered under the 
  license below.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-
  1301 USA
*/


#include <CurieBLE.h>

const int ledPin = 13; // set ledPin to use on-board LED

char state;   // variable to hold a transmitted byte

BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)

// ====  create Nordic Semiconductor UART service =========
BLEService uartService = BLEService("6E400001B5A3F393E0A9E50E24DCCA9E");
// create characteristics
BLECharacteristic rxCharacteristic = BLECharacteristic("6E400002B5A3F393E0A9E50E24DCCA9E", BLEWriteWithoutResponse, 20);  // == TX on central (android app)
BLECharacteristic txCharacteristic = BLECharacteristic("6E400003B5A3F393E0A9E50E24DCCA9E", BLENotify , 20); // == RX on central (android app)

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output

  // set advertised local name and service UUID:
  blePeripheral.setLocalName("BLE_ROV");
  blePeripheral.setAdvertisedServiceUuid(uartService.uuid());

  // add service, rx and tx characteristics:
  blePeripheral.addAttribute(uartService);
  blePeripheral.addAttribute(rxCharacteristic);
  blePeripheral.addAttribute(txCharacteristic);

  // assign event handlers for connected, disconnected to peripheral
  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  // assign event handler for characteristic
  rxCharacteristic.setEventHandler(BLEWritten, rxCharacteristicWritten);

  // advertise the service
  blePeripheral.begin();
}

void loop() {
  // poll ble peripheral
  blePeripheral.poll();  
}

void blePeripheralConnectHandler(BLECentral& central) {
  // central connected event handler
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
  //Serial.println("LED on");
  digitalWrite(ledPin, HIGH);
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
  //Serial.println("LED off");
  digitalWrite(ledPin, LOW);
}

void rxCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic) {
  // central wrote new value to characteristic, update LED
  Serial.print("Characteristic event, written: ");
  
  if (characteristic.value()) {       //null pointer check
    state = *characteristic.value();  //set state to be the value written from the phone/tablet to the Arduino 101
    Serial.println(char(state));      //print out the character to the serial monitor
  } 
}

Credits

shadeydave

shadeydave

3 projects • 14 followers
Thanks to Nordic Semiconductor.

Comments