How to determine if unit is running on Battery or DC power?

Hello, I am interested in building a WisBlock solution that is installed inside a vehicle, using the RAK19010 base with power slot, and RAK19016 5-24VDC power slot module. I will also incorporate an appropriate lithium rechargeable battery.

I want to connect the unit’s power input to the vehicle ignition switch, so that when the ignition is ON, this unit receives power, and when it is OFF, the unit runs only on its internal battery.

How can I tell, within my Arduino code, whether the unit is being powered by external ignition power, or by the lithium battery? Do I have to build a separate circuit to place across the 12VDC ignition power to supply the appropriate 3.3V input to one of the RAK4631 IO pins? or is there already a built-in way to sense between battery and DC power?

In November 2021 this was not possible. See this question. Hopefully something has changed since this time with the new base board, power slot modules, etc. If not, I respectfully request adding such a through-hole pad to the board in case of developers needing this feature.

Thank you.

Hi @thegpx

What you can possible do is use one WisBlock ADC input to sense the 12v coming from the car battery.

As for the USB sensing, there is no plan to release new family of WisBlock Base. Unfortunately, this is a limitation if really need by the device application.

1 Like

Did you try

#include <nrfx_power.h>

	nrfx_power_usb_state_t usb_status = nrfx_power_usbstatus_get();

	if (usb_status != NRFX_POWER_USB_STATE_DISCONNECTED) // No USB power detected
	{
		MYLOG("APP", "No USB connection detected");
	}
	else // USB power detected
	{
		MYLOG("APP", "USB connection detected");
	}

Not 100% sure, it might detect only active USB connection with a computer.
This is nrfx_power_usbstatus_get():

NRFX_STATIC_INLINE nrfx_power_usb_state_t nrfx_power_usbstatus_get(void)
{
    uint32_t status = nrf_power_usbregstatus_get(NRF_POWER);
    if(0 == (status & NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK))
    {
        return NRFX_POWER_USB_STATE_DISCONNECTED;
    }
    if(0 == (status & NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK))
    {
        return NRFX_POWER_USB_STATE_CONNECTED;
    }
    return NRFX_POWER_USB_STATE_READY;
}

Maybe using the first part with the NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK

1 Like

Wow, that’s pretty neat. Will try. Thank you!

I think I got the states wrong.

Should be

#include <nrfx_power.h>

	nrfx_power_usb_state_t usb_status = nrfx_power_usbstatus_get();

	if (usb_status != NRFX_POWER_USB_STATE_DISCONNECTED) // USB power detected
	{
		MYLOG("APP", "USB connection detected");
	}
	else // No USB power detected
	{
		MYLOG("APP", "No USB connection detected");
	}
2 Likes