nRF52840 boards
Measurements on 3 nRF52840 boards shown below.
Top to bottom
- RAK4631 with external BLE antenna (module also does LoRa)
- Arduino Nano 33 BLE Sense
- Seeed Xiao BLE nRF52840
BLE libraries
The Arduino IDE supports all of these boards, but BLE is supported by two different libraries. The Arduino Nano 33 BLE Sense and Seeed Xiao BLE nRF52840 use the ArduinoBLE library with the low level functions handled by the Mbed OS. To implement iBeacon there is an additional small BeaconNano library used. The RAK4631 uses the Adafruit Bluefruit52lib library with FreeRTOS. The iBeacon is implemented within the Bluefruit library. Note: in the case of the RAK4631, the BLE library is automatically installed as part of the board library installation.
nRF52 TX power
Supported tx_power values depending on mcu:
nRF52832: -40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.
nRF52840: -40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +2dBm, +3dBm, +4dBm, +5dBm, +6dBm, +7dBm and +8dBm.
Default is 0 dBm.
I had problems setting the TX power with the two boards using the Mbed OS. The TX power is set within the Mbed Cordio BLE stack. I found that the boards do have individual mbed_config.h files in their variants directory that include #defines for various Cordio parameters including TX power. Unfortunately, changing that parameter definition (MBED_CONF_CORDIO_PREFERRED_TX_POWER) did not produce a change in measured TX power.
I've included the Cordio section of the mbed_config.h file below.
#define MBED_CONF_CORDIO_DESIRED_ATT_MTU 23 // set by library:cordio #define MBED_CONF_CORDIO_LL_DEFAULT_EXTENDED_ADVERTISING_FRAGMENTATION_SIZE 64 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_EXTENDED_ADVERTISING_SIZE 512 // set by library:cordio-ll[MCU_NRF52840] #define MBED_CONF_CORDIO_LL_MAX_ACL_SIZE 256 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_MAX_ADVERTISING_REPORTS 4 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_MAX_ADVERTISING_SETS 3 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_MAX_SCAN_REQUEST_EVENTS 4 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_NRF52840_CRYPTOCELL310_ACCELERATION 1 // set by library:cordio-ll-nrf52840 #define MBED_CONF_CORDIO_LL_PHY_2M_SUPPORT 1 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_PHY_CODED_SUPPORT 1 // set by library:cordio-ll[MCU_NRF52840] #define MBED_CONF_CORDIO_LL_RX_BUFFERS 4 // set by library:cordio-ll #define MBED_CONF_CORDIO_LL_TX_BUFFERS 4 // set by library:cordio-ll #define MBED_CONF_CORDIO_MAX_PREPARED_WRITES 4 // set by library:cordio #define MBED_CONF_CORDIO_NORDIC_LL_HCI_DRIVER_BUFFER_SIZE 16056 // set by library:cordio-nordic-ll[MCU_NRF52840] #define MBED_CONF_CORDIO_NORDIC_LL_WSF_POOL_BUFFER_SIZE 4900 // set by library:cordio-nordic-ll #define MBED_CONF_CORDIO_PREFERRED_TX_POWER 8 // set by library:cordio #define MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS 1 // set by library:cordio #define MBED_CONF_CORDIO_RX_ACL_BUFFER_SIZE 70 // set by library:cordio #define MBED_CONF_CORDIO_TRACE_HCI_PACKETS 0 // set by library:cordio #define MBED_CONF_CORDIO_TRACE_PAL_ECHOES 0 // set by library:cordio
The Mbed library is a pre-compiled module that is linked during sketch compilation. I've tried to find the correct method to call the Cordio function setTxPower() from my sketch code, but haven't succeeded yet. For now, I'll run some close proximity tests with the default 0 dBm default power.
BeaconNano code (same for both Nano 33 and Xiao boards)
arduino_nano_ble33_ibeacon.ino
// GGBeaconNano - Version: Latest
#include <ArduinoBLE.h>
#include <BeaconNano.h>
void setup() {
BeaconNano bn;
bn.setUuid("c336aa38054bb0483b0ae75027061982");
bn.setMajor(1);
bn.setMinor(1);
bn.setTx(197); // TX power (0xC5 = 197, 2's complement = 256-197 = -59 dBm) is the strength of the signal measured at 1 meter from the device
bn.startBeacon();
}
void loop(){
}
Arduino Nano 33 BLE Sense
Seeed Xiao BLE
The results are similar as might be expected, the Nano has a PCB antenna and the Xiao has a chip antenna.
RAK4531
I had more success being able to modify the TX power on the RAK4631. The Bluefruit library has a setTxPower() function and that works properly with the sketch code.
I took a few data points between 0 and 8 dBm to check it out. At 0 dBm the external antenna shows 7 to 9 dBm improvement over the chip/PCB antennas.
RAK4631_ble_beacon.ino
/********************************************************************* This is an example for our nRF52 based Bluefruit LE modules Pick one up today in the adafruit shop! Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! MIT license, check LICENSE for more information All text above, and the splash screen below must be included in any redistribution *********************************************************************/ #include <bluefruit.h> // Beacon uses the Manufacturer Specific Data field in the advertising // packet, which means you must provide a valid Manufacturer ID. Update // the field below to an appropriate value. For a list of valid IDs see: // https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers // 0x004C is Apple // 0x0822 is Adafruit // 0x0059 is Nordic #define MANUFACTURER_ID 0x0059 // "nRF Connect" app can be used to detect beacon uint8_t beaconUuid[16] = { 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0 }; // A valid Beacon packet consists of the following information: // UUID, Major, Minor, RSSI @ 1M BLEBeacon beacon(beaconUuid, 0x0102, 0x0304, -54); void setup() { Serial.begin(115200); // Uncomment to blocking wait for Serial connection // while ( !Serial ) delay(10); Serial.println("Bluefruit52 Beacon Example"); Serial.println("--------------------------\n"); Bluefruit.begin(); // off Blue LED for lowest power consumption Bluefruit.autoConnLed(false); Bluefruit.setTxPower(4); // Check bluefruit.h for supported values // Manufacturer ID is required for Manufacturer Specific Data beacon.setManufacturer(MANUFACTURER_ID); // Setup the advertising packet startAdv(); Serial.println("Broadcasting beacon, open your beacon app to test"); // Suspend Loop() to save power, since we didn't have any code there suspendLoop(); } void startAdv(void) { // Advertising packet // Set the beacon payload using the BLEBeacon class populated // earlier in this example Bluefruit.Advertising.setBeacon(beacon); // Secondary Scan Response packet (optional) // Since there is no room for 'Name' in Advertising packet Bluefruit.ScanResponse.addName(); /* Start Advertising * - Enable auto advertising if disconnected * - Timeout for fast mode is 30 seconds * - Start(timeout) with timeout = 0 will advertise forever (until connected) * * Apple Beacon specs * - Type: Non connectable, undirected * - Fixed interval: 100 ms -> fast = slow = 100 ms */ //Bluefruit.Advertising.setType(BLE_GAP_ADV_TYPE_ADV_NONCONN_IND); Bluefruit.Advertising.restartOnDisconnect(true); Bluefruit.Advertising.setInterval(160, 160); // in unit of 0.625 ms Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds } void loop() { // loop is already suspended, CPU will not run loop() at all }
The Eye Diagrams at 0 and 8 dBm TX power
0 dBm
+8 dBm