Datasheet

2. Next, you can configure the Heart Rate Measurement characteristic (hrmc above). The values that you set for this
will depend on the characteristic definition, but for convenience sake we've documented the key information in the
comments in the code above.
' hrmc.setProperties(CHR_PROPS_NOTIFY); ' - This sets the PROPERTIES value for the characteristic, which
determines how the characteristic can be accessed. In this case, the Bluetooth SIG has defined the characteristic
as Notify, which means that the peripheral will receive a request ('notification') from the Central when the Central
wants to receive data using this characteristic.
` hrmc.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); ` - This sets the security for the characteristic, and
should normally be set to the values used in this example.
` hrmc.setFixedLen(2); ` - This tells the Bluetooth stack how many bytes the characteristic contains (normally a value
between 1 and 20). In this case, we will use a fixed size of two bytes, so we call .setFixedLen. If the characteristic
has a variable length, you would need to set the max size via .setMaxLen.
' hrmc.setCccdWriteCallback(cccd_callback); ' - This optional code sets the callback that will be fired when the CCCD
record is updated by the central. This is relevant because the characteristic is setup with the NOTIFY property.
When the Central sets to 'Notify' bit, it will write to the CCCD record, and you can capture this write even in the
CCCD callback and turn the sensor on, for example, allowing you to save power by only turning the sensor on
(and back off) when it is or isn't actually being used. For the implementation of the CCCD callback handler, see
the full sample code at the bottom of this page.
' hrmc.begin(); ' Once all of the properties have been set, you must call .begin() which will add the characteristic
definition to the last BLEService that was '.begin()ed'.
3. Optionally set an initial value for the characteristic(s), such as the following code that populates 'hrmc' with a correct
values, indicating that we are providing 8-bit heart rate monitor values, that the Body Sensor Location characteristic is
present, and setting the first heart rate value to 0x04:
The CCCD callback handler has the following signature:
Note that we use .notify() in the example above instead of .write(), since this characteristic is setup with the
NOTIFY property which needs to be handled in a slightly different manner than other characteristics.
// Set the characteristic to use 8-bit values, with the sensor connected and detected
uint8_t hrmdata[2] = { 0b00000110, 0x40 };
// Use .notify instead of .write!
hrmc.notify(hrmdata, 2);
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 47 of 175