Experimental BLE project showing how IO can be made with an App over BLE. Pointer to matching App will be added when ready, initially this works with: - Android App [nRF-Master Control Panel], supports Write,Read,Notify - Android Project [BluetoothLeGatt]

Dependencies:   BLE_API mbed nRF51822

This is an experimental project for BLE (Bluetooth LE == Bluetooth Low Energy == Bluetooth Smart).

  • It supports general IO over BLE with Read/Notify/Write support.
  • It is compatible with FOTA using Android App "nRF Master Control Panel" (20150126)
  • IO supported by:
    • Custom Android App is in the WIKI under: Android-App, developed from Android Sample "BluetoothLeGatt"
    • Android App: nRF-MCP (Master Control Panel)
    • iOS App LightBlue.
    • General HRM, HTM, Battery and similar apps should be able to access the matching services.
  • It includes combinations of code from other projects, alternative code included can be tried by moving comments (, //)
  • 20150126 bleIO r25: It compiles for both "Nordic nRF51822" and "Nordic nRF51822 FOTA" platforms
  • 20150126 The matching bleIO App (in wiki) doesn't support FOTA yet, use Android App "nRF Master Control Panel"

Feedback and ideas greatly appreciated!!!

Revision:
22:533275e76f55
Parent:
21:f92bb1c80538
Child:
23:78aad4e53ae2
--- a/main.cpp	Mon Dec 29 20:02:23 2014 +0000
+++ b/main.cpp	Sun Jan 11 20:01:40 2015 +0000
@@ -11,13 +11,17 @@
 //    - 
 //    - miscellaneous adopted from more samples...
 // Reference:
+//    - nRF51822:
+//          - MKit Pins: http://developer.mbed.org/users/mbed_official/code/mbed-src/file/c80ac197fa6a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/TARGET_NRF51822_MKIT/PinNames.h
+//          - Platform:  http://developer.mbed.org/platforms/Nordic-nRF51822/
+//          - MCU:       http://developer.mbed.org/users/mbed_official/code/mbed-src/file/d2c15dda23c1/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822
 //    - http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/
 //    - Reference: http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/tip/
 //    - Reference: http://developer.mbed.org/teams/Bluetooth-Low-Energy/
 // Warnings:
 //    - As of 20141210 it is necessary to use Android App [nRF-Master Control Panel] to ensure any previous connected 
 //      code on mkit is properly Disconnected before trying to connect other Android nRF Apps (nRFToolbox, nRF UART 2.0, etc.).
-//      As UART device doesn't offer disconnect you may need to load a 3rf sample, then connect, then discoonect, to clear the link.
+//      As UART device doesn't offer disconnect you may need to load a non-uart sample, then use MCP to connect and discoonect, to clear the link.
 // Notes: 
 //    - onDataSent() maybe only occuring when confirmed receive by phone, as onDataSent() didn't happen when phone moved out of range, and no onDataSent() with App nRF-MCP.
 //    - onDisconnect(Reason:8) occured after ~20Tx with no onDataSent() after phone moved out of range, OnTimeout didn't occur at all.
@@ -84,10 +88,10 @@
 
 //========== IO Hardware: Buttons, LEDs, PWM ==========
 // Inputs: (Simultaneous DigitalIn and InteruptIn is OK)
-DigitalIn       bB1in(BUTTON1); //if(bB1in){}
-DigitalIn       bB2in(BUTTON2); //if(bB2in){}
-InterruptIn     B1int(BUTTON1); //B1int.rise(&onB1rise);  
-InterruptIn     B2int(BUTTON2); //B1int.fall(&onB1fall);
+DigitalIn       bB1in(BUTTON1); //nRF51822p0.16==pin22 //if(bB1in){}
+DigitalIn       bB2in(BUTTON2); //nRF51822p0.17==pin25 //if(bB2in){}
+InterruptIn     B1int(BUTTON1); //nRF51822p0.18==pin26 //B1int.rise(&onB1rise);  
+InterruptIn     B2int(BUTTON2); //nRF51822p0.19==pin27 //B1int.fall(&onB1fall);
 
 // Outputs:
 //a DigitalOut      bL1out(LED1);   // Direct LED1 drive
@@ -101,6 +105,39 @@
 //a volatile uint8_t uB2rise; void onB2rise(void){ uB2rise++; };// Flag Event, Counter helps detect missed events since last cleared
 //a volatile uint8_t uB2fall; void onB2fall(void){ uB2fall++; };// Flag Event, Counter helps detect missed events since last cleared
 
+//========== ADC ==========
+// ADC/Analog: 20150106PR
+//    - Options:
+//      - AnalogIn, Default: http://developer.mbed.org/handbook/AnalogIn
+//      - ADC Lib, http://developer.mbed.org/users/simonb/code/ADC_test/
+//      - Fast, but burns power: http://developer.mbed.org/users/Sissors/code/FastAnalogIn/
+// Initially using the mbed standard: AnalogIn  (Later may change when power or timing require it)
+//      - adcX.read() returns a float, scaled so 0.0~1.0 == ADC range 0~Vcc (0.3 == 30% of Vcc)
+//      - adcX.read_u16() returns uint16, raw (0x0000~0xFFFF)
+//nRF51822 mkit Analog Pins are only p1~p6 (P0_1~P0_6):
+//AnalogIn adc0(p26);// nRF51822p0.26==pin45==AIN0==XL2   (Reserve for low power 32KHz Crystal)
+//AnalogIn adc1(p27);// nRF51822p0.27==pin46==AIN1==XL1   (Reserve for low power 32KHz Crystal)
+//AnalogXX AREF0     // nRF51822p0.00==pin04      ==AREF0 (Reserve for Analog Reference)
+AnalogIn   adcA(p1); // nRF51822p0.01==pin05==AIN2
+AnalogIn   adcB(p2); // nRF51822p0.02==pin06==AIN3
+//AnalogIn   adcC(p3); // nRF51822p0.03==pin07==AIN4
+//AnalogIn   adcD(p4); // nRF51822p0.04==pin08==AIN5
+//AnalogIn   adcE(p5); // nRF51822p0.05==pin09==AIN6 
+//AnalogIn   adcF(p6); // nRF51822p0.06==pin10==AIN7==AREF1 (Option: Reserve for Analog Reference)
+
+void vShowADC(void)
+{   //TODO: Check what the actual ADC register settings are to know how the nRF51822 is actually configured
+    DEBUG(" ShowADC:\n");
+    DEBUG(" p1=AIN2[%f=0x%04X]", adcA.read(), adcA.read_u16() );
+    DEBUG(" p2=AIN3[%f=0x%04X]", adcB.read(), adcB.read_u16() );
+    //DEBUG(" p3=AIN4[%f=0x%04X]", adcC.read(), adcC.read_u16() );
+    //DEBUG(" p4=AIN5[%f=0x%04X]", adcD.read(), adcD.read_u16() );
+    //DEBUG(" p5=AIN6[%f=0x%04X]", adcE.read(), adcE.read_u16() );
+    //DEBUG(" p6=AIN7[%f=0x%04X]", adcF.read(), adcF.read_u16() );
+    DEBUG(" \n");  
+}
+
+
 //==========BLE==========
 //const static char pcDeviceName[] = "bleIOv04_pr"; //Too Long for advertising with a UUID128
 const static char pcDeviceName[] = "bleIOv04"; //Advertised device name (Max length depends on available space with other Advertising data)
@@ -293,6 +330,8 @@
     //DEBUG("  LinkLoss: AlertLevel:%d",  pServiceLinkLoss->getCharacteristic(0)->getHandle());
     //DEBUG("  DFU:%d",           pServiceDFU.getValueAttribute().getHandle());
     //DEBUG("  UART:%d\n",        pServiceUART.getValueAttribute().getHandle());
+
+    vShowADC();
 }
 
 //==== Soft Updates to Characteristics for initial tests: (Most replaced by real buttons/sensors/timers )
@@ -623,7 +662,7 @@
     ble.onUpdatesEnabled(Callback_BLE_onUpdatesEnabled);//PR: Occurs when host enables notify on a Characteristic that has Notify property set
     ble.onUpdatesDisabled(Callback_BLE_onUpdatesDisabled);    //TODO:
     ble.onConfirmationReceived(Callback_BLE_onConfirmRx);     //TODO:
-    //ble.onDataRead(Callback_BLE_onDataRead) //TODO: Need a callback for when reading data so can ensure characteristic is fully up to data before it is passed back (For now update periodically)
+    //ble.setReadAuthorizationCallback(Callback_BLE_onDataRead) //TODO: Test new callback "setReadAuthorizationCallback()", then can read sensors live instead of polling them continuously.   
     
     //BLE2: Setup Services (with their initial values and options)
     DEBUG("BLE: Setup Services\n");