Lets get started
Right, so let’s just dive right into the code. The example below creates a persistent Eddystone beacon. It starts out by advertising in fast mode (500mS seconds between advertisements) for the first 10 seconds and then reverts back to the slow advertisement mode (2 seconds between advertisements) and continues on forever.
/*********************************************************************
* This example sets the system up for low power operation and
* creates an Eddystone beacon that chugs along forever.
*********************************************************************/
#include <bluefruit.h>
#include <nrf_soc.h>
//#define DEBUG
#if defined(DEBUG)
#define Debug(arg) Serial.print(arg)
#define Debugln(arg) Serial.println(arg)
#else
#define Debug(arg)
#define Debugln(arg)
#endif
#define URL "https://www.ilabs.se"
// Create an EddyStone URL with rssi at 0m = -40 and URL as defined above
EddyStoneUrl eddyUrl(-40, URL);
void setup()
{
/*
* First setup hardware
*/
// Set all pins to a known low power safe state.
for(int i=0;i<PINS_COUNT;i++) {
pinMode(i, INPUT_PULLUP);
}
// Configure LED pins
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, LOW);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, LOW);
// Switch of RGB LED and Bi2C connector power.
pinMode(PIN_LDO_CONTROL, OUTPUT);
digitalWrite(PIN_LDO_CONTROL, LOW);
// Since we have switched of power to the LED we need to
// bring the clk/data pin low to avoid current leakage.
pinMode(LED_NEOPIXEL, OUTPUT);
digitalWrite(LED_NEOPIXEL, LOW);
// Configure external FLASH SPI pins so that the flash memory
// enters stand by mode. If lower FLASH current is needed a
// power down command can be sent to the flash.
pinMode(PIN_SPI1_CS, OUTPUT);
digitalWrite(PIN_SPI1_CS, HIGH);
pinMode(PIN_SPI1_SCK, OUTPUT);
digitalWrite(PIN_SPI1_SCK, LOW);
pinMode(PIN_SPI1_MOSI, OUTPUT);
digitalWrite(PIN_SPI1_MOSI, LOW);
pinMode(PIN_SPI1_MISO, INPUT_PULLDOWN);
// Set internal analog reference to 3.0V
analogReference(AR_INTERNAL_3_0);
#if defined(DEBUG)
while(!Serial)
delay(10);
Serial.begin(115200);
#endif
Debugln("Bluefruit52 EddyStone URL Example");
Debugln("---------------------------------\n");
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.autoConnLed(0); // Disable connection LED
// Setup the advertising packet
startAdv();
Debug("Battery voltage: ");
Debugln(analogRead(PIN_VBAT));
Debug("Supply voltage: ");
Debugln(analogReadVDD());
Debugln("Broadcasting EddyStone URL, can be found by most Android beacon scanners.");
}
void startAdv(void)
{
// Advertising packet
// Set the beacon payload using the BLEBeacon class populated
// earlier in this example
Bluefruit.Advertising.setBeacon(eddyUrl);
// 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 10 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.setIntervalMS(500, 2000); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(10); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
delay(1000);
}
Now lets just quickly go through what happens during setup and how that relates to what we discussed on the previous page.
- The absolutely first thing we do in setup is to set all pins to a known state that is compliant with the low power consumption that we are looking for.
// Set all pins to a known low power safe state.
for(int i=0;i<PINS_COUNT;i++) {
pinMode(i, INPUT_PULLUP);
}
- Next we reconfigure the LED pins to be output again
// Configure LED pins
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, LOW);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, LOW);
- After this we disable the LDO to fully disable the RGB LED and the Bi2C connector.
// Switch of RGB LED and Bi2C connector power.
pinMode(PIN_LDO_CONTROL, OUTPUT);
digitalWrite(PIN_LDO_CONTROL, LOW);
- In order to avoid current leakage into the RGB LED we make sure the clk/data pin is set to a known state
// Since we have switched of power to the LED we need to
// bring the clk/data pin low to avoid current leakage.
pinMode(LED_NEOPIXEL, OUTPUT);
digitalWrite(LED_NEOPIXEL, LOW);
- We also need to set the pins the the external FLASH memory into a correct state to make sure the device enters low power mode.
// Configure external FLASH SPI pins so that the flash memory
// enters stand by mode. If lower FLASH current is needed a
// power down command can be sent to the flash.
pinMode(PIN_SPI1_CS, OUTPUT);
digitalWrite(PIN_SPI1_CS, HIGH);
pinMode(PIN_SPI1_SCK, OUTPUT);
digitalWrite(PIN_SPI1_SCK, LOW);
pinMode(PIN_SPI1_MOSI, OUTPUT);
digitalWrite(PIN_SPI1_MOSI, LOW);
pinMode(PIN_SPI1_MISO, INPUT_PULLDOWN);
Basically, this is what is needed for the Challenger 840 BLE boards to operate in a low power mode. Below are few plots taken from a current measurement tool with a board that is running the code above:
Current measurement fast advertisement
The first measurement is taken from the initial sequence of the board running fast advertising for 10 seconds:
Using the tools built in battery life calculator we get the following:
Current measurement slow advertisement
And here are the same measurements from the slow advertisement:
And as for the fast measurement here’s a battery life estimate using slow mode:
As you can see from the Battery Life Estimator it also takes into account the self discharge of a standard LiPo cell. Normally this is estimated to between 2%-6% per month and we used 5% here which seem to be what most people use when estimating battery life time. A safety margin is also introduced here to ensure that the battery life is not over estimated. The 2.5 years is basically what we can expect from a LiPo battery running the system under these conditions.
Other things such as temperature, mechanical stress etc will also affect the battery life but this is outside the scope of this brief article.
Also notice that this applies to LiPo batteries only. Other battery technologies such as LiFEPO4, Li/MnO2, lithium button cells and others will have completely different characteristics and may or may not be compatible with this board. So please be careful when selecting and attaching a battery to the board.
Conclusion
This brief shows how you can run a BLE beacon on currents below 20uA yielding a battery time of ~2.5 years using a small 1000mAh LiPo battery. There are a few more tricks we can employ to get rid of a few more uA’mps to gain a little extra energy. But that requires more testing and trials so we will have to come back to that in a later article.
0 Comments for “Running your Challenger 840 BLE on a battery – Part 2”