Author Topic: Code to read battery level on Mega168 - BabyOrangutan board - ADC questions  (Read 1618 times)

0 Members and 1 Guest are viewing this topic.

Offline nanobot9000Topic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
I have been building various robots over the years and just discovered this site - it is great!

Background:  I am building a small tracked bot using geared pager motors and the BabyOrangutan controller board from Pololu.  I am using a single 3.7V LiPo battery which is under the recommended 5v, but I have adjusted the board to use the internal 8MHz setting rather than the external 20MHz based on other recommendations and have done this before.  I am also using a solar powered charging circuit to top off the battery when there is sufficient light, but it is not currently integrated into this design.

In a nutshell, I have never written a C-program from scratch and while that is bad and I know I need to try, I am seeking a code example of how to read the battery voltage and use the internal 1.1vref to determine the battery state.  The board has a few LEDs that I can blink if it reaches a certain level, but that is for later.  I read a few posts about ADC on this forum and have looked at the mega168 datasheet, but what I am hoping for is that someone has some actual code that is not pseudo-code, that I could test with this chip/board using the internal reference point preferably if it is standalone as a modular approach seems to work best. 

I know that is a lot to ask, but any and all help is appreciated.

Thanks, Mike

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Look at my $50 Robot tutorial. It has code for both the ATmega8 and ATmega168 (99% compatible). I heavily commented to code so it'll make sense if you read through it.

 


Get Your Ad Here