Frederik De Swaef
Published © GPL3+

Orange NB-IoT RDK Power Consumption Measurement

How to measure the power consumption of the Orange NB-IoT Rapid Development Kit.

BeginnerProtip30 minutes717
Orange NB-IoT RDK Power Consumption Measurement

Things used in this project

Hardware components

AllThingsTalk Orange NB-IoT Rapid Development Kit
×1
1 Ohm resistor
×1

Software apps and online services

AllThingsTalk Orange Maker IoT Platform for Prototyping
AllThingsTalk Orange Nb-IoT Arduino SDK

Hand tools and fabrication machines

Multimeter

Story

Read more

Code

Orange NB-IoT RDK - Battery Measurement

Arduino
/*    _   _ _ _____ _    _              _____     _ _     ___ ___  _  __
 *   /_\ | | |_   _| |_ (_)_ _  __ _ __|_   _|_ _| | |__ / __|   \| |/ /
 *  / _ \| | | | | | ' \| | ' \/ _` (_-< | |/ _` | | / / \__ \ |) | ' <
 * /_/ \_\_|_| |_| |_||_|_|_||_\__, /__/ |_|\__,_|_|_\_\ |___/___/|_|\_\
 *                             |___/
 *
 * Copyright 2018 AllThingsTalk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 *  Initial source of counter example by AllThingsTalk
 *  Modified for battery status by Frederik De Swaef
 */
 
/****
 * Basic example sending the battery status to Orange Maker IoT Cloud.
 */
 
#include "ATT_NBIOT.h"
#include <CborBuilder.h>

// Mbili support
#define DEBUG_STREAM Serial
#define MODEM_STREAM Serial1
#define MODEM_ON_OFF_PIN 23

ATT_NBIOT device;
CborBuilder payload(device);

void setup()
{
  delay(3000);

  DEBUG_STREAM.begin(57600);
  MODEM_STREAM.begin(9600);
  
  DEBUG_STREAM.println("Initializing and connecting... ");

  device.init(MODEM_STREAM, DEBUG_STREAM, MODEM_ON_OFF_PIN);
  
  if(device.connect())
    DEBUG_STREAM.println("Connected!");
  else
  {
    DEBUG_STREAM.println("Connection failed!");
    while(true) {}  // No connection. No need to continue the program
  }
}

//defines for the battery measurement
#define ADC_AREF 3.3f //analog to digital reference volgate
#define BATTERY_VOLT_R1 4.7f // resistor divider value
#define BATTERY_VOLT_R2 10.0f //
#define BATTERY_VOLT_PIN A6 // 

//basic Lipo battery voltage to percentage conversion
const uint16_t batteryStates [11][2] = { {4200, 100}, {4100, 90}, {3990,80}, {3890,70}, {3780,60},{3680,50}, {3570,40}, {3470,30}, {3360,20}, {3270,10}, {3150,1}};

uint16_t getBatteryStatus()
{
    //measure the battery voltage on pin A6 BATVOLT_PIN
    uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATTERY_VOLT_R1 + BATTERY_VOLT_R2) / BATTERY_VOLT_R2 * analogRead(BATTERY_VOLT_PIN));

    //run through the conversion array
    for( int8_t i = 0; i < 11; i++)
    {
      if(voltage >= batteryStates[i][0])
      {
        return batteryStates[i][1];
      }
    }
    return 0;
}


unsigned long sendNextAt = 0;  // Keep track of time
void loop() 
{
  if(sendNextAt < millis())
  {
    payload.reset();
    payload.map(1);
    payload.addInteger(getBatteryStatus(), "battery");
    payload.send();

    sendNextAt = millis() + 10000;
  }
}

Credits

Frederik De Swaef

Frederik De Swaef

5 projects • 11 followers
Techplorer....exploring technology with a passion for embedded programming and IoT

Comments