Detect if MKR 1000 is charging


When i connect both USB and battery, i can see an orange led lighting. What i want to do is to detect in my program if the battery is charging. Why: Because i do not want the program running when charging battery.

Is there a way to monitor battery life level ?


Not properly.
However a simple divider resistor of the correct value will allow you to check the voltage same way you would read any analog voltage with an Arduino.

You cannot ( AFAIK) fully stop the sketch but you can put the board to sleep.
Then you just have to wake it up occasionally to check the battery level to decide if you need more sleep.

I can see on MKR1000 shematics that this orange led is connected to PA21_TCC0-W7. But i do not know how i can read PA21 from an arduino sketch ...

You cant.

You would have to attach something to the positive connector on the back of the LIPO connector to read anything.
And a divider network resistor would have to be selected for the max of 4.7 volts (max lipo charge)

Only to complement @ballscrewbob. If you try to read the battery from the positive terminal while it is charging over the micro usb, the charging procedure can vary the actual level of the battery, to get a nice reading from the voltage divisor you would turn down the ENABLE pin from the charger IC (this isolates the battery from the charger, then you read just battery) and then turn on again, it can be done from a MKR1000 digital GPIO.

nice hack: actually you can do this every four hours in order to avoid the time limit in the charger.