7 Replies Latest reply on Feb 10, 2016 11:18 PM by nitewing117

    Battery supply monitor

    nitewing117

      Hi All,

       

      I'm trying to research how I can monitor my battery supply and turn on an LED and activate a shutdown procedure for some subsystems when the battery is getting weak. I was wondering if there is a feature for the Edison that is similar to what is found here:

      https://code.google.com/archive/p/tinkerit/wikis/SecretVoltmeter.wiki

      There's apparently a way that certain arduino chips can measure their own voltage.

       

      To give some background about my project, I'm using an Edison with the arduino breakout board. It will be configured to be an underwater sensor that uses a PWM controlled electro-permanent magnet to attach a ballast, allowing it to sink and collect data. Unfortunately, I realized that the EPM module stays charged/connected even if disconnect the power supply. I need a means of sending single PWM pulse when the battery is low to tell the module to deactivate so I don't lose this thing.

       

      My system uses a 5V source. If there isn't a feature like the above, could I just wire up my power supply to Vin, an analog input pin, and use analogRead() to measure the power level? I know that if I opt to use a >5V source, I should use a voltage divider before doing so.

        • 1. Re: Battery supply monitor
          Vincenze

          Try to run the script battery-voltage

           

          root@edison:~# battery-voltage

          Battery Voltage = 3920 mV

          Battery level = 52%

          1 of 1 people found this helpful
          • 2. Re: Battery supply monitor
            nitewing117

            Is there a way to use this script within the arduino IDE?

            • 3. Re: Battery supply monitor
              CMata_Intel

              Hi nitewing117,

               

              You can use system calls in order to run the command.Take a look at this example:

              //For this example you need to wire the pins 0 and 1 on the Arduino Expansion Board (Rx and Tx)
              
              void setup() {
                Serial.begin(9600);      // Configure Serial Monitor
                Serial1.begin(9600);     // Configure Serial1 - UART1
              }
              
              void loop() {
                system("battery-voltage > /dev/ttyMFD1");  // Run in console the command battery-voltage and send the output to /dev/ttyMFD1 - Tx pin1
                delay(100);                                // delay of 100ms 
                char a[15];                                
                a[15]= Serial1.read();                      // a[15] will store the values from Rx pin 0
                Serial.write(a[15]);                        // Prints on the Serial Monitor the value of a[15]
              }
              

               

              You need to wire the TX to RX pins in the board (1 and 0) .

              What the sketch does is: It runs in console the command battery-voltage and sends the output to /dev/ttyMFD1 this is the UART on pins 0 and 1. By having these pins wired you can read what you are writing and then have a variable in your code to work with.

              More Information related to the UARTs: Using Serialx on Edison

               

              Regards,

              Charlie

              1 of 1 people found this helpful
              • 4. Re: Battery supply monitor
                nitewing117

                Thanks CMata_Intel.

                 

                I just recently created a separate sketch which is tying up pins 0 and 1 with an XBee and have used Serial1 in that way. What would I be physically wiring the TX and RX pins to for the battery-voltage script case?

                • 5. Re: Battery supply monitor
                  CMata_Intel

                  Hi nitewing117,

                   

                  The example I posted lets you use the output of the system call as a variable so you could use this in your code in order to be able to recognize the output of the battery-voltage function.

                  If you just use the command system("battery-voltage”) it will run the battery-voltage command on Terminal but you will not see the output. The system() function allows you to run commands on Terminal but you will not have the output on the Arduino IDE side, this is the reason why in the example the output of battery-voltage is sent to /dev/ttyMFD1 (The UART on pins 1 and 0) so you could read the value with Serial1.read()

                   

                  If you have the pins 0 and 1 unavailable you can use a multiplexer to use more UARTs or you can use a different approach in order to be able to use the outputs from the system calls.

                   

                  Regards,

                  Charlie

                  • 6. Re: Battery supply monitor
                    CMata_Intel

                    Hi nitewing117,

                     

                    I would like to know if you have chosen an approach for your project in order to use the battery-voltage command from the Arduino IDE.

                     

                    Regards,

                    Charlie

                    • 7. Re: Battery supply monitor
                      nitewing117

                      Hi Charlie,

                       

                      When I tried the sketch initially, I was receiving random characters in the serial monitor and assumed something was wrong with my board. I just got a 2nd board and realized that I had forgotten to connect pin 0 and 1 together. I just got it the code running and I am indeed receiving the same output that Vincenze posted.

                       

                      The update rate is a bit slow for my application (1 character per loop) so I may go with an analogRead() approach, but it's good to know how to use the system() command.

                       

                      Thanks.