Components and supplies
Arduino 101
Project description
Code
RoverRemote
c_cpp
Arduino Sketch that sets up the Nordic Semiconductor UART BLE service as a RC rover remote control
1/* 2 This Sketch creates a simple Remote Control for an Arduino 101 3 based Rover. It can be easily modified for other purposes. 4 Author: Dave Shade 5 6 It is intended to be paired with the UART sample in the 7 nRF Toolbox available for the Android and IOS platforms 8 9 The Nordic Semiconductor UART profile for Bluetooth Low Energy 10 is implemented in the CallbackLED sample for the Arduino 101 11 which is: 12 13 Copyright (c) 2015 Intel Corporation. All rights reserved. 14 15 Both that sample and this sketch are covered under the 16 license below. 17 18 This library is free software; you can redistribute it and/or 19 modify it under the terms of the GNU Lesser General Public 20 License as published by the Free Software Foundation; either 21 version 2.1 of the License, or (at your option) any later version. 22 23 This library is distributed in the hope that it will be useful, 24 but WITHOUT ANY WARRANTY; without even the implied warranty of 25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 Lesser General Public License for more details. 27 28 You should have received a copy of the GNU Lesser General Public 29 License along with this library; if not, write to the Free Software 30 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110- 31 1301 USA 32*/ 33 34 35#include <CurieBLE.h> 36 37const int ledPin = 13; // set ledPin to use on-board LED 38 39char state; // variable to hold a transmitted byte 40 41BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming) 42 43// ==== create Nordic Semiconductor UART service ========= 44BLEService uartService = BLEService("6E400001B5A3F393E0A9E50E24DCCA9E"); 45// create characteristics 46BLECharacteristic rxCharacteristic = BLECharacteristic("6E400002B5A3F393E0A9E50E24DCCA9E", BLEWriteWithoutResponse, 20); // == TX on central (android app) 47BLECharacteristic txCharacteristic = BLECharacteristic("6E400003B5A3F393E0A9E50E24DCCA9E", BLENotify , 20); // == RX on central (android app) 48 49void setup() { 50 Serial.begin(9600); 51 pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output 52 53 // set advertised local name and service UUID: 54 blePeripheral.setLocalName("BLE_ROV"); 55 blePeripheral.setAdvertisedServiceUuid(uartService.uuid()); 56 57 // add service, rx and tx characteristics: 58 blePeripheral.addAttribute(uartService); 59 blePeripheral.addAttribute(rxCharacteristic); 60 blePeripheral.addAttribute(txCharacteristic); 61 62 // assign event handlers for connected, disconnected to peripheral 63 blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler); 64 blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); 65 66 // assign event handler for characteristic 67 rxCharacteristic.setEventHandler(BLEWritten, rxCharacteristicWritten); 68 69 // advertise the service 70 blePeripheral.begin(); 71} 72 73void loop() { 74 // poll ble peripheral 75 blePeripheral.poll(); 76} 77 78void blePeripheralConnectHandler(BLECentral& central) { 79 // central connected event handler 80 Serial.print("Connected event, central: "); 81 Serial.println(central.address()); 82 //Serial.println("LED on"); 83 digitalWrite(ledPin, HIGH); 84} 85 86void blePeripheralDisconnectHandler(BLECentral& central) { 87 // central disconnected event handler 88 Serial.print("Disconnected event, central: "); 89 Serial.println(central.address()); 90 //Serial.println("LED off"); 91 digitalWrite(ledPin, LOW); 92} 93 94void rxCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic) { 95 // central wrote new value to characteristic, update LED 96 Serial.print("Characteristic event, written: "); 97 98 if (characteristic.value()) { //null pointer check 99 state = *characteristic.value(); //set state to be the value written from the phone/tablet to the Arduino 101 100 Serial.println(char(state)); //print out the character to the serial monitor 101 } 102} 103
Downloadable files
Arduino 101 Schematic
Arduino 101 Schematic
Arduino 101 Schematic
Arduino 101 Schematic
Arduino 101 Schematic
Arduino 101 Schematic
Comments
Only logged in users can leave comments
shadeydave
0 Followers
•0 Projects
+1
Work attribution
Table of contents
Intro
5
0