Batery Status as Senor?
Page 1 of 1

Author:  CranoBot [ Wed Mar 07, 2007 6:59 pm ]
Post subject:  Batery Status as Senor?

Hi all! I'm new to C in general but I have a very specific question: How can I read out the battery status and make my NXT's actions dependent from it? I would like it to go charge itself when batery is low. THX for your help.


Author:  Jesspepette [ Thu Mar 08, 2007 3:30 am ]
Post subject: 

you should find many interesting things there in the RobotC Software Help:

Battery & Power Control
The NXT firmware keeps track of the minutes of inactivity on a NXT. When this exceeds a configurable limit, then the NXT will automatically power off. Inactivity is defined as time without a user keypress.

The inactivity timeout value can be set via the NXT GUI. It can also be set via editing RobotC property pages. Whenever RobotC makes a connection to a NXT it will set the timeout value to the value from the property page configuration.

Note that the NXT can behave unpredictably at low voltages and when trying to write to flash memory. So whenever RobotC attempts a connection between PC and NXT it checks the battery voltage. If the voltage is too low for reliable operation, the RobotC connection will be aborted.


Calling this function resets the “inactive power down” timer.

If a application program is running and it periodically calls the ‘alive()’ function, then this will prevent the NXT from auto power off.


This function call will immediately turn off the NXT


A Boolean flag that, when set, indicates the NXT should not automatically power off when powered by an AC adaptor.


A Boolean flag that indicates whether the NXT is powered from a LEGO rechargeable battery. There is a hidden switch inside the NXT battery compartment that is depressed when a LEGO rechargeable battery is used. This variable reads the value of this switch.


The average of several recent samples of the battery voltage. A value of 7500 indicates a voltage of 7.5 volts.


The most recent sampled value of the battery voltage.


The number of minutes of inactivity that will trigger automatic power off of the NXT.


The low voltage value that will trigger automatic shutdown of the NXT. A value of 6100 indicates a shut down at 6.1V.

And this sample program should help:
//                            NXT Battery Level Access
// Test program to:
//   1. Read the NXT battery levels and display on LCD.
//   2. Ue the battery level in a user program to make a decision on program flow.
// Two RobotC intrinisc variables are available:
//        nAvgBatteryLevel
//        nImmediateBatteryLevel
// Some sensors and other devices require

const int kMinimumBatteryLvel = 6300;

task main()
  int nCounter = 0;

  while (true)
      if (nImmediateBatteryLevel < kMinimumBatteryLvel)
         // Battery level too low to proceeed.
      nxtDisplayTextLine(0, "Battery Levels");

      // Display the Battery levels
      nxtDisplayTextLine(2, "Avg %3.1fV;Now %3.1f", nAvgBatteryLevel / (float) 1000, nImmediateBatteryLevel / (float) 1000);

     // Display the voltage level at which the NXT will "shutdown"
     nxtDisplayTextLine(4, "Shutdown at%4.1fV", nShutdownVoltage / (float) 1000);

     // DIsplay the voltage level at which the NXT will "shutdown"
     nxtDisplayTextLine(5, "Sleep Tmr: %d min", nPowerDownDelayMinutes);

      // Display the Battery type: rechargeable or one-time only
      if (bNxtRechargable)
         nxtDisplayTextLine(7, "Rechargable");
        nxtDisplayTextLine(7, "Non-Rechargable");

     // You can also immediately power off the NXT as follows:
     if (nCounter > 15000)

Author:  CranoBot [ Thu Mar 08, 2007 5:13 am ]
Post subject: 

THX a lot.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group