Battery Monitor Sample

This sample demonstrates measuring battery Voltage.

To run the sample:

  1. Copy the sample code to a folder on the Raspberry Pi.

  2. Open terminal, and then go to the folder you copied the sample.

  3. Run the sample with the following command:

python3 Battery_Monitor.py

Sample Code

Battery_Monitor.py
#!/usr/bin/env python3

#This sample demonstrates measuring battery Voltage.
#Install RC Driver HAT library with "pip3 install turta-rcdriverhat"

from time import sleep
from turta_rcdriverhat import Turta_RCDriver

#Initialize
rc = Turta_RCDriver.RCDriver()

try:
    #Activate fan at 50% speed
    rc.set_fan(50)

    while True:
        #Read battery Voltage
        voltage = rc.read_voltage()

        #Print the reading
        print("Battery...: " + str(voltage) + "V")

        #Wait
        sleep(2.0)

#Exit on CTRL+C
except KeyboardInterrupt:
    print('Bye.')

Result

When you run the sample, it prints the Voltage applied to the power in port. The example output should be like this:

Battery...: 0V

To stop the Python script, just press CTRL + C.

Last updated