Gadget Renesas

Linking Ideas and Electronics

Item

TOP

GR-LYCHEE Special

Let's connect with the smartphone with BLE!

Overview

Let's connect GR-LYCHEE and smartphone with BLE. GR-LYCHEE has an ESP32 module, which allows connection between Wi-Fi and BLE. This time I will use BLE to communicate with the smartphone.

Preparation

Hardware

Prepare GR-LYCHEE, USB cable (micro B type). Also prepare a smartphone that can use BLE.

login login


Software

iPhone application "LightBlue" for confirming BLE operation.

 

GATT profile

The ESP32 initial firmware has the GATT profile as follows. This profile is used to communicate between GR-LYCHEE and smartphone. In this example, GR-LYCHEE is the server and the smartphone is the client.


UUID Access property Size (bytes) Characteristic Number
A002 Read 2 -
C300 Read 1 1
C301 Read 512 2
C302 Write 1 3
C303 Write Without Response 3 4
C304 Write 2 5
C305 Notify 5 6
C306 Indicate 5 7

UUID

"A002" is set as the service UUID in the setting of Primary Service UUID (0x2800). Subsequently, Characteristic UUIDs "C300" - "C306" are included in the Characteristic Declaration (0x2803), and each access property is defined.


Access property

Read: Readable from client
Write: Writable from client. For writing, there is a response from server(GR-LYCHEE).
Write Without Response: Writable from client. There is no response from server(GR-LYCHEE) for writing.
Notify: Server(GR-LYCHEE) notifies the client of the change of Characteristic.
Indicate: Server(GR-LYCHEE) notifies to client about the change of Characteristic. Unlike Notify, Indicate also requires a response from client.

Size

It is the size of byte data that can be handled at once. It is the maximum length of the dynamic setting value.


Characteristic Number

It is the number of <char_index> obtained by the AT command "AT + BLEGATTSCHAR?" It is used to program Characteristic by program.


 

Example

Below is a sample program of BLE.

Caution: In the IDE for GR V 1.03, the parser does not operate properly due to the linker option "--specs = nano.specs", and "fail to get service" occurs. Although it is troublesome, replace "platform.txt" in IDE for GR folder "ide4gr-1.03\hardware\arduino\rza1lu\" here.

 

Operation check

Activate the serial monitor and press the reset button of GR-LYCHEE. In "Light Blue" of the smartphone application "GR-LYCHEE" is displayed. The serial monitor shows that initialization of GATT and advertising started.


When you tap GR-LYCHEE with Light Blue, the connection is established and the properties are displayed. Also, the green LED of GR - LYCHEE will light up. On the serial monitor, the connection number (conn_index) and Mac address are displayed. Connection number is always 0 for single connection. After the connection, the client reads the property of the server, so the log is displayed for 8 lines.


In the property list of LightBlue, tap UUID "C300", the default value 0x30 is displayed. After you press the UB0 button of GR-LYCHEE, if you do "Read again" with LightBlue, you can see that 0x01 is written. As the value to be written is incremented by 1 each time the button is pressed, 0x02, 0x03 are sequentially written if it is repeated several times. For example, if you connect a sensor to GR - LYCHEE and update its value, you can read the sensor value with a smartphone.


Next I will try Notification. Display UUID "C305" and press "Listen for notifications". After that, you can see that the value is displayed every time you press the GR-LYCHEE UB1 button.


Finally, let's write the data from the smartphone to GR-LYCHEE. Display UUID "C302" and press "Write new value". In the figure below, "11" is entered. When input is completed, "11" is displayed on the serial monitor.


 

share