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
  • 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

Children
Related