Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
942 Views

Battery supply monitor

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 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.

7 Replies
VIvan7
New Contributor III
71 Views

Try to run the script battery-voltage

root@edison:~# battery-voltage

Battery Voltage = 3920 mV

Battery level = 52%

idata
Community Manager
71 Views

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

Carlos_M_Intel
Employee
71 Views

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:

Regards,

Charlie

idata
Community Manager
71 Views

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?

Carlos_M_Intel
Employee
71 Views

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

Carlos_M_Intel
Employee
71 Views

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

idata
Community Manager
71 Views

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.

Reply