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:


Sample Code
#!/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

rc = Turta_RCDriver.RCDriver()

    #Activate fan at 50% speed

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

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


#Exit on CTRL+C
except KeyboardInterrupt:


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