Internal system definitions like PWR

Apologies in advance if this has been covered elsewhere - I just don’t know what terminology to use to search for it:

Where would I find the internal references to system definitions that can be used in my code - things like:

digitalRead(PWR);
analogRead(BATT); 

So its the list of PWR and BATT and other definitions I am looking for to see what else is available so I dont have to reinvent the wheel in my code. (For example until I found out about PWR - I had a resistor divider from VSUB to 0V and into an IO pinto do exactly what PWR provides already)

Found it !

1 Like

I was just about to link to that too :wink:

PWR doesn’t seem to work (Argon or Xenon) - unless I have used incorreclty?

// ------------------------------------------------------------------------------
bool checkVUSB() 
// ------------------------------------------------------------------------------
{
    bool powerState = digitalRead(PWR);
    Log.warn(powerState ? "Power ON" : "Power FAIL");
    Particle.publish("power_state", powerState ? "on" : "off", PUBLIC);
    return powerState;
}

How are you building?
What do you consider “not working”?

If i have the Argon or Xenon on a ETH featherwing with a LiPo attached. I power the module through the USB port.
Run this code

SYSTEM_THREAD(ENABLED);

/*
  DEBUG STUFF
*/

// ApplicationWatchdog wd(30000, System.reset);

SerialLogHandler logHandler(LOG_LEVEL_WARN, // Logging level for non-application messages
{ 
    { "app", LOG_LEVEL_ALL } // Logging level for application messages
});


int led = D7;
const int delayTime =  2500; //

void setup() {
    Serial.begin(115200);
    waitFor(Serial.isConnected, 30000);
    
    Serial.println(Time.timeStr()); //
    Log.info("Started");
    pinMode(led, OUTPUT);
}

void loop() {
    // wd.checkin(); // resets the AWDT count
    Serial.println(Time.timeStr()); //
    
    digitalWrite(led, HIGH);
    checkBattV();
    checkBattC();
    checkVUSB();
    delay(delayTime);
    digitalWrite(led, LOW);
    delay(delayTime);
}

// ------------------------------------------------------------------------------
float checkBattV()
// ------------------------------------------------------------------------------
{   
    float battVoltage = analogRead(BATT) * 0.0011224;
    Particle.publish("battery_voltage", String::format("%.2f",battVoltage), PUBLIC);
    Log.info("Batt level:%.2fV",battVoltage);
    return battVoltage;
}
// ------------------------------------------------------------------------------
bool checkBattC()
// ------------------------------------------------------------------------------
{   
    bool charging = digitalRead(CHG);
    Particle.publish("battery_charging", charging ? "yes" : "no", PUBLIC);
    Log.info("Batt %s charging", charging ? "is" : "not");
    return charging;
}
// ------------------------------------------------------------------------------
bool checkVUSB() 
// ------------------------------------------------------------------------------
{
    bool powerState = digitalRead(PWR);
    Log.warn(powerState ? "Power ON" : "Power FAIL");
    Particle.publish("power_state", powerState ? "on" : "off", PUBLIC);
    return powerState;
}

Power state never changes:

  • With USB plugged in the particle console shows power_state off (every 5s)
  • Unplug usb power console still shows power_state off (every 5s)

Have you set pinMode(PWR, INPUT) - I can’t seem to find that instruction?
I think unlike the STM32 devices the default on nRF is not INPUT but something like “not-set”.

Ping! - working! Sometime its so easy to miss the obvious!

1 Like

What is interesting is that on the Xenon with no battery connected is still shows CHG is high - but I have seen thread about this elsewhere …

That’s because CHG is active low (it’s actually /CHG)

1 Like

cool - help me understand how I would have seen that in the link to the source files above ?

Not directly from the device OS sources but from the HW schematic and/or the forum
https://docs.particle.io/datasheets/mesh/xenon-datasheet/#power-1
image

2 Likes