This is a project to receive, calculate and display the cadence from a BLE device using the Cycling Speed and Cadence service. It uses the below listed hardware and
- https://jmparound.blogspot.com/2021/02/building-cadence-display-for-ble.html
- https://github.com/jamesmontemagno/mycadence-arduino
- https://stackoverflow.com/questions/64624472/ble-cycling-speed-and-cadence-service-crank-timing-data
The software is implemented as a state machine. During setup
, the application's initialize
method is called. After setup, loop
calls the applications step
, where all state and logic will be executed.
During the initialize
, the application will set up the display, connecting to it over I2C using the default address. Next, the BLE stack is initialized and certain scan settings are set, including registering the class as the callback for onResult
of a BLE advertised device being found.
The first order of business is to locate the cadence sensor. During SCAN_DEVICES
the BLE scan is started with a callback registered for the completion of the scan.
The scan will run at most 10 times, for 30 seconds per scan.
If the scan has happened 10 or fewer times, the state will transition to SCAN_RUNNING
.
If the scan has happened 11 or more times, the state will transition to ABORT_NOTIFY
.
During SCAN_RUNNING
, the application only outputs some information to the serial interface.
If no devices advertising the CSC service are found during this scan, the state will transition back to SCAN_DEVICES
.
If a device is found advertising the CSC service, the onResult
method will transition the state to CONNECT_TO_SENSOR
.
During CONNECT_TO_SENSOR
, a remote device is connected to and the notify characteristic is set with the notify callback.
If connection fails, the state will transition to SCAN_DEVICES
.
If the connection succeeds, the state will transition to DISPLAY_CADENCE
.
During DISPLAY_CADENCE
, the cadence is displayed, if it has changed. The cadence is calculated by the notify callback, as sent by the sensor when the characteristic changes.
If the onDisconnect
callback is called, the state will transition to SENSOR_DISCONNECT
.
Otherwise, the application is expected to remain in this state until power off.
During SENSOR_DISCONNECT
, a serial message is sent to notify the sensor has disconnected.
The state will transition to SCAN_DEVICES
.
The state will transition to ABORT
, after notifying over serial and on the display of the failure to locate a sensor.
The state will never transition.
See https://learn.adafruit.com/3d-printed-case-for-adafruit-feather/overview
- feather-case.stl
- feather-bat-switch.stl
- feather-top-wing.stl
Also see https://learn.adafruit.com/on-slash-off-switches/overview