AN1906 Bluetooth® Low Energy Digital Pedometer Demo Design Author: Zhang Feng Microchip Technology Inc. Studies have shown that proper daily exercise can reduce blood pressure and body mass index. Bracelettype activity trackers featuring step counting and Bluetooth® Low Energy (BLE) are now becoming popular as an everyday exercise measurement and motivation tool for people wanting to improve their physical activity and health. The Microchip Pedometer Demo can be worn on the wrist like a bracelet/watch. The on-board RN4020 BLE module allows the pedometer demo to communicate with a smartphone or tablet on which the user’s exercise progress can be tracked. The pedometer demo is powered by a single 3V coin lithium battery (CR2032). Figure 1 shows the block diagram of the pedometer demo. OVERVIEW A digital pedometer is a portable electronic device that counts each step a person takes by detecting the motion of the person's body with an accelerometer. This application note demonstrates the implementation of a Bluetooth Low Energy Digital Pedometer using the Microchip PIC16LF1718, a cost effective 8-bit microcontroller with extreme low power (XLP), the Microchip RN4020 Bluetooth 4.1 Low Energy Module, and the Bosch Sensortec BMA250E digital triaxial accelerometer. FIGURE 1: BLOCK DIAGRAM 8-Bit Microcontroller PIC16LF1718 I2C IOC 2015 Microchip Technology Inc. Accelerometer Bosch BMA250E CR2032 Lithium Battery VDD Push Button UART RN4020 Bluetooth® 4.1 Low Energy Module I/Os Three digits 7-Segment LED Display DS00001906A-page 1 BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN THEORY OF OPERATION Step Detection The Microchip pedometer demo uses a Bosch 10-bit triaxial digital accelerometer (BMA250E) to detect the motion of the wearer. The Microchip pedometer demo firmware running in the PIC16LF1718 microcontroller contains a step detection algorithm library developed by Bosch Sensortec. A step detection function in this library is called periodically by the user application. The microcontroller will read the acceleration data of X/Y/Z axes from the accelerometer via an I2C™ interface when the step detection function is called. The step detection function then analyzes the accumulated acceleration data and determines the number of steps taken by using pattern recognition. The accumulated number of steps can be shown on the three digit 7-Segment LED displays or a BLE application running in a smartphone/tablet that is paired with the RN4020 BLE module. Bluetooth Low Energy (BLE) Communication The RN4020 BLE module complies with Bluetooth Core Specification v4.1. The RN4020 supports 13 public profiles and 17 public services based on the Generic Attribute Profile (GATT). Among supported public profiles, four are health-device-related profiles: heart rate monitor, health thermometer, glucose meter and blood pressure monitor. The RN4020 also supports a user-defined private profile/service, which can precisely fit a user's particular application. This demo defined a private service for the pedometer application. All configurations are saved in the on-board non-volatile memory (NVM) of the RN4020, so users need to set up the module only once. The microcontroller activates the RN4020 when the BLE communication is enabled by pressing the onboard push button. The RN4020 then becomes pairable with a smartphone or tablet that supports BLE. The microcontroller periodically sends the step number to the RN4020 via UART interface after successful pairing. The RN4020 then transmits the step number to the paired smartphone or tablet, where a compatible BLE application can be used to display the step number. DS00001906A-page 2 Because the Apple® HealthKit, a new feature for iOS 8, adheres to the BLE GATT specifications, medical devices like heart rate and blood pressure monitors, thermometers, and glucose meters that are built with RN4020 will be supported natively by HealthKit. That means device manufacturers could potentially skip the process of developing a companion application for their product, and instead, allow HealthKit to automatically control the device/accessory itself when it has been paired with the RN4020 BLE module. Human Interface A single push button provides quick function control to the pedometer demo via the Interrupt-On-Change (IOC) interface. To turn on/off the LED display, press the button and quickly release it within 1 second. To enable/disable BLE communication, press the button and hold it down for more than 1 second but less than 4 seconds. To zero the step number, press the button and hold it down for more than 4 seconds, then release it. Power The pedometer demo is powered by a single 3V coin lithium battery (CR2032). The LED displays are automatically turned off after 10 seconds to save power. The baud rate of the UART communication is set to 2400 Kbps so that the RN4020 BLE module can remain in Deep Sleep mode when there is no UART data communication. If there is no motion for 16 seconds, the microcontroller will get a no-motion interrupt from the accelerometer via the IOC interface. When the no-motion interrupt occurs, the microcontroller reconfigures the accelerometer to high-g interrupt and then puts it into Low Power Mode 1. The microcontroller next goes into Sleep mode as well, putting the overall system into the lowest power consumption mode. In Low Power Mode 1, the accelerometer is periodically switching between a sleep phase and a wake-up phase. During the sleep phase the whole analog circuit of the accelerometer is powered down. During the wake-up phase, the accelerometer works normally and the high-g interrupt function is running to determine when to wake up from the Low Power Mode. The accelerometer will generate a high-g interrupt to wake up the microcontroller when the wearer's motion is over the preset threshold for a high-acceleration event, such as walking, picking up the pedometer, or waving or rotating the pedometer in the air. The pedometer then resumes normal operation after waking up. 2015 Microchip Technology Inc. BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN PROGRAM FLOWCHART Figure 2 shows the firmware process flow of the pedometer demo. FIGURE 2: BLOCK DIAGRAM Start System Initialization Main Loop Sleep Routine Step Detection Routine – Read Accelerometer & Calculate Step Number Display Step Number on Segments LED Display 2015 Microchip Technology Inc. Display Step Number thru BLE Communication DS00001906A-page 3 BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN APPENDIX A: PEDOMETER DEMO BOARD Figure 3 shows the front (top photo) and the back (lower photo) of the pedometer demo board. FIGURE 3: PEDOMETER DEMO BOARD DS00001906A-page 4 2015 Microchip Technology Inc. BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN PEDOMETER DEMO BOARD SCHEMATICS FIGURE 4: SCHEMATICS APPENDIX B: BAT PW R 1 S1 3 CL-SB-12B-01T C1 4.7uF R15 DNP R16 DNP L1 DNP 6 3 R18 0R 3 2 1 GND 5 6 7 8 9 10 12 U2 5 4 R1 DNP R2 DNP RA0 RE3 RB4 RB5 RB6 RB7 GND RA1 RB3 MCU RA2 RB2 RB0 RB1 GND VDD RA4 RA7 RC7 GND RC6 RA6 RC5 3 2 VDD R9 R17 470R 470R 470R SEG_F SEG_G SEG_DP MCP1700T-3302E/TT VSS VI N VOUT U3 Pow er Regulation VDD LDO_VI N 1 R8 GND ICSPDAT C2 10uF GND ICSPCLK 26 SEG_D SEG_E 470R 470R R6 25 24 470R VDD SEG_A C4 16V 0.1μF LD3 Blue R14 330R GND SEG_B SEG_C R3 R13 330R 470R 470R RN_TX R4 R5 22 21 20 RN_RX PI C_TX 18 16 SDA 17 19 15 R12 330R 23 R7 28 GND 27 GND C7 4.7uF RC0 RA5 RA3 U1 MCP1640T-I/CHY DNP VFB VI N VOUT EN DIGI T_ONE MCP1640_EN 11 INT1 INT2 W AKE_HW W AKE_SW DIGI T_THREE 4 PI O1 CMD/MLDP MCLR MCP1640_EN GND RC1 VDD RC4 RC2 RC3 GND PIC16LF1718-I/SS 23 24 GND LD2 Red C3 16V 0.1μF VDD GND SEG_F 4 3 2 3 2 3 2 J1 DNP RN_CTS RN_RTS RN_RX LDO_VI N PI Ck itSe rial 2 4 6 8 10 12 PI C_TX J2 DNP SEG G SEG F K K SEG DP SEG C SEG B SEG A Display SEG E SEG E SEG G SEG F K K SEG DP SEG C SEG B SEG A SEG E SEG G SEG F K K SEG DP SEG C SEG B SEG A LSHD-7503 SEG D D3 LSHD-7503 SEG D D2 LSHD-7503 SEG D D1 1 3 5 7 9 11 PI Ck it3 MCLR ICSPDAT ICSPCLK SEG_G 1 SEG_E 5 DIGI T_ONE SEG_D SEG_F 4 DIGI T_TW O 1 SEG_G 5 SEG_E SEG_D SEG_F 4 DIGI T_THREE 1 SEG_G 5 SEG_E SEG_D GND RN_TX 10 SEG_A 9 SEG_B 8 SEG_C 7 SEG_DP 6 DIGI T_ONE 10 SEG_A 9 SEG_B 8 SEG_C 7 SEG_DP GND GND 4 3 2 1 Accelerometer VDD R11 10K C5 16V 0.1μF SCL SDO SDx S C RE W S C RE W 7 8 9 10 U5 BMA250E CSB GND VDD GNDI O VDD R10 10K VDD VDDI O NC S C RE W S C RE W SDA VDD GND W ATC H BAS E Mechanica l Ass embly P arts S TANDO F F S TANDO F F S TANDO F F 10 SEG_A S C RE W S TANDO F F SEG_B 9 S C RE W SEG_DP SEG_C S C RE W 8 DIGI T_THREE 7 6 W R IS T S TRA P S C RE W 6 DIGI T_TW O 11 V DD 12 SCx IN T 2 IN T 1 5 IN T 1 IN T 2 6 2 GND R20 470R C8 16V 0.1μF 14 DIGI T_TW O 13 SCL Bluetooth Module GND 22 21 20 18 RN_RTS 19 LD1 Green 1 2 3 OFF ON VDD R19 10K GND U4 GND VDD RSVD RSVD PI O7 RSVD RTS/ PI O6 17 P IO 3 BT1 CR2032 3V S2 1 2 AIO2 AIO1 AIO0 UART_TX UART_RX W AKE_SW SPI /PI / IO /P GND P IO 2 1 SW G ND 2 VDD GND GND C6 16V 0.1μF DS00001906A-page 5 2015 Microchip Technology Inc. 3 4 5 6 CMD/MLDP RN4020-V/RM GND P IO 1 GND GND GND RN_TX RN_RX W AKE_SW 7 CMD/MLDP 8 GND G ND 16 G ND 9 P IO 1/S C K ML DP _E V /PIO 2/CS W S /PIO 3/MO S I P IO 4/MIS O C T S /PIO 5 W AK E _HW 10 11 12 13 R N_C T S 14 W AK E _HW15 P IO 1 P IO 2 P IO 3 BLUETOOTH LOW ENERGY DIGITAL PEDOMETER DEMO DESIGN APPENDIX C: WARNINGS, RESTRICTIONS AND DISCLAIMER This demo is intended solely for evaluation and development purposes. It is NOT intended for medical, diagnostic or treatment use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. DS00001906A-page 6 APPENDIX D: REFERENCES PIC16(L)F1717/8/9 Cost Effective 8-Bit Intelligent Analog Flash MCU Data Sheet (DS40001740). RN4020 Bluetooth Low Energy Module Data Sheet (DS50002279). RN4020 Bluetooth Low Energy Module Command Reference User's Guide (DS70005191). Data sheet BMA250E Digital, triaxial acceleration sensor (BST-BMA250E-DS004-05). 2015 Microchip Technology Inc. Note the following details of the code protection feature on Microchip devices: • Microchip products meet the specification contained in their particular Microchip Data Sheet. • Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. • There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. • Microchip is willing to work with the customer who is concerned about the integrity of their code. • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.” Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act. Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights. Trademarks The Microchip name and logo, the Microchip logo, dsPIC, FlashFlex, flexPWR, JukeBlox, KEELOQ, KEELOQ logo, Kleer, LANCheck, MediaLB, MOST, MOST logo, MPLAB, OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC, SST, SST Logo, SuperFlash and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. The Embedded Control Solutions Company and mTouch are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, ECAN, In-Circuit Serial Programming, ICSP, Inter-Chip Connectivity, KleerNet, KleerNet logo, MiWi, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, RightTouch logo, REAL ICE, SQI, Serial Quad I/O, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries. GestIC is a registered trademarks of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries. All other trademarks mentioned herein are property of their respective companies. © 2015, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. ISBN: 978-1-63277-172-8 QUALITY MANAGEMENT SYSTEM CERTIFIED BY DNV == ISO/TS 16949 == 2015 Microchip Technology Inc. Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified. DS00001906A-page 7 Worldwide Sales and Service AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://www.microchip.com/ support Web Address: www.microchip.com Asia Pacific Office Suites 3707-14, 37th Floor Tower 6, The Gateway Harbour City, Kowloon China - Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 Austria - Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 China - Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 Denmark - Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 India - Bangalore Tel: 91-80-3090-4444 Fax: 91-80-3090-4123 France - Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 India - New Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 Germany - Dusseldorf Tel: 49-2129-3766400 Atlanta Duluth, GA Tel: 678-957-9614 Fax: 678-957-1455 Hong Kong Tel: 852-2943-5100 Fax: 852-2401-3431 Australia - Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China - Beijing Tel: 86-10-8569-7000 Fax: 86-10-8528-2104 Austin, TX Tel: 512-257-3370 China - Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 Boston Westborough, MA Tel: 774-760-0087 Fax: 774-760-0088 China - Chongqing Tel: 86-23-8980-9588 Fax: 86-23-8980-9500 Chicago Itasca, IL Tel: 630-285-0071 Fax: 630-285-0075 Cleveland Independence, OH Tel: 216-447-0464 Fax: 216-447-0643 Dallas Addison, TX Tel: 972-818-7423 Fax: 972-818-2924 Detroit Novi, MI Tel: 248-848-4000 Houston, TX Tel: 281-894-5983 Indianapolis Noblesville, IN Tel: 317-773-8323 Fax: 317-773-5453 Los Angeles Mission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608 New York, NY Tel: 631-435-6000 San Jose, CA Tel: 408-735-9110 Canada - Toronto Tel: 905-673-0699 Fax: 905-673-6509 China - Dongguan Tel: 86-769-8702-9880 China - Hangzhou Tel: 86-571-8792-8115 Fax: 86-571-8792-8116 India - Pune Tel: 91-20-3019-1500 Japan - Osaka Tel: 81-6-6152-7160 Fax: 81-6-6152-9310 Japan - Tokyo Tel: 81-3-6880- 3770 Fax: 81-3-6880-3771 Korea - Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 China - Hong Kong SAR Tel: 852-2943-5100 Fax: 852-2401-3431 Korea - Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 China - Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 Malaysia - Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 China - Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 Malaysia - Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 China - Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 Philippines - Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 China - Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 China - Shenzhen Tel: 86-755-8864-2200 Fax: 86-755-8203-1760 Taiwan - Hsin Chu Tel: 886-3-5778-366 Fax: 886-3-5770-955 China - Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 Taiwan - Kaohsiung Tel: 886-7-213-7828 China - Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 Germany - Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Germany - Pforzheim Tel: 49-7231-424750 Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Italy - Venice Tel: 39-049-7625286 Netherlands - Drunen Tel: 31-416-690399 Fax: 31-416-690340 Poland - Warsaw Tel: 48-22-3325737 Spain - Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 Sweden - Stockholm Tel: 46-8-5090-4654 UK - Wokingham Tel: 44-118-921-5800 Fax: 44-118-921-5820 Taiwan - Taipei Tel: 886-2-2508-8600 Fax: 886-2-2508-0102 Thailand - Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 01/27/15 DS00001906A-page 8 2015 Microchip Technology Inc.