This project is a high-speed CAN-Bus datalogger for a BMW Z4 E85. It integrates into the onboard network and feeds data to RaceChrono over Bluetooth Low Energy (BLE).
- High-speed GPS module
- Upload 3d printed enclosure .stl files and pictures
- Bluetooth security
- Update rate improvements
- Merge CAN messages?
- XY-Axis acceleration data
- Formulas/decoding needs to be fixed
- ASL ESP32-CAN-X2
- Tulay's Wire Werks E46 CAN-Bus Plug and Play Adapter
- 3D printed enclosure (SLS nylon)
To achieve high CAN message throughput, the following things should be considered:
- Choose 2M BLE PHY over 1M or CODED PHY
- Run freeRTOS CAN and BLE tasks with higher than 0 (IDLE) priority
- Use a fast CAN ARBID filter function
- Ensure that there are free BLE transmit buffer available before sending (
esp_ble_get_cur_sendable_packets_num
) - Set the TX power to a high enough setting, depending on distance to phone
- Filter out uninteresting CAN ARBIDs in hardware
- Set BLE MTU higher than message size + 4
- Request HIGH connection priority on the client side
The BLE stack operates on two connection interval values (min, max), which
effectively determine the maximum possible update rate for CAN-bus messages
transmitted from the ESP32 device to the phone. While we can set the preferred
values on the server side with pAdvertising->setMinPreferred(0x06);
, it's the
client (phone) which ultimately chooses the values. By default, my Android Pixel
4 seems to pick a balanced value resulting in a update rate of ~30-40 Hz. Apps
can explicitly request a priority for a given connection docs, picking between 4 presets.
In my experiments I used the nRF Connect app to both log and set BLE parameters. When following these steps, I could significantly increase the observed CAN message rate:
- Enable Bluetooth
- Open nRF Connect app and connect to data logger
- From drop-down, open "Request connection priority" and pick
HIGH
- Confirm change in logs
- Open Racechrono
- Start new recoding session
- Open sensor menu
^
and confirm "Bluetooth LE CAN-bus" update rate
Here are the different rates observed with different settings:
Connection Prio | Data Rate [Hz] |
---|---|
default | ~45 |
HIGH | >60 |
BALANCED | ~45 |
LOW_POWER | 7 |