| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ANT+ Bicycle Speed and Cadence
This example requires the following SoftDevice: S212

Important: Before you run this example, make sure to program the SoftDevice.

The combined Bicycle Speed and Cadence (BSC) example applications show the usage of the Bicycle Speed and Cadence profile.

# Receiver

The BSC Receiver application has three versions: Speed Receiver, Cadence Receiver, and Combined Speed and Cadence Receiver. You can select the receiver version using "DISPLAY_TYPE" field in the SDK configuration header file.

Each version of the BSC Receiver application connects to the nearest bicycle speed and/or cadence sensor in range and prints out incoming page data. The actual channel state is indicated by the ANT channel state indicator.

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\ant\ant_plus\ant_bsc\bsc_rx`

## User interface

If a time-out occurs during search (30 seconds by default), the ANT channel is closed and the device is put into sleep mode. To wake it up, press Button 4. You can also put the device in sleep mode by pressing Button 4 while it is searching (see BSP ANT Button Module).

# Transmitter

The BSC Transmitter application has three versions: Speed Transmitter, Cadence Transmitter, and Combined Speed and Cadence Transmitter. You can select the transmitter version using "SENSOR_TYPE" field in the SDK configuration header file.

Each version of the Transmitter application simulates a bicycle speed and/or cadence sensor. The Speed Transmitter and the Cadence Transmitter transmit the speed or cadence information in the main data page (page 5). Device-specific information is transmitted at a slower rate in the background data pages (pages 1-4). The Combined Speed and Cadence Transmitter transmits the speed and cadence information in the main data page (combined speed and cadence data page 0). It does not transmit background pages.

The application prints outgoing page data. The actual channel state is indicated by the ANT channel state indicator.

The profile information is generated by the ANT BSC simulator.

There are two ways to modify the profile information (speed and/or cadence) for each version of the Transmitter application:

- Automatic, which means that the speed and cadence values rise and fall periodically.

- Button controlled, which means that the data can be modified by pressing the buttons. Pressing Button 1 increases the speed and/or cadence values. Pressing Button 2 decreases the values.

You can select how the profile information is modified using "MODIFICATION_TYPE" field in the SDK configuration header file.

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\ant\ant_plus\ant_bsc\bsc_tx`

# Testing

Note: You can use a custom channel or encryption when running any of the ANT examples. When adding a new channel or encryption, remember to update ANT stack configuration.

You can test the Bicycle Speed and Cadence examples in different ways:

- Testing the BSC Transmitter with the BSC Receiver
- Testing the BSC Transmitter using AntWare II
- Testing the BSC examples with the ANT+ Simulator tools

## Testing the BSC Transmitter with the BSC Receiver

Note that UART is not available when you use the Dynastream D52 Starter Kit.

1. Start a terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
   - Baud rate: 115.200
   - 8 data bits
   - 1 stop bit
   - No parity
   - HW flow control: RTS/CTS
2. Ensure that the UART tracing settings are configured in the Bicycle Speed and Cadence (see Compile time configuration options).
3. Compile and program one of the BSC Receivers. Observe that the receiver board indicates states following CHANNEL_TYPE_SLAVE/CHANNEL_TYPE_SLAVE_RX_ONLY.
4. Compile and program the corresponding BSC Transmitter. Observe that the transmitter board indicates states following CHANNEL_TYPE_MASTER.
5. After a while, observe that the receiver board is connected.

The following information should be output on the console for the Transmitter:

    ANT BSC channel 0 init
    ANT BSC channel 0 open

- For the Combined Speed and Cadence Transmitter:

      BSC TX Page:                   "Combined Speed & Cadence Page"
      Cadence Revolution count:      0
      Cadence event time:            0.000s
      Speed Revolution count:        0
      Speed event time:              0.000s

- For the Speed Transmitter or the Cadence Transmitter:

      BSC TX Page number:            5
      Revolution count:              0
      BSC event time:                0.000s
      Bicycle stopped.

The following information should be output on the console for the Receiver:

    ANT BSC channel 0 init
    ANT BSC channel 0 open

- For the Combined Speed and Cadence Receiver:

      BSC RX Page Number:            "Combined Speed & Cadence Page"
      Cadence Revolution count:      31
      Cadence event time:            26.550s
      Speed Revolution count:        0
      Speed event time:              0.000s

      Computed speed value:          0 kph
      Computed cadence value:        70 rpm

- For the Speed Receiver or the Cadence Receiver:

      BSC RX Page Number:            5
      Revolution count:              0
      BSC event time:                0.000s
      Bicycle stopped.

      Page was updated
      Computed speed value:          0 kph

If you are testing the BSC Transmitter button version, observe that the computed values increase when pressing Button 1 and decrease when pressing Button 2.

If you are testing the BSC Transmitter auto version, observe that the computed values periodically rise and fall.

## Testing the BSC Transmitter using AntWare II

1. Compile and program one of the BSC Transmitters. Observe that the transmitter board indicates states following CHANNEL_TYPE_MASTER.
2. Run AntWare II. Select your ANT PC dongle (for example, ANTUSB-m) from the available devices. Configure the device channel by loading the device profile configuration from the following files, where `<Type>` is the type of Receiver device (speed, cadence, or combined) that you want to simulate: `<InstallFolder>\examples\ant\ant_plus\ant_bsc\bsc_tx\<Type>\bsc_<Type>_rx_device_profile.xml`. Alternatively, you can configure the device channel manually:
   1. Set the channel assignment to slave.
   2. Set the channel ID to "0, 123, 0" for a speed receiver, "0, 122, 0" for a cadence receiver, or "0, 121, 0" for a combined receiver.
   3. On the Basic tab, set the radio frequency to 2457 MHz and the channel period to 8118 cycles (4,036 Hz) for a speed receiver, 8102 cycles (4,044 Hz) for a cadence receiver, or 8086 cycles (4,052 Hz) for a combined receiver.
   4. Keep the default for all other settings.
3. Click the Auto-Open button. Observe that messages describing the received payload appear for each ANT message. These messages should look similar to the following fragment (the example shows data for a speed sensor):

       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-84-FF-C8-22-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-84-FF-C8-22-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-84-FF-C8-22-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-84-FF-C8-22-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09
       Received BROADCAST_DATA_0x4E
         :: 4e, 00-05-01-FF-FF-43-5C-6A-09

   Each message can be decoded according to the ANT message protocol and the Bicycle Speed/Cadence Display ANT+ device profile.

## Testing the BSC examples with the ANT+ Simulator tools

To use the ANT+ Simulator tools, you must set the ANT+ Network Key to a proper value.

You can then use the ANT+ Display Simulator to test the BSC Transmitter and the ANT+ Sensor Simulator to test the BSC Receiver. See the documentation of the ANT+ Simulator tools at thisisant.com for information about how to use these tools.

Note
  The ANT+ Network Key and ANT+ Simulator tools are available for ANT+ Adopters. Go to thisisant.com to become an ANT+ Adopter and access the key.