GetBatteryVoltage()
Purpose
Read the potential difference between the 12V and GND green terminals (the board supply voltage).
When to use
If you want to know the robot’s battery voltage during the code execution.
Where to use
Most probably in the void loop()
part of your .ino
file, since we’d usually want to actively monitor the value.
Click here to learn more on the power supply circuits of the 9880 board.
This function requires the use of the following CrcLib functions at some point of your .ino
file in order to work properly:
Returns
This function returns the value of the board supply voltage in Volt as a float
type.
Main prototype
static float CrcLib::GetBatteryVoltage(float correction)
The following parameters must be passed to the function for it to work properly:
correction
: The voltage divider correction factor that is unique to your board. Must be of the typefloat
. See below for more information.
Overloads
#1: Without a correction factor
static float CrcLib::GetBatteryVoltage()
The following parameters must be passed to the function for it to work properly:
No parameters needed. A correction factor of 1.0 will be used automatically.
Examples
More on this function
How does it work ?
The board uses a micro-controller analog input hooked up to a voltage divider embedded on the board to read the potential between the 12V and GND green terminals. The voltage divider steps down the 12V voltage to something that can be read by the micro-controller.
For more information on voltage divider, read this!
How to identify the correction factor for a given CrcDuino board
Write a simple program to print to the serial monitor the battery voltage reading. Start by using a 1.0 correction factor, and upload it to your board. On the serial monitor appears the voltage read by the micro-controller.
Hook a multimeter to the battery terminals to read the voltage of your battery.
By trial and error, change the correction factor until the reading on the serial monitor corresponds to what is read by the multimeter.