• Power Analysis with CurrentRanger and Grafana

    11/03/2021 at 15:30 0 comments

    This project requires making sure power consumption is kept to a minimum, as it runs from a CR2032 battery. As a hobbyist, I can't afford a power analyzer, and anyway, "good enough" is usually the mindset as I'm not considering mass market. Just one household :-)

    I'd read up on the CurrentRanger by LowPowerLab and, of course, the uCurrent Gold by Dave Jones. This video by Andreas Spiess was convincing enough that, for the type of analysis I needed to do, the CurrentRanger was the way to go.

    In my application, sleep current is about 80 nA, vs about 30 mA when taking a temperature measurement. That's a ratio of 375,000 : 1. The CurrentRanger's ability to switch ranges quickly has worked beautifully to capture both extremes.

    What I found was missing was a good way to record the data, and so here are the overall steps to do so, using Grafana.

    Power Analysis with CurrentRanger and Grafana

    Steps to get this going 

    1. Install docker
    2. Install Grafana docker image
    3. Install redis docker image & redis-timeseries
    4. From Grafana, install redis-timeseries plugin
    5. Modify the CurrentRanger firmware to output timeseries-like data:

    change format to NANOS:


     add timing information to output, right around where there is a check for USB logging is enabled:

     uint32_t ms = millis(); //add this variable
     if (USB_LOGGING_ENABLED && ms != lastupdate && !(ms%10))

     and finally, change the format of the NANOS output to:

    if(LOGGING_FORMAT == LOGGING_FORMAT_NANOS) {Serial.print(millis()); Serial.print(":");Serial.println(VOUT * (RANGE_NA ? 1 : RANGE_UA ? 1000 : 1000000));} else

    This gist contains required changes. You can flash your CurrentRanger with the Arduino IDE.

    6. Use this slapped-together (but easily modifiable) python script to ingest data

    7. And finally, this is the Grafana dashboard source