Trying to read battery level

Ringo setup, hardware, basic programming. User to user support.
AngoLito
Posts: 5
Joined: Sat May 21, 2016 8:09 pm

Trying to read battery level

Postby AngoLito » Sat May 21, 2016 8:37 pm

Hi!

Please, there are any way to get battery level?

I'm trying to read and show charge by changing color of NeoPixel 3:

(bat_level values on sketch are invented; just for testing...)

Code: Select all

case 16:                   // plum geek button for battery measurement
         PlayAck();
         MotorCapBattVolts = 1;
         int bat_level;
         bat_level = (analogRead(A0));
         Serial.print ("Batería = ");
         Serial.println (bat_level);
         if (bat_level>1000) {
         SetPixelRGB( 3, 0, 0, 200);
         goto fin;
         }
         if (bat_level>800) {
         SetPixelRGB( 3, 0, 200, 0);
         goto fin;
         }
         if (bat_level>600) {
         SetPixelRGB( 3, 200, 200, 0);
         goto fin;
         }
         else (SetPixelRGB( 3, 200, 0, 0));
         fin:
         delay (250);
         OffPixels();
         MotorCapBattVolts = 0;
         PlayAck();         
         RxIRRestart(4);
         break;


I'm reading every time 1022, 1023 values

R55 is missing; maybe it will be necessary to read a lower level than power voltage?
I hear and I forget. I see and I remember. I do and I understand (Confucius)

Kevin
Posts: 181
Joined: Tue Jul 28, 2015 12:56 am

Re: Trying to read battery level

Postby Kevin » Sat May 28, 2016 3:27 pm

The BattVolts line was intended to provide a warning before the battery reach it's cut off around 3.2 volts (it can go lower, but that's when the volt monitor switch cuts out) and not so much of a running voltage monitor - but it certainly could be used for that. I can't remember why R55 was never populated. With all the time I spent going over every detail of the Ringo hardware I'm can't remember the reasoning for this.

Because the Vcc to the processor is 3.5v, this battery voltage is measured in reference to the 3.5. If it's above, it's going to read high numbers. The R55 pad was added to bring this down as you suggest, but I see in all the schematics that it is listed as non-populated. If a resistor is added for R55 to create a divider off the 27k R50, it would be readable. Any divider that would bring 4.2 volts down to below 3.5 volts and you would be able to have a useful reading.

I'm glad you pointed this out. Don't know how we missed this all this time.

Thanks,
-Kevin

AngoLito
Posts: 5
Joined: Sat May 21, 2016 8:09 pm

Re: Trying to read battery level

Postby AngoLito » Mon May 30, 2016 8:39 pm

Hi Kevin!

Thank you very much for your answer and info; i've add a 47KOhm on R55 and it works. But first code shared here was wrong... :o
I had a big mistake attempting to set MotorCapBattVolts to 1 (line 2 of code); MotorCapsBattVolts defines the pin number of ADC!! (0 for Arduino A0) :oops:

Source_Select is line to control U8 digital switch; yes...looking schematics Is easy to understand... ;)

Now, I can measure Batt voltage; simple battery indicator is easy to implement. When I have some more time to test battery levels, I will share code


Please Kevin, let me tell you something: scanning the electronic scheme I was pleasantly surprised how tremendously well thought are electronic design.
During KS campaign I did not think it was so well made.

Congratulations

Best regards...
I hear and I forget. I see and I remember. I do and I understand (Confucius)

AngoLito
Posts: 5
Joined: Sat May 21, 2016 8:09 pm

Re: Trying to read battery level

Postby AngoLito » Sat Jun 04, 2016 8:02 pm

Hi,

I already have finished a simple (but useful) battery indicator :)
Correct code is:

Code: Select all

// ---------------------------------------------------------------------------------------------------------
//  IMPORTANT: THIS CODE REQUIRES TO SOLDER R55 47KOhm SMD 0603 or 0402 package
// ----------------------------------------------------------------------------------------------------------
// Blue color     = full charge
// Green color   = good charge
// Yellow color  = medium charge
// Red color      = poor charge
//
// Angolito - Luanda, May 2016

void read_batt() {
  digitalWrite (Source_Select, HIGH);
  long bat_level=0;
  for (byte i=0; i<10; i++) {     //Take 10 measurements
    PlayChirp(250+(80*i),50);
    bat_level += (analogRead(A0));
    delay (8);
  }
  bat_level /= 10;
  PlayChirp(0,0);
    Serial.print ("Batt. raw = ");
    Serial.println (bat_level);
   
  //Batt values can be ajusted for each Ringo_depending tolerance or new R55 aded, R50 and cuttoff level of U11
  //In my Ringo U11 level is 3,25V to auto power Off and 3,35V minimum to power On
  //Battery volts = (ADC(0)_value*ADC_Ref)/ADC_resolution*((R50+R55)/R55)
  //Battery volts = (bat_level*3,5)/1024*((27000+47000)/47000))
  //Battery fully charged = 4,21V(782 value), 4,17V(775) after unplug charger for short time
  //Auto off function (U11) = 3,25V(604 value)
 
 
  if (bat_level>755) SetPixelRGB(3,0,0,100);         // BLUE, full charge batt condition (>4,06V)
    else if (bat_level>710) SetPixelRGB(3,0,100,0);  // GREEN, high charge batt condition (3,82 ... 4,06V)
    else if (bat_level>650) SetPixelRGB(3,100,80,0); // YELLOW, medium charge batt condition (3,50V ... 3,82V)
    else (SetPixelRGB(3,100,0,0));                   // RED, poor charge batt condition (<3,50V)
    delay (250);
    OffPixels();
    digitalWrite (Source_Select, LOW);
    RxIRRestart(4);
}


I have shared my particular version of Ringo_Preloaded_Behaviors_V06_ReadBatt with this Battery read function implemented on PlumGeek IR button :geek: and some minor modifications...

Please, consult CODE SHARE in this forum; thanks for reading... ;)

AngoLito
I hear and I forget. I see and I remember. I do and I understand (Confucius)

KSenijawib
Posts: 4
Joined: Tue Sep 11, 2018 3:44 pm
Location: Czech
Contact:

Trying to read battery level

Postby KSenijawib » Mon Sep 24, 2018 3:38 pm

Hi,
which are the units that apeears on the .txt file in the channel of the battery? I mean, the column that represents the battery level channel 6 in my case is a number around 580 or 570 that represents the battery level of charge, isnt? How can i translate this number into voltage units?
Thanks
[url="http://hd-wallpapersfd.info/category/fantasy/"]hd-wallpapersfd.info[/url]

Kevin
Posts: 181
Joined: Tue Jul 28, 2015 12:56 am

Re: Trying to read battery level

Postby Kevin » Tue Oct 02, 2018 9:19 pm

I can't remember the units of the ADC, it should be whatever is standard for Arduino. The processor runs on 3.5 volts, so readings will be referenced from there. Going from memory here, I think max range of that ADC is 1024 at 3.5 volts. The main reason for that battery read line is to tell when battery voltage begins to drop below 3.5 volts. Normally the battery is 3.7 to 4.2, which is above the readable range.

On the original Ringo1 robot (the one with the ribbon cable to the programmer) you need to set Source_Select to HIGH, otherwise it is going to read the voltage of the motor capacitors (which after we actually made the robots we realized we didn't need because it is generally stable). This Source_Select is the same line that selects between the ambient light sensors and the bottom light sensors - so just set the robot to read the ambient sensors, then you can read the ADC on this channel (ADC0) to read the battery voltage.

On the Ringo2 robot, we got rid of the source select for the battery/motor. It now always reads the battery, so there's no need to care what the Source_Select is set to, since we don't need the Motor_Cap reading for anything.

Let me know if that helps.

Thanks,
-Kevin


Who is online

Users browsing this forum: No registered users and 2 guests