Shop OBEX P1 Docs P2 Docs Learn Events
MyVolts program — Parallax Forums

MyVolts program

RsadeikaRsadeika Posts: 3,837
edited 2013-09-23 06:46 in Learn with BlocklyProp
On my ActivityBot I have the Boebot li-ion power pack installed, and as per the suggestion by Andy, I wired up a circuit to measure the state of the battery. The program is working as expected, it shows a value of ~4.93 Volts, but what is that really showing me? The li-ion pack is putting out, or is rated at 7.4 Volts, the program is showing ~4.93 Volts, but when I plug in to charge, the blue LEDs are flashing, which means it is not ready for a charge. So I guess the question is, what is the state of my battery charge?

What I would like to do is, for my ActivityBot program, I will add this function and monitor the battery state via the XBee terminal, and at some Volt number I can have the ActivityBot start flashing a red LED as a warning, and maybe display a message on the terminal screen. But first a discussion of what that ~4.93 is really telling me.

Thanks

Ray
/*
  myvolts.c
   
*/
#include "simpletools.h"
#include "adcDCpropab.h"

int main()
{
  // Add startup code here.
  adc_init(21,20,19,18);
  float v3;
 
  while(1)
  {
    // Add main loop code here.
    v3 = adc_volts(3);
    v3 = v3*2;
    putChar(HOME);
    print("%f  Volts%c\n",v3,CLREOL);
    pause(100);   
  }  
}

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2013-09-22 16:53
    Without knowing the voltage divider that you are using it would be very difficult to tell you what ~4.93 volts you are getting actually means. How are you reducing the battery voltage to something meaningful below 5 volts that you are applying to A/D 3 ?

    I just tested your code with the following setup:

    I applied a 7.2 volt source to one side of a 100K pot, grounded the other side, and adjusted the center pin to 3.6 volts. Appllied that to A/D 3 and ran your program as you posted it. The terminal screen displayed continuously 7.2xxxxxx volts.

    So the code is good, more than likely your voltage divider is not using equal resistors.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-09-23 00:46
    For battery monitoring, try this:

    Take an unused pair of servo ports, like P16 and P17, and set the power jumper for that pair to VIN.

    Run a socket to pin jumper from the center pin of either the P16 or P17 port to an unused row on the breadbaord.

    Connect two 10 k resistors in series (end to end) from GND to the VIN row you created on the on the breadbaord.

    The row where the two series resistors are connected together should have half of the VIN voltage. Check with a voltmeter.

    After using a voltmeter to verify that the voltage at the node where the series resistors meet is 1/2 VIN, connect a jumper wire from that half voltage row to A/D3.

    Start with the Measure Volts project from http://learn.parallax.com/propeller-.../measure-volts. Modify it to display just v3. You could also multiply v3 by 2 so that it displays the actual battery voltage.

    The Lion pack docs will probably have some info on when the batteries are tired. As for the 5-cell alkaline pack, I'd say test if your ActivityBot continues performing down to 6 V.

    You'll probably want to make your code take an average of voltages. Avoid taking voltage measurements during direction changes because battery voltage will dip briefly, but significantly during those maneuvers.
    The above quote probably should have been added to the first post, sorry. Now that I am thinking about it, maybe the Learn Team should add a section for voltage divider applications, specifically as it applies to the battery packs that are available for the ActivityBot.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-09-23 05:17
     adc_init(21,20,19,18);
    
    This is for the Activity Board, but what is the code for the PropBOE ADC? I want to use a PropBOE setup as a quick way of checking my batteries.

    Ray
  • Hal AlbachHal Albach Posts: 747
    edited 2013-09-23 06:23
    ADC on the two boards are not the same. For starters, on the Activity board the ADC device interface is SPI while on the BOE board it is I2C. At first glance most of the BOE software examples are in SPIN while the Activity Board is in C. OBEX may have what you need if you are going to use SPIN, otherwise if you want to use C you will have to either convert the SPIN programs to C or start from scratch. I believe there is a utility that converts SPIN to C but I am not familiar with its use or how well it does the conversion. Perhaps someone who has used it may be able to guide you.

    The procedure you quoted from Andy pretty well outlines how to make the voltage divider, but it left it to the user to make sure to set PWR switch to position 3 to activate the servo Vin rail. Also, if you did not set the jumper as indicated and left it in the 5v position would explain the reading you were getting.

    Hal
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-09-23 06:46
    I figured out the problem for the voltage reading, my BOEBOT li-ion pack is acting up. I put in a couple of different batteries, and now the readings are correct.

    I wanted to create a C version of MyVolts for the PropBOE, but I noticed at the Learn.com, coverage for the PropBOE is strictly Spin. Maybe it's going to be - Activity Board <-> C, and PropBOE <-> Spin.

    Ray
Sign In or Register to comment.