An integrated code base for smart watch model using nrf51822. Used the efforts from Roger Clark, Goran Mahovlic, Nordic team SDKs and mbed repos on OLED. Programming: The watch prototype can be interfaced to Tiny Seeed BLE programmer (left of the Tiny Seeed BLE board). Connect SWDIO, SWD CLK, Vin and GND pins. For USB debugging also connect RX and TX pins. Used Roger's nice webpage to come up with the pin mapping and many other HW insights. http://www.rogerclark.net/arduino-on-the-id100hr-fitness-tracker/
Dependencies: BLE_API SFE_MicroOLED_debugPrint mbed nRF51822
Fork of BLE_TemperatureAdvertising by
store.txt@7:1b0597b7ead3, 2017-12-27 (annotated)
- Committer:
- sandyr7
- Date:
- Wed Dec 27 06:47:27 2017 +0000
- Revision:
- 7:1b0597b7ead3
- Parent:
- 5:8c21994db8d2
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandyr7 | 5:8c21994db8d2 | 1 | |
sandyr7 | 5:8c21994db8d2 | 2 | /* mbed Microcontroller Library |
sandyr7 | 5:8c21994db8d2 | 3 | * Copyright (c) 2006-2015 ARM Limited |
sandyr7 | 5:8c21994db8d2 | 4 | * |
sandyr7 | 5:8c21994db8d2 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sandyr7 | 5:8c21994db8d2 | 6 | * you may not use this file except in compliance with the License. |
sandyr7 | 5:8c21994db8d2 | 7 | * You may obtain a copy of the License at |
sandyr7 | 5:8c21994db8d2 | 8 | * |
sandyr7 | 5:8c21994db8d2 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
sandyr7 | 5:8c21994db8d2 | 10 | * |
sandyr7 | 5:8c21994db8d2 | 11 | * Unless required by applicable law or agreed to in writing, software |
sandyr7 | 5:8c21994db8d2 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
sandyr7 | 5:8c21994db8d2 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sandyr7 | 5:8c21994db8d2 | 14 | * See the License for the specific language governing permissions and |
sandyr7 | 5:8c21994db8d2 | 15 | * limitations under the License. |
sandyr7 | 5:8c21994db8d2 | 16 | */ |
sandyr7 | 5:8c21994db8d2 | 17 | |
sandyr7 | 5:8c21994db8d2 | 18 | #include "mbed.h" |
sandyr7 | 5:8c21994db8d2 | 19 | #include "stdio.h" |
sandyr7 | 5:8c21994db8d2 | 20 | //#include "ble/BLE.h" |
sandyr7 | 5:8c21994db8d2 | 21 | //#include "TMP_nrf51/TMP_nrf51.h" |
sandyr7 | 5:8c21994db8d2 | 22 | |
sandyr7 | 5:8c21994db8d2 | 23 | #define APP_SPECIFIC_ID_TEST 0xFFFF |
sandyr7 | 5:8c21994db8d2 | 24 | |
sandyr7 | 5:8c21994db8d2 | 25 | #define VIBRATE P0_7 |
sandyr7 | 5:8c21994db8d2 | 26 | #include "SFE_MicroOLED.h" |
sandyr7 | 5:8c21994db8d2 | 27 | //accelerometer |
sandyr7 | 5:8c21994db8d2 | 28 | #include "KX22.h" |
sandyr7 | 5:8c21994db8d2 | 29 | #define KX_SCL P0_16 |
sandyr7 | 5:8c21994db8d2 | 30 | #define KX_SDA P0_14 |
sandyr7 | 5:8c21994db8d2 | 31 | |
sandyr7 | 5:8c21994db8d2 | 32 | #define UART_TX p18 |
sandyr7 | 5:8c21994db8d2 | 33 | #define UART_RX p17 |
sandyr7 | 5:8c21994db8d2 | 34 | //got these numbers from roger! tx in tx |
sandyr7 | 5:8c21994db8d2 | 35 | //vibrate motor |
sandyr7 | 5:8c21994db8d2 | 36 | DigitalOut vib(VIBRATE); |
sandyr7 | 5:8c21994db8d2 | 37 | |
sandyr7 | 5:8c21994db8d2 | 38 | |
sandyr7 | 5:8c21994db8d2 | 39 | #pragma pack(1) |
sandyr7 | 5:8c21994db8d2 | 40 | struct ApplicationData_t { |
sandyr7 | 5:8c21994db8d2 | 41 | uint16_t applicationSpecificId; /* An ID used to identify temperature value |
sandyr7 | 5:8c21994db8d2 | 42 | in the manufacture specific AD data field */ |
sandyr7 | 5:8c21994db8d2 | 43 | //TMP_nrf51::tmpSensorValue_t tmpSensorValue; /* User defined application data */ |
sandyr7 | 5:8c21994db8d2 | 44 | }; |
sandyr7 | 5:8c21994db8d2 | 45 | #pragma pack() |
sandyr7 | 5:8c21994db8d2 | 46 | |
sandyr7 | 5:8c21994db8d2 | 47 | //BLE ble; |
sandyr7 | 5:8c21994db8d2 | 48 | //TMP_nrf51 tempSensor; |
sandyr7 | 5:8c21994db8d2 | 49 | //DigitalOut alivenessLED(LED1, 1); |
sandyr7 | 5:8c21994db8d2 | 50 | //static bool triggerTempValueUpdate = false; |
sandyr7 | 5:8c21994db8d2 | 51 | //const static char DEVICE_NAME[] = "Sandyr"; |
sandyr7 | 5:8c21994db8d2 | 52 | |
sandyr7 | 5:8c21994db8d2 | 53 | /*********OLED******************/ |
sandyr7 | 5:8c21994db8d2 | 54 | //from roger :: works!!! |
sandyr7 | 5:8c21994db8d2 | 55 | SPI my_spi(P0_29, NC, P0_30); |
sandyr7 | 5:8c21994db8d2 | 56 | MicroOLED oled(my_spi, P0_1, P0_0, P0_2); |
sandyr7 | 5:8c21994db8d2 | 57 | |
sandyr7 | 5:8c21994db8d2 | 58 | //from some guy |
sandyr7 | 5:8c21994db8d2 | 59 | //SPI my_spi(P0_2, P0_3, P0_1); |
sandyr7 | 5:8c21994db8d2 | 60 | //MicroOLED oled(my_spi, P0_30, P0_0, P0_29); |
sandyr7 | 5:8c21994db8d2 | 61 | |
sandyr7 | 5:8c21994db8d2 | 62 | /************KX ACC*************/ |
sandyr7 | 5:8c21994db8d2 | 63 | TwoWire wire = TwoWire(NRF_TWI1); |
sandyr7 | 5:8c21994db8d2 | 64 | KX22 acc(KX_SCL, KX_SDA, &wire); |
sandyr7 | 5:8c21994db8d2 | 65 | |
sandyr7 | 5:8c21994db8d2 | 66 | /***********Serial*****/ |
sandyr7 | 5:8c21994db8d2 | 67 | extern Serial pc(UART_TX, UART_RX); |
sandyr7 | 5:8c21994db8d2 | 68 | |
sandyr7 | 5:8c21994db8d2 | 69 | |
sandyr7 | 5:8c21994db8d2 | 70 | |
sandyr7 | 5:8c21994db8d2 | 71 | /*void periodicCallback(void) |
sandyr7 | 5:8c21994db8d2 | 72 | { |
sandyr7 | 5:8c21994db8d2 | 73 | //Any periodic requests that we need to handle |
sandyr7 | 5:8c21994db8d2 | 74 | |
sandyr7 | 5:8c21994db8d2 | 75 | /* Do blinky on LED1 while we're waiting for BLE events */ |
sandyr7 | 5:8c21994db8d2 | 76 | // alivenessLED = !alivenessLED; |
sandyr7 | 5:8c21994db8d2 | 77 | triggerTempValueUpdate = true; |
sandyr7 | 5:8c21994db8d2 | 78 | } |
sandyr7 | 5:8c21994db8d2 | 79 | */ |
sandyr7 | 5:8c21994db8d2 | 80 | |
sandyr7 | 5:8c21994db8d2 | 81 | /*void accumulateApplicationData(ApplicationData_t &appData) |
sandyr7 | 5:8c21994db8d2 | 82 | { |
sandyr7 | 5:8c21994db8d2 | 83 | appData.applicationSpecificId = APP_SPECIFIC_ID_TEST; |
sandyr7 | 5:8c21994db8d2 | 84 | /* Read a new temperature value */ |
sandyr7 | 5:8c21994db8d2 | 85 | //appData.tmpSensorValue = 20; %tempSensor.get(); |
sandyr7 | 5:8c21994db8d2 | 86 | } |
sandyr7 | 5:8c21994db8d2 | 87 | |
sandyr7 | 5:8c21994db8d2 | 88 | void temperatureValueAdvertising(void) |
sandyr7 | 5:8c21994db8d2 | 89 | { |
sandyr7 | 5:8c21994db8d2 | 90 | ApplicationData_t appData; |
sandyr7 | 5:8c21994db8d2 | 91 | |
sandyr7 | 5:8c21994db8d2 | 92 | accumulateApplicationData(appData); |
sandyr7 | 5:8c21994db8d2 | 93 | //printf("Temp is %f\r\n", (float)appData.tmpSensorValue); |
sandyr7 | 5:8c21994db8d2 | 94 | |
sandyr7 | 5:8c21994db8d2 | 95 | /* Setup advertising payload */ |
sandyr7 | 5:8c21994db8d2 | 96 | // ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, |
sandyr7 | 5:8c21994db8d2 | 97 | // (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); |
sandyr7 | 5:8c21994db8d2 | 98 | //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | |
sandyr7 | 5:8c21994db8d2 | 99 | // GapAdvertisingData::LE_GENERAL_DISCOVERABLE); /* Set flag */ |
sandyr7 | 5:8c21994db8d2 | 100 | //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); /* Set appearance */ |
sandyr7 | 5:8c21994db8d2 | 101 | //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
sandyr7 | 5:8c21994db8d2 | 102 | //(uint8_t *)&appData, sizeof(ApplicationData_t)); /* Set data */ |
sandyr7 | 5:8c21994db8d2 | 103 | |
sandyr7 | 5:8c21994db8d2 | 104 | /* Setup advertising parameters */ |
sandyr7 | 5:8c21994db8d2 | 105 | //ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
sandyr7 | 5:8c21994db8d2 | 106 | //ble.gap().setAdvertisingInterval(1000); |
sandyr7 | 5:8c21994db8d2 | 107 | |
sandyr7 | 5:8c21994db8d2 | 108 | /* Start advertising */ |
sandyr7 | 5:8c21994db8d2 | 109 | |
sandyr7 | 5:8c21994db8d2 | 110 | //ble.gap().startAdvertising(); |
sandyr7 | 5:8c21994db8d2 | 111 | } |
sandyr7 | 5:8c21994db8d2 | 112 | |
sandyr7 | 5:8c21994db8d2 | 113 | void updateSensorValueInAdvPayload(void) |
sandyr7 | 5:8c21994db8d2 | 114 | { |
sandyr7 | 5:8c21994db8d2 | 115 | ApplicationData_t appData; |
sandyr7 | 5:8c21994db8d2 | 116 | |
sandyr7 | 5:8c21994db8d2 | 117 | accumulateApplicationData(appData); |
sandyr7 | 5:8c21994db8d2 | 118 | |
sandyr7 | 5:8c21994db8d2 | 119 | /* Stop advertising first */ |
sandyr7 | 5:8c21994db8d2 | 120 | // ble.gap().stopAdvertising(); |
sandyr7 | 5:8c21994db8d2 | 121 | /* Only update temperature value field */ |
sandyr7 | 5:8c21994db8d2 | 122 | // ble.gap().updateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
sandyr7 | 5:8c21994db8d2 | 123 | //(uint8_t *)&appData, sizeof(ApplicationData_t)); |
sandyr7 | 5:8c21994db8d2 | 124 | /* Start advertising again */ |
sandyr7 | 5:8c21994db8d2 | 125 | //ble.gap().startAdvertising(); |
sandyr7 | 5:8c21994db8d2 | 126 | } |
sandyr7 | 5:8c21994db8d2 | 127 | */ |
sandyr7 | 5:8c21994db8d2 | 128 | int main(void) |
sandyr7 | 5:8c21994db8d2 | 129 | { |
sandyr7 | 5:8c21994db8d2 | 130 | |
sandyr7 | 5:8c21994db8d2 | 131 | pc.baud(115200); |
sandyr7 | 5:8c21994db8d2 | 132 | pc.printf("Serial setup AGAIN!! \n"); |
sandyr7 | 5:8c21994db8d2 | 133 | |
sandyr7 | 5:8c21994db8d2 | 134 | /*do nothing |
sandyr7 | 5:8c21994db8d2 | 135 | //2 quick vibrations |
sandyr7 | 5:8c21994db8d2 | 136 | vib =1; |
sandyr7 | 5:8c21994db8d2 | 137 | wait(0.25); |
sandyr7 | 5:8c21994db8d2 | 138 | vib=0; |
sandyr7 | 5:8c21994db8d2 | 139 | wait(1); |
sandyr7 | 5:8c21994db8d2 | 140 | vib=1; |
sandyr7 | 5:8c21994db8d2 | 141 | wait(0.25); |
sandyr7 | 5:8c21994db8d2 | 142 | vib=0; |
sandyr7 | 5:8c21994db8d2 | 143 | */ |
sandyr7 | 5:8c21994db8d2 | 144 | // OLED part of code |
sandyr7 | 5:8c21994db8d2 | 145 | pc.printf("OLED setting up \n"); |
sandyr7 | 5:8c21994db8d2 | 146 | |
sandyr7 | 5:8c21994db8d2 | 147 | /* |
sandyr7 | 5:8c21994db8d2 | 148 | oled.init(0, 8000000); |
sandyr7 | 5:8c21994db8d2 | 149 | oled.clear(PAGE); |
sandyr7 | 5:8c21994db8d2 | 150 | oled.clear(ALL); |
sandyr7 | 5:8c21994db8d2 | 151 | oled.puts("Dance Tracker v1.1"); |
sandyr7 | 5:8c21994db8d2 | 152 | oled.display(); |
sandyr7 | 5:8c21994db8d2 | 153 | wait(2); |
sandyr7 | 5:8c21994db8d2 | 154 | pc.printf("OLED set complete\n"); |
sandyr7 | 5:8c21994db8d2 | 155 | */ |
sandyr7 | 5:8c21994db8d2 | 156 | // |
sandyr7 | 5:8c21994db8d2 | 157 | |
sandyr7 | 5:8c21994db8d2 | 158 | Ticker ticker; // to interrupt the controllers' process every period |
sandyr7 | 5:8c21994db8d2 | 159 | /* Enable trigger every 2 seconds */ |
sandyr7 | 5:8c21994db8d2 | 160 | ticker.attach(periodicCallback, 2); |
sandyr7 | 5:8c21994db8d2 | 161 | |
sandyr7 | 5:8c21994db8d2 | 162 | // ble.init(); |
sandyr7 | 5:8c21994db8d2 | 163 | pc.printf("BLE set up \n"); |
sandyr7 | 5:8c21994db8d2 | 164 | /* Start temperature advertising */ |
sandyr7 | 5:8c21994db8d2 | 165 | temperatureValueAdvertising(); |
sandyr7 | 5:8c21994db8d2 | 166 | |
sandyr7 | 5:8c21994db8d2 | 167 | |
sandyr7 | 5:8c21994db8d2 | 168 | while (true) { |
sandyr7 | 5:8c21994db8d2 | 169 | //if (triggerTempValueUpdate) { |
sandyr7 | 5:8c21994db8d2 | 170 | /* Update temperature value */ |
sandyr7 | 5:8c21994db8d2 | 171 | //updateSensorValueInAdvPayload(); |
sandyr7 | 5:8c21994db8d2 | 172 | //triggerTempValueUpdate = false; |
sandyr7 | 5:8c21994db8d2 | 173 | |
sandyr7 | 5:8c21994db8d2 | 174 | //here also display the current accelerometer values |
sandyr7 | 5:8c21994db8d2 | 175 | /* |
sandyr7 | 5:8c21994db8d2 | 176 | oled.init(0, 8000000); |
sandyr7 | 5:8c21994db8d2 | 177 | oled.clear(PAGE); |
sandyr7 | 5:8c21994db8d2 | 178 | oled.clear(ALL); |
sandyr7 | 5:8c21994db8d2 | 179 | oled.printf( "Acc values:%d,%d,%d\n", |
sandyr7 | 5:8c21994db8d2 | 180 | (int32_t) acc.getAccel(0,&wire), |
sandyr7 | 5:8c21994db8d2 | 181 | (int32_t) acc.getAccel(1,&wire), |
sandyr7 | 5:8c21994db8d2 | 182 | (int32_t) acc.getAccel(2,&wire)); |
sandyr7 | 5:8c21994db8d2 | 183 | |
sandyr7 | 5:8c21994db8d2 | 184 | oled.display(); |
sandyr7 | 5:8c21994db8d2 | 185 | */ |
sandyr7 | 5:8c21994db8d2 | 186 | pc.printf("going to print vals now\n"); |
sandyr7 | 5:8c21994db8d2 | 187 | |
sandyr7 | 5:8c21994db8d2 | 188 | pc.printf("Acc values:%d,%d,%d\n", |
sandyr7 | 5:8c21994db8d2 | 189 | (int32_t) acc.getAccel(0,&wire), |
sandyr7 | 5:8c21994db8d2 | 190 | (int32_t) acc.getAccel(1,&wire), |
sandyr7 | 5:8c21994db8d2 | 191 | (int32_t) acc.getAccel(2,&wire)); |
sandyr7 | 5:8c21994db8d2 | 192 | pc.printf("completed the acc read and oled jobs\n"); |
sandyr7 | 5:8c21994db8d2 | 193 | wait(5); |
sandyr7 | 5:8c21994db8d2 | 194 | } |
sandyr7 | 5:8c21994db8d2 | 195 | // pc.printf("completed the acc read and oled jobs\n"); |
sandyr7 | 5:8c21994db8d2 | 196 | //ble.waitForEvent(); |
sandyr7 | 5:8c21994db8d2 | 197 | //pc.printf("wait for ble event\n"); |
sandyr7 | 5:8c21994db8d2 | 198 | //} |
sandyr7 | 5:8c21994db8d2 | 199 | |
sandyr7 | 5:8c21994db8d2 | 200 | } |