Seeedino Stalker v2.1 Reading battery voltage/charge state

I am trying to read the battery voltage and charge state on my new Seeedino Stalker v2.1. I never see the
charge state change and the battery voltage doesn’t make sense. From your documentation you state that the pins are 3.3V. Yet the battery is 3.7V. I assume you must have a resister in the circuit to bring down the battery voltage so it can be read. But, I couldn’t find the proper calculation needed in your documentation. Here is the code and output that I get.

Output:
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE
Battery voltage is 0.66V, ADvalue: 205, Pin#: 21, Charging: TRUE, Charged: TRUE

[code]
const int batteryVoltagePin = A7; // Analog input pin battery voltage is connected to
const int chargedPin = 7; //Digital pin 0 == charged
const int chargingPin = 6; //Digital pin 0 == charging

[code]void setup ()
{
Serial.begin(57600);
}

void loop ()
{
int i = 0;
int charging = 1;
int charged = 1;
float batteryVoltage = 0;
Serial.print("Battery voltage is ");
Serial.print(analogRead(batteryVoltagePin) * 0.00322265625);
Serial.print("V, ADvalue: “);
Serial.print(analogRead(batteryVoltagePin));
Serial.print(”, Pin#: ");
Serial.print(batteryVoltagePin);

charging = digitalRead(chargingPin);
Serial.print(", Charging: ");
if(charging == LOW)
{
   Serial.print("TRUE");
}
else
{
   Serial.print("FALSE");
}

charged = digitalRead(chargedPin);
Serial.print(", Charged: ");
if(charged == LOW)
{
  Serial.print("TRUE");
}
else
{
   Serial.print("FALSE");
}
  
  Serial.println(""); 

delay(1000);

}[/code]

Dear customer,

Although we may not help you at software, but I need to remind you, our Stalker V2.1 haven’t has A7 port.
So try to change to A0 may be work correct.
If you attach your photo here to show up how you connect with, that can let more others help you.
Anyway, thanks you share your code to everybody with this function.

Best regards,

Yuri

Yuri,
According to your documentation on the Wiki for the 2.1 Stalker it does support Analog pin 7. Here is the information from your page.

BAT_READ (Jumper type: 2 pin, Location: Top, Factory state: mounted)
If a jumper is placed on BAT_READ, the Lithium Battery voltage can be read via the analog pin 7 (ADC7) of ATmega328P. This pin is only available on the ATmega328P SMD package which is present on Seeeduino Stalker. (The Dual-Inline Package (DIP) only has analog pins from 0 thru 5.)

In digging through your site I found an example of reading the battery voltage under the 2.0 Stalker page, see seeedstudio.com/wiki/File:St … _Fat16.zip. I am sure that will fix my problem. I suggest you add that link to your 2.1 Stalker page.

Hi,
I am having similar problems. I have a 3.7v LIPO battery connected to my Stalker, and an UartSBee connected to a USB outlet on my PC.

When I move the switch the SBee from 3.3v to 5v, The red CH led comes on the Stalker. And I am hoping that if I wait long enough its will extinguish, and the green OK led will come on, indicating a charged state of the battery (or maybe more accurately “charging cycle completed”).

With the red LED on, I get Charging and Charged both showing TRUE when running the sketch above, so maybe some adjustment is required?

I notice in the circuit diagram, that there are two resistors in series between the battery + and GND. One is 10M ohm (near the battery, and the other is 2M ohm. So I would think that one sixth of the battery voltage is applied to the A to D pin. At the junction of the 10M and 2M resistors are the letters ‘VOL’ and these quite clearly also appear on the ATMEGA ADC pin 22 (ADC 7). So I cannot understand what the message about ‘try ADC 0’ is about. Unless of course the diagram is of a previous version??

Any help ideas would be welcome.

Further to my post above, I have made some progress, which I’ll post here in case anyone’s watching!

  1. I did find that in the sketch above that indeed the battery volatage is measured by A7, and that a " * 6 " added to the factor seemed to give sensable results. In my case 4.12 volts which is the same as measured on a multimeter on the board.

  2. When connected to the USB 5 volts, the red led did come on, and after about an hour the red led extringusished and the green one let. The voltage reading on A7 was still 4.12 (The data sheet for the charging IC saiys it should keep charging until 4.2 volts, but whats .08 of a volt amongst friends.

  3. The get the sketch to produce sensible results I had to invert the sense of the “Charged” output.

  4. As a test I left the stalker running the sketch over night (8 hours) with no USB power and the voltage dropped from 4.12v o 4.06v. The RAW value fell from 212 to 210. (My battery is a 1000mAh, marked as 3.7v). When the USB power was removed the green LED extinuished, but the sketch continued to report “charged”.

When I have more time I would like to run the sletch for several days to discharge the battery further. I will also be trying to recharge the battery with a solar cell attached to the stalker, but thats perhaps another story (thread)

Here’s the output of the modified sketch. (The number at the start of each line is the time in mins from startup)

15 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
30 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
45 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
60 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
75 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
90 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
105 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
120 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
135 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
150 Battery voltage is 4.10V, ADvalue: 212, Pin#: 21, Charging: FALSE, Charged: TRUE
165 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
180 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
195 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
210 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
225 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
240 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
255 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
270 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
285 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
300 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
315 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
330 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
345 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
360 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
375 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
390 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
405 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
420 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
435 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
450 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
465 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
480 Battery voltage is 4.08V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
495 Battery voltage is 4.06V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
510 Battery voltage is 4.06V, ADvalue: 211, Pin#: 21, Charging: FALSE, Charged: TRUE
525 Battery voltage is 4.06V, ADvalue: 210, Pin#: 21, Charging: FALSE, Charged: TRUE
540 Battery voltage is 4.06V, ADvalue: 210, Pin#: 21, Charging: FALSE, Charged: TRUE
555 Battery voltage is 4.06V, ADvalue: 210, Pin#: 21, Charging: FALSE, Charged: TRUE

and here’s the sketch

const int batteryVoltagePin = A7; // Analog input pin battery voltage is connected to
const int chargedPin = 7; //Digital pin 0 == charged
const int chargingPin = 6; //Digital pin 0 == charging
int mins;

void setup ()
{
Serial.begin(57600);
}

void loop ()
{
int i = 0;
int charging = 1;
int charged = 1;
mins = mins +15;
float batteryVoltage = 0;
Serial.print (mins);
Serial.print(" Battery voltage is ");
Serial.print(analogRead(batteryVoltagePin) * 0.00322265625 * 6);
Serial.print("V, ADvalue: “);
Serial.print(analogRead(batteryVoltagePin));
Serial.print(”, Pin#: ");
Serial.print(batteryVoltagePin);

charging = digitalRead(chargingPin);
Serial.print(", Charging: ");
if(charging == LOW)
{
   Serial.print("FALSE");
}
else
{
   Serial.print("TRUE");
}

charged = digitalRead(chargedPin);
Serial.print(", Charged: ");

if(charged == LOW)
{
  Serial.print("TRUE");
}
else
{
   Serial.print("FALSE");
}
  
  Serial.println(""); 

delay(900000);

}

Hi everybody,

Thanks all of you. And the code is great. Appreciated for what you share with us.
Hope that can help more guys for this function.

best regards,

Yuri