As we approach release, I've been adding a number of things into my code. Most people have probably noticed that I've putting a voltage divider circuit onto an analog port to measure the battery level (LiPOs don't like low voltage levels...). Up at CNRG, I had a bit of "duh, why didn't I think of that" moment when Jon Hylands suggested using the AX-12's onboard voltage measurement. So, without further ado, here's a snippet of code from Jon that will save your LiPOs (it's also at the startup of the default NUKE sketch):
float voltage = (ax12GetRegister (1, AX_PRESENT_VOLTAGE, 1)) / 10.0;
Serial.print ("System Voltage: ");
Serial.print (voltage);
Serial.println (" volts.");
if (voltage < 10.0)
while(1);
If you are running this code at startup, you'll want at least a 1000ms delay beforehand, or you won't get a real voltage reading.
-Fergs
No comments:
Post a Comment