Skip to main content

Documentation Index

Fetch the complete documentation index at: https://learn.pcbcupid.com/llms.txt

Use this file to discover all available pages before exploring further.

GLYPH BLE SERVER

BLE Server Image This guide will help you configure the GLYPH board as a Bluetooth server and send data to your GLYPH board through a Smart Phone, assuming you are using GLYPH-C3 (but any GLYPH development board from the ESP32 Series should work)

Step 1: Code Setup

  1. Open Arduino IDE
  2. Enter the following code into the Arduino IDE
// ESP32 Series BLE Library
#include <BLEDevice.h>  
#include <BLEUtils.h>
#include <BLEServer.h> 

//UUIDs for the Bluetooth service and characteristic
#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

//Class to handle when a data is received from smart phone
class onReceive: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
        // Retrieve the value written to the characteristic and Convert to Arduino String
        String value = pCharacteristic->getValue().c_str(); 

        // If the value length is greater than 0, print it to the Serial Monitor
        if (value.length() > 0) {
            Serial.println("*********");
            Serial.print("New value: ");
            for (int i = 0; i < value.length(); i++)
                Serial.print(value[i]); // Print each character of the received value
            Serial.println();
            Serial.println("*********");
        }
    }
};

void setup() {

    Serial.begin(115200);  // Initialize the Serial Monitor
    // Initialize BLE device with the name "GLYPHC3"
    BLEDevice::init("GLYPHC3");
  
    // Create a BLE server
    BLEServer *pServer = BLEDevice::createServer();
    // Create a BLE service with the defined UUID
    BLEService *pService = pServer->createService(SERVICE_UUID);
    // Create a BLE characteristic with the defined UUID
    BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

    // Set the function that as to be called when data is received 
    pCharacteristic->setCallbacks(new onReceive());

    // Set an initial value for the characteristic
    pCharacteristic->setValue("Hello World");
    pService->start();  // Start the service

    // Start advertising the BLE service
    BLEAdvertising *pAdvertising = pServer->getAdvertising();
    pAdvertising->start();

    // Print message indicating that the server has started
    Serial.println("BLE Server started, advertising...");
}

void loop() {
    //The main loop doesn't do anything until the data is received by the BLE 
    delay(2000);  // Wait for 2 seconds
}

This code is derived and modified from SeeedStudio Xiao ESP32C3
If your Arduino ESP32 Core is not upgraded to version 3.0.0 or above, make sure to update the code:
  • Change String value = pCharacteristic->getValue(); to std::string value = pCharacteristic->getValue();

Step 2: Upload the Code

  1. Connect the Board
    • Connect your GLYPH board to your computer
  2. Select the Board and Port Do the following setting in your Arduino IDE,
    • Tools > Board and select the appropriate board.
    • Tools > Port and select the port connected to your GLYPH.
    • Tools > USB CDC on Boot and select Enabled
If USB CDC on BOOT not enabled, you won’t be seeing any serial data on Arduino IDE.
  1. Upload the Code
    • Click the upload button (➡️ icon) or use the shortcut CRTL + U in Arduino IDE to upload the code to the board.

Step 3: Download & Install LightBlue App

  1. Install the App

Step 4: Connect to the Bluetooth Device

  1. Open Bluetooth on Your Phone
    • Ensure Bluetooth is enabled on your smartphone.
  2. Scan for Devices
    • Bring your phone close to the GLYPH board.
    • Scan for devices and locate the GLYPHC3 device.
      PCBCUPID_available_devices

Step 5: Open LightBlue App and Connect

  1. Open the LightBlue App
    • Launch the LightBlue app on your smartphone.
  2. Scan Tab
    • Click on the scan tab.
  3. Connect to Device
    • Click CONNECT next to GLYPHC3.
    PCBCUPID_connect
  4. Select Readable, Writable Section
    • Click on the section at the very bottom which says Readable, Writable.
    PCBCUPID_READABLE_WRITABLE
  5. Set Data Format
    • Under the Data format drop-down menu, select UTF-8 String.
    PCBCUPID_format
  6. Send a Message
    • Type any text that you like to send to your GLYPH Board, In this case let’s try “PCBCUPID-GLYPHC3” under WRITTEN VALUES and click WRITE.
    PCBCUPID_WRITE_VALUE

Step 6: View the Output

  1. Check the Serial Monitor
    • You will see the text string “Hello” output on the Serial Monitor of Arduino IDE.
    PCBCUPID_output_bluetooth_result