|
1 | | -# ArduinoBLE |
| 1 | +# ArduinoBLE — BLE 5.0 PHY Fork |
2 | 2 |
|
3 | | -[](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) |
| 3 | +> **Fork of [arduino-libraries/ArduinoBLE](https://github.com/arduino-libraries/ArduinoBLE)** with BLE 5.0 PHY support (2M PHY, Coded PHY). |
| 4 | +
|
| 5 | +## What's Added |
| 6 | + |
| 7 | +The stock ArduinoBLE library doesn't expose BLE 5.0 PHY control, even though the underlying hardware (nRF52840, etc.) and BLE stack (Cordio) fully support it. This fork adds ~70 lines to expose PHY selection through the existing HCI layer. |
| 8 | + |
| 9 | +### New API |
| 10 | + |
| 11 | +```cpp |
| 12 | +#include <ArduinoBLE.h> |
| 13 | + |
| 14 | +void setup() { |
| 15 | + BLE.begin(); |
| 16 | + |
| 17 | + // Set preferred PHY for all new connections |
| 18 | + // Bit 0 = LE 1M, Bit 1 = LE 2M, Bit 2 = LE Coded |
| 19 | + BLE.setPreferredPhy(0x03, 0x03); // prefer 2M, accept 1M fallback |
| 20 | + |
| 21 | + // ... rest of your setup |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +| Method | Description | |
| 26 | +|--------|-------------| |
| 27 | +| `BLE.setPreferredPhy(txPhys, rxPhys)` | Set default PHY preference for all new connections | |
| 28 | +| `BLE.requestPhy(handle, txPhys, rxPhys, options)` | Request PHY change on an active connection | |
| 29 | +| `BLE.readPhy(handle, txPhy, rxPhy)` | Read current PHY of a connection | |
| 30 | + |
| 31 | +### PHY Bit Values |
| 32 | + |
| 33 | +| Bit | PHY | Benefit | |
| 34 | +|-----|-----|---------| |
| 35 | +| `0x01` | LE 1M | Default, always supported | |
| 36 | +| `0x02` | LE 2M | ~2x throughput | |
| 37 | +| `0x04` | LE Coded | ~4x range (long range) | |
| 38 | + |
| 39 | +OR bits together for preferences: `0x03` = "prefer 2M, accept 1M". |
| 40 | + |
| 41 | +### Backward Compatible |
| 42 | + |
| 43 | +- Falls back to 1M if the remote device doesn't support 2M/Coded |
| 44 | +- No changes to existing API — all your current code works unchanged |
| 45 | +- PHY negotiation happens at the controller level; your application code doesn't need to handle it |
| 46 | + |
| 47 | +### Tested On |
| 48 | + |
| 49 | +- Arduino Nano 33 BLE (nRF52840 + mbed/Cordio) |
| 50 | +- Should work on any board with a BLE 5.0-capable controller |
| 51 | + |
| 52 | +## Installation |
| 53 | + |
| 54 | +### Arduino IDE |
| 55 | +1. Download this repo as a ZIP |
| 56 | +2. Sketch → Include Library → Add .ZIP Library |
| 57 | +3. Select the downloaded ZIP |
| 58 | + |
| 59 | +### Manual |
| 60 | +```bash |
| 61 | +cd ~/Arduino/libraries |
| 62 | +git clone https://github.com/LAPlanters/ArduinoBLE.git |
| 63 | +``` |
| 64 | +This replaces the stock ArduinoBLE. To revert, delete the folder and reinstall via Library Manager. |
| 65 | + |
| 66 | +## Changes from Upstream |
| 67 | + |
| 68 | +All changes are in 4 files: |
| 69 | + |
| 70 | +- `src/utility/HCI.h` — Added `READ_PHY`, `SET_DEFAULT_PHY`, `SET_PHY` to `LE_COMMAND` enum; `PHY_UPDATE_COMPLETE` to `LE_META_EVENT` enum; method declarations |
| 71 | +- `src/utility/HCI.cpp` — Implemented `leSetDefaultPhy()`, `leSetPhy()`, `leReadPhy()`; added `PHY_UPDATE_COMPLETE` event handler |
| 72 | +- `src/local/BLELocalDevice.h` — Declared `setPreferredPhy()`, `requestPhy()`, `readPhy()` |
| 73 | +- `src/local/BLELocalDevice.cpp` — Implemented the public API methods |
| 74 | + |
| 75 | +## Original README |
4 | 76 |
|
5 | 77 | Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. |
6 | 78 |
|
|
0 commit comments