My Raspberry Pi2 is freezing. Some online forums mentioned that freezing is due to inefficient power supply (as minimum allowed voltage is 4.75 v). In order to test this, I want to have a running job that is able to report voltage input of the power supply. Can anyone advise how to have a script that can report power level of the supply.
The Pi cannot do this, as it has no analog capability. You could of course add suitable hardware.
The Pi (at least all since B+) does have a power monitor - the APX803 chip triggers if voltage falls below 4.63±0.07V. This drives the power LED and is connected to a pin on the chip (35 for B+ but it may have changed for P2) which could be monitored.
In fact the Pi will run at lower voltages as it requires 3.3V and has an on-board regulator. The lower voltage may impact peripherals.
Pi randomly freezing, probably due to insufficient power or an unstable power source.
My recommendation is at a minimum to use a high quality phone or tablet charger that can reliably output 1.2A at 5V. However, I strongly recommend using an official Raspberry Pi power supply.
In terms of measuring power consumption a multimeter is your best bet, although this website might interest you.
As stated on the website run this set of instructions in the LXTerminal.
git clone https://github.com/raspitv/pi2test/ cd pi2test python Pi2test.py
This will give you a program that should measure the current draw of your CPU.
However looking at the results, the most the Pi 2's CPU consumes is 420mA with all 4 cores under load. Once you account for USB devices, and other circuitry on the Pi, you can see where the 1.2A recommendation comes from.