Is there a way to reduce TX power in my BLE code?

Any ideas on how I may reduce my power consumption? I measure a quiescent current draw of 7mA running the following code. I'm happy to reduce the TX power because my project only requires a range of a couple of meters. Is there a "setTxPower(low) type of function I may use? I'm running on a Seeed XIAO BLE Sense (board manager 2.6.1).

#include <TimeLib.h>
#include <ArduinoBLE.h>

BLEService allService("813e67ed-3cf4-4f27-82e5-a65799933158");    // Bluetooth® Low Energy Batt Voltage Service
BLEService timeService("d2e4ba7e-5f59-4d44-acfc-5726f4ab965a");   // Bluetooth® Low Energy Time Service

// Bluetooth® Low Energy Voltage Characteristic - custom 128-bit UUID, read and writable by central
BLEStringCharacteristic battCharacteristic("8aa8f8ba-c1a5-421d-87c9-79fa3a231027", BLERead | BLENotify, 80);
BLEStringCharacteristic timeCharacteristic("b4103f2b-1be3-411b-b362-65683ac4a7f1", BLERead | BLENotify, 60);

int analogV1_counts;
int analogV2_counts;
int Batt_counts;
int timeNow;
int secondCounter = 0;
int timeCounter;
String reading1, reading2;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  analogReference(AR_INTERNAL2V4); // Default=3.30V, INTERNAL=0.60V, 1V2=1.2V, 2V4=2.4V
  if (!BLE.begin()) {              // Begin BLE initialization
    Serial.println("Starting XIAO BLE failed!");
    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("XIAO BLE");
  BLE.setAdvertisedService(allService);
  BLE.setAdvertisedService(timeService);

  // add the characteristic to the service
  allService.addCharacteristic(battCharacteristic);
  allService.addCharacteristic(timeCharacteristic);

  // add service
  BLE.addService(allService);
  BLE.addService(timeService);

  // start advertising
  BLE.advertise();
  Serial.println("XIAO BLE active, waiting for connections...");
  delay(10);
}

void loop() {
  // listen for Bluetooth® Low Energy peripherals to connect:
  BLEDevice central = BLE.central();
  delay(1);
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    // Recheck if a central is connected to peripheral:
    while (central.connected()) {
      digitalWrite(LED_BLUE, LOW);             // turn on blue LED
      timeNow = now();                         // count in seconds from start of program
      analogV1_counts = analogRead(A0);        // read voltage V1 at pin A0 from sensor
      analogV2_counts = analogRead(A1);        // read voltage V2 at pin A1 from sensor
      delay(10);                               // delay increases brightness for the LED
      digitalWrite(LED_BLUE, HIGH);            // turn off blue LED

      // Change analog voltage int data to string
      reading1 = "Time," + (String)timeNow + ",V1," + (String)analogV1_counts + ",V2," + (String)analogV2_counts;

      // Check if 120 seconds (2 minutes) have passed. If yes, send Batt volts by BLE
      if (timeCounter == 120) {
        Batt_counts = analogRead(A2);          // read external battery at pin A2
        reading2 = "Time," + (String)timeNow + ",Batt," + (String)Batt_counts;
        battCharacteristic.writeValue(reading2);
        secondCounter = 0;
        Serial.println("2min_interval," + reading2);
      }

      timeCharacteristic.writeValue(reading1); //update reading1 BLE characteristic
      Serial.println(reading1);
      timeCounter += 2;                        // add 2 seconds to timeCounter every loop
      delay(1990);                             // sum of delays is about 2 seconds per loop
    }
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
    delay(1000);
  }
}

I will take a SWAG: Can you remove the LEDs?

Nordic Semiconductor Infocenter

Above suggests multiple transmit modes with different power modes. My guess is you will need to consult the SoC reference manual to modify the power mode. Unknown if Seeed has wrapped this in an Arduino class function.

Take a look in the library documentation and code.

Place the code in your first post, in line, using code tags. Few people on the forum will bother to download it.

I've got the LED off - good point. I do blink a LED every ADC read cycle but only for troubleshooting purposes, that too can be turned off in the use mode.

1 Like

I'm not certain that Seeed has included access to these, but you have given me more detailed info to post on their forum, thank you.

You may also want to query the Seeed forum:

Tech support

Please submit any technical issues into our forum

Agreed, I try to post duplicate questions over there, but the participation numbers are rather low compared to this forum. I get a reasonable response only sporadically. Thanks!

I found on seeed wiki this :slight_smile:

  • It is recommanded to use the Seeed nRF52 Boards library if you want to apply Bluetooth function and "Low Energy Cost Function".

so maybe You should use board 1.0.0 ?
does this matter which board to choose ( 1.0.0 or 2.6.1 mbed ) when I use arduinoBLE.h library ?

I'm a bit lost reading about versions to select in arduino ide and which version is working properly with arduinoBLE library ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.