Measure coin cell voltage on nRF52840 DK

I'm trying to make a demo with nRF52840DK. And I want to power it using the coin cell. So I want to check the voltage (percentage) so that I can know how long can the device keep running without changing the battery.

I searched a little bit and I have a few questions:

  • I found a previous thread that solves the exact the same issue. Martin provided a demo ble_app_battery_service.7z in the thread.
    • I viewed the code and flashed the hex on my 52840DK board. But I don't know how to see the output. As I understand, the demo uses `nrf_drv_saadc_sample` to get the voltage and uses `NRF_LOG_INFO` to print it. I tried two ways: 1. open a serial console (in Putty, baudrate 115200, I think the port is correct) 2. use JLink and JLinkRTTClient. But from both I cannot see any output. How can I see the output?
    • I always connect my 52840DK to my PC using a USB cable (since I need to read the output from it). However, in this way, will the power source always be the USB instead of the coin cell? As I read the doc, turn the power source to 'VDD', and the coin cell will be used when there is no USB. How can we force the power source to be the coin cell (or make sure we are measuring the coin cell's voltage)
  • The previous thread was a long ago (4 years). Is it still the best way to do so for my requirement? Is there any better choice. I recently set up the environment (include nRF Connect SDK and VSCode) following the tutorials. But I don't see find a good sample for my requirement. Is there a good sample for that?

Thanks!

  • Hi,

    The nRF Connect SDK is quite different from the nRF5 SDK, so it is unlikely that you can just transfer the same code.

    For the nRF Connect SDK, out nRF Desktop sample has a Battery measurement module. Maybe get some inspiration from this?

    Regards,
    Sigurd Hellesvik

  • Hello, 

    I'm also interested in coin cell voltage measuring. It would be great if there is a sample for the nrf52dk. Is it possible to get the voltage internal, so i dont have to measure it on a gpio pin? 

    Best Regards, Jonas 

  • Hi Jonas,

    Jonas Gelhaus said:
    It would be great if there is a sample for the nrf52dk.

    We do not have a sample for using the coin cell measuring for the nrf52dk specifically.
    You will have to learn how to do it from the previous link I sent and write the code yourself.

    Jonas Gelhaus said:
    Is it possibly to get the voltage internal, so i dont have to measure it on a gpio pin? 

    Have a look at  Internal Reference Voltage .

    Keep in mind that the voltage level of a coin-cell battery does not necessarily linearly proportional with the remaining power of the battery. See the Coin-Cell datasheet for more information on that.

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    I'm trying to learn how to use Battery measurement module now. I went through the code but still have some questions.

    So it looks like in nRF Desktop, there will be some 'battery_level_event'. And an event_handler will read the battery value from the event. But how is the 'battery_level_event' generated? All I can see the main function calls `event_manager_init`. Does it mean, so long as we use event_manager, 'battery_level_event' will be generated? Or do we need to do something?

    And does it mean to use battery measurement module, we have to use event_manager and get the value from the event?

    Actually what I want is something more 'primitive'. As I asked in the original question, can we use things like `nrf_drv_saadc_sample`? I saw in introduction of Battery measurement module: 'The Battery measurement module uses Zephyr’s ADC driver to measure voltage.' So I think the module is also implemented by ADC. I messed 'Connect SDK' and 'nRF5 SDK' up at first. So as I understand now, probably I should use nRF5 SDK and I can use the saadc API to get the voltage, right?

  • Agree with JonasG that it would be useful to have a turnkey reference implementation, since this is a super common request across many/most coin cell based sensors/remotes/etc.  It does not make sense for every developer to have to reinvent this functionality on their own (with its own set of bugs and quirks to figure out).  This question has come up many, many times in this forum.

    In a future SDK release would it be possible for Nordic to add a library for measuring remaining battery capacity, and provide known-good circuit designs that work with the library?

Related