Cant build zephyr battery example

Hi,

I was trying to build the zephyr battery example Battery Voltage Measurement — Zephyr Project Documentation (nordicsemi.com) . But when I was building the project, it raises an error like this:

note: in expansion of macro 'DEVICE_DT_GET'

78 | .adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(ZEPHYR_USER)),

What should I do? Or is there any way to read/calculate/measure the input voltage to a pin?

Parents Reply Children
  • No worries. I’m GMT+10, so I’ve got my whole day ahead of me :-)

    OK, so I grabbed the example code from ...v2.2.0/zephyr/samples/boards/nrf/battery and added the overlay file as described here.

    This is what my overlay file looks like:

    / {
        zephyr,user {
           io-channels = <&adc 4>;
        };
     };

    That all builds without errors if I use the nrf52dk_nrf52832 as my target (that's the DK I am using)

    However, if I try and build it for the nrf52840dk_nrf52840, then I see the same error you are getting.

    However, if I add the voltage divider version of the vbatt node to my overlay file instead, like this:

    / {
    
        vbatt {
            compatible = "voltage-divider";
            io-channels = <&adc 0>;
            output-ohms = <47000>;
            full-ohms = <(100000 + 47000)>;
            power-gpios = <&gpio0 30 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
            };
        };

    Then I can get it to build without errors for the nrf52840dk_nrf52840.

    In my application, I'm actually using a voltage divider to step the voltage down (so, I'm measuring the battery voltage across a 47K resistor, which is in series with a 100K resistor, hence the values above for ouput-ohms and full-ohm), and I'm also enabling the battery voltage to the relevant GPIO using an arrangement of MOSFETs (means I can keep quiescent current down).  I'm using P0.30 as my enable signal, hence the value for power-gpios above where I am setting this to Pin 30.  The flags indicate that I need to set it high to activate it, and that its normally pulled low when I'm not driving that GPIO via firmware.

    I've attached the code here as a .zip file so you can see what I've done

    Hope that helps sort out your issue

    Cheers,

    Mike

    battery_nordic.zip

  • Thank you for your answer Mike. I changed my overlay file as you said. But the error occured again.(note: in expansion of macro 'DEVICE_DT_GET' undefined). Then, I downloaded the zip and tried to build again. But a cmake error occured(Configuration incomplete). I' ve attached to you my code as zip.

    Thanks in advance 

    battery_BehicMV.zip

  • OK, your code builds OK for me - no errors.

    Try deleting your build folder within Windows Explorer (just delete the 'build" subfolder under your project directory), then doing a pristine build in VSC, via:

    View->Command Palette->nRF Connect:Pristine Build

    Let me know if that fixes things.

  • Hello Mike.

    BehicMV is a very close friend of mine who I am currently co-working with in the project that he is trying to solve the problem which is connected to this ticket. 

    Because of the fact that you have mentioned the code builds for you OK, without any problems, we have tried to build it from my computer (we were trying to build the code from his computer until now). Everything worked fine, and I just wanted to ask the reason behind this weird issue.

    Thanks for your help!

Related