user guide pic24 xlp bluetooth le iot demoww1.microchip.com/downloads/en/devicedoc/pic24 iot demo...

14
MICROCHIP User Guide PIC24 XLP Bluetooth LE IoT Demo

Upload: others

Post on 06-Sep-2019

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

MICROCHIP

User Guide

PIC24 XLP

Bluetooth LE

IoT Demo

Page 2: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

Contents 1. Introduction ...................................................................................................................................... 3

2. PIC® Microcontrollers with XLP Technology ............................................................................. 3

3. Microchip RN4020 Module............................................................................................................ 3

4. Android application ......................................................................................................................... 4

4.1. Main functionality of the IoT application: .............................................................................. 4

5. Hardware Requirements ............................................................................................................... 4

6. Hardware Connections .................................................................................................................. 6

5. Installing the Android application on SmartPhone or Tablet ................................................... 8

6. Demo Instructions .......................................................................................................................... 9

6.1. Establishing connection between Android application and RN4020 module .................. 9

6.2. LED Control ............................................................................................................................. 11

6.3. Switch States .......................................................................................................................... 11

6.4. 128bit AES Encryption ........................................................................................................... 12

6.5. 128bit AES Decryption .......................................................................................................... 12

7. Power Saving ................................................................................................................................ 13

8. References .................................................................................................................................... 14

Page 3: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

1. Introduction

Bluetooth® has emerged as a standard of choice for connecting local embedded applications through a router, smartphone or tablet. Today, Bluetooth is known to provide easy and temporary connectivity to smartphones and tablets, and is supported in many Android® and iOS® applications. Many applications only need simple command and control, or a quick status update from a sensor. By catering to these needs Bluetooth Low Energy (BLE) has evolved to support these low-duty cycle applications. However when the application is a simple command and control, the power consumption is also expected to be as low as possible. Power consumption has become one of the foremost concerns for embedded system designers. It is important that a microcontroller not only consumes as little power as possible, but also provides features that allow for minimal power consumption in the rest of the design as well. Microchip’s eXtreme Low Power PIC® Microcontrollers and RN4020 Bluetooth low energy module help in achieving low power consumption. This demonstration shows the simple communication between the RN4020 module and a Bluetooth Low Energy (BLE) supporting smartphone or tablet. The RN4020 module is controlled by the PIC24FJ128GB204 MCU which also includes a hardware crypto engine used for AES encryption in the demonstration. The demo is built using standard development tools from Microchip including the Explorer 16 Board, PIC24FJ128GB204 Processor Plug-In Module (PIM), and Bluetooth LE PICtail Plus Daughter Card. These readily available tools can be used to easily replicate this demo on your own. The demo is supported by MCU firmware and an app that will run on an Android phone or tablet.

2. PIC® Microcontrollers with XLP Technology

As more electronic applications require low power or battery power, energy conservation becomes paramount. Today’s applications must consume little power and, in extreme cases, last for up to 15–20 years while running from a single battery. To enable applications like these, products with Microchip’s eXtreme Low Power (XLP) Technology offer the industry’s lowest currents, where extreme low power applications spend 90–99% of their time. The PIC24FJ128GGB204 device used in this demo has an integrated hardware Crypto engine. The Crypto Engine is intended to accelerate applications that need cryptographic functions. The Crypto engine supports AES and DES/TDES ciphers. 128-bit AES is shown in this demo.

3. Microchip RN4020 Module

Bluetooth Low Energy (BLE), also known as Bluetooth Smart, is intended for low-duty cycle devices that support low-data throughput and can operate for a longer duration compared to other protocols from a coin cell battery. BLE operates in the same spectrum band (i.e. 2.400 GHz to 2.4835 GHz ISM band) as Classic Bluetooth technology, but uses a different set of channels and different modulation techniques. For additional information related to Bluetooth and its specifications, refer to “Bluetooth Core Specification V4.0” from the following web site: http://www.bluetooth.org.

The Microchip RN4020 is a fully-certified Bluetooth Version 4.1 module for adding low-power wireless capability to applications and products.

Note: This demo is based on the RN4020 PICTail module with 1.20 firmware version. To get the firmware version refer to commands in RN4020 datasheet.

Page 4: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

4. Android application

The android application (16-bit XLP BLE AES Demo) interacts with the RN4020 BLE PICTail plus module. The smart phone or tablet in which the app is installed should support Bluetooth 4.0 or newer. The app is compatible with Android 5.0 lollipop and lower versions.

4.1. Main functionality of the IoT application:

Discover BLE devices nearby

Toggle the LEDs on the Explorer16 board

Reflect the switch state of the Explorer16 board

Receive 128 bit AES encrypted data (cipher text) from the PIC24FJ128GA204/

GB204 device for a given plain text

Receive 128 bit AES decrypted data from the PIC24FJ128GA204/ GB204 device for

a given cipher text

5. Hardware Requirements

Below are the hardware requirements to run this demo:

1. Power Supply (9V)

https://www.microchipdirect.com/ProductSearch.aspx?Keywords=AC002014

2. Microcontroller: PIC24FJ128GB204 PIM (Part # MA240036) or PIC24FJ128GA204 PIM

(Part # MA240037) for Explorer 16 Board. The device needs to be programmed on the

Explorer16 board with supported hex file which can be downloaded from

www.microchip.com/PIC24IoTDemo. To learn more about loading a hex file, view this

video: https://www.youtube.com/watch?v=pEMORwwuyos.

The jumper settings on the PIM’s for this demo are given below-

PIC24FJ128GA204

PIM

PIMPIC24FJ128GB204

PIM

J1 at POT J1 at USBID

Page 5: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

J2 at Temp J2 at SC_RX

J3 at SC-RX J3 at SC_TX

J4 at SC-TX J4 at EE_CS

J5 at EE-CS J5 at VBUS/PMD6

J6 at PMWR J6 at POT

J7 at TEMP

J8 at PGC1

J9 at PGD1

3. RN4020 Bluetooth PICTail Daughter Card with JP1 jumper placed (Part # RN-420-

PICtail)

4. Explorer16 Development Board (Part # DM240001)– Both PIM and PICtail Daughter

Card plug directly into the Explorer 16 Board

Page 6: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

6. Hardware Connections

1. Mount the RN4020 Bluetooth PICTail Daughter Card on Explorer16 Development

Board’s PICTail Plus slot. Make sure the Pin No1 of PICTail is aligned to Pin No1 of PICTail

Plus slot as shown below.

2. Mount the PIC24FJ128GA204 or PIC24FJ128GB204 PIM in the U1 socket as shown

below

Page 7: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

3. On the Explorer16 Board make sure to connect

The Switch S2 to PIM end

Jumper J7 to PIC24 end

Mount the jumper JP2

4. Power up the Explorer16 board using 9V supply

Page 8: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

5. Installing the Android application on SmartPhone or Tablet

The Android application must be installed on the smartphone or tablet. The phone or tablet must support Bluetooth 4.0 or newer running Android 5.0 lollipop or newer versions. To install the app, please follow the steps below.

Enable “Unknown Sources” on Android - to enable Unknown Sources go to

Settings > Security and check the box next to” Unknown Sources “

Download the APK file “com.microchip.iotdemo-2.apk” from the webpage:

www.microchip.com/PIC24IoTDemo

Install the .APK file

Navigate to the directory where the .APK file has been downloaded

Tap the .APK file and an installation dialogue box will pop-up. Hit the install

button to install the .APK on your Android device

Page 9: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

6. Demo Instructions

6.1. Establishing connection between Android application and RN4020 module

1. On power-up of the Explorer16 Board

WAKE LED of the RN4020 module will turn on

On Explorer16 LED D7 starts flashing every 0.5 seconds

2. Run the “16XLP BLE AES Demo” application on the Android device

3. If Bluetooth is off, the app will request to turn on the Bluetooth - Select “Allow”

Page 10: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

4. The app will scan for BLE enabled modules in the vicinity. If found, it displays the

name as “IoT_BLE”.

5. Selecting IoT_BLE establishes connection between Android phone or tablet and

RN4020 module on the Explorer 16 Board. This also opens the interactive screen

on the tablet or smartphone

Connection status is reflected with CONN LED ON in RN4020 PICTail module and LED

D7 ON in the Explorer16 board.

Page 11: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

6.2. LED Control

The app controls turning ON and OFF of the LED D9 and D8 independently on

Explorer16 Board. This demonstrates controlling an end application remotely from the

phone or tablet.

6.3. Switch States

The app also reflects the status of S3 and S4 switches of Explorer16 Board. Changing

the state of the switches on the Explorer 16 Board will reflect in the on/off states

changing on the app. This demonstrates communication of sensor information or data

from an end application to a phone or tablet.

Page 12: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

6.4. 128bit AES Encryption

In order to protect the data in the end application, the data can be encrypted locally,

before being sent to/from the board (end application) to the phone or tablet and

sometimes on to a cloud-based storage.

On the app, the hex numbers to be encrypted in the “Plain Text” section can be entered.

Plain text can be maximum of 32 characters and any text less than 32 characters are

appended with 0’s by the app.

AES encryption tools are available online, such as http://aes.online-domain-tools.com/

After entering the data to be encrypted, press the “Encrypt” button on the app. The

PIC24FJ128GA204 or PIC24FJ128GB204 device will encrypt the data by using the

default 128bit Key “95 A8 EE 8E 89 97 9B 9E FD CB C6 EB 97 97 52 8D”.

Encrypted data will be displayed in “Cipher Text” section.

6.5. 128bit AES Decryption

Enter the hex numbers to be decrypted in the “Cipher Text” section. Cipher Text can be

maximum of 32 characters and any text less than 32 characters are appended with 0’s

by the app. After entering the data to be decrypted, press “Decrypt” button. The PIC24F

MCU will decrypt the data and it will be displayed in “Decrypted Text” section.

Page 13: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

7. Power Saving

If the is no activity for 1minute either in the android application or on the Explorer16

Board, the BLE module and the PIC device enter to sleep mode in order to save

power. When entering sleep, the following will happen:

o The WAKE LED of the BLE module will turn off

o LED D7 on Explore16 turns OFF

o Activities in the application will be disabled

Page 14: User Guide PIC24 XLP Bluetooth LE IoT Demoww1.microchip.com/downloads/en/DeviceDoc/PIC24 IoT Demo User Guide.pdf · Install the .APK file Navigate to the directory where the .APK

The RN4020 and PIC24 will wake up by asserting either S3 or S4 switch on the Explorer

16 Board.

8. References

For more information on PIC24F devices, crypto module or RN4020 module refer to:

www.microchip.com/PIC24FJ128GB204 www.microchip.com/PIC24FJ128GA204 www.microchip.com/RN4020

AN1861 - Bluetooth® Smart Communication Using Microchip RN4020 Module and 16-bit

PIC® Microcontroller