Pages: [1]   Go Down
Author Topic: SMBus Laptop Battery "Hacker" with phi_prompt LCD user interface  (Read 4939 times)
0 Members and 2 Guests are viewing this topic.
Fresno, CA, USA
Offline Offline
Full Member
***
Karma: 1
Posts: 153
Arduino rocks (literally, with a WaveShield!)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"Hack" a laptop battery, see what's going on in its head. Send commands to reset and change values, read the voltage, temperature, charge rate, anything the controller can report. And more. With the awesome flexibility of phi_prompt, this little program has a nice menu-based UI that scales to whatever type of LCD you happen to have (I can only imagine how it looks on 20x4)! Plus, if you have a battery whose controller isn't supported yet (I only have bq2040 support embedded, but it's pretty easy to add a whole new command library that you can select from the menus).

Menus:
  • Setup
    • Test SMBus - checks for proper connection and response from the selected address
    • Scan SMBus - scans all usable SMBus addresses and displays the devices that respond to their address
    • Enter Address - directly enter a binary address to contact on SMBus for all functions
    • Command Set - change the command set that's used for built-in functions in Read Info and Single Command (only one is included, for the bq2040, but more can be easily added)
  • Read Info
    • Battery ID - displays manufacturer, model, chemistry info
    • Charge Data - displayes voltage, amps, percent charge, and temperature twice a second
    • Statistics - Manufacturing date and cycle count
  • Control
    • Single Command - displays a full, labeled list of all known commands within the command set - select one, and it'll show you the formatted result (volts, amps, percent, string, hex, etc).
    • Write Word - modify a value on the battery's controller, if it can be modified. Many parameters, like the serial number, cycle count, max charge, etc., can be written by referencing the chip's datasheet. Most changes are temporary, but should last long enough to put it back into a PC and see your changed values (like modifying the string "Dell" into "Hell" for kicks).
    • Read Word - reads a raw hex value from the controller.
    • Read Block - reads a text string onto the display, if it's a proper block value.

The code is pretty huge, compiles to 19450 bytes (obviously only compatible with 328p's). Strings for the commands account for about 580 bytes of it, the rest is pretty much code and libraries.

It makes use of the phi_prompt library by liudr (primarily), as well as I2C Master to more accurately harness the power of the ATMega's TWI interface to emulate SMBus instead of true I2C (repeated starts, commands, etc). It works a treat!

Configure your LCD and button arrangement by reading over the top of the file (all neatly consolidated for semi-readability), then upload away!

Planning on doing some kinda video soon with this thing, but meanwhile, here are some teaser pics. smiley-wink


And the code is attached! smiley

edit: Ugh, it's amazing how much trouble a "<" where a "<=" should go can cause. Quick fix for selecting command set. =P

edit: Updated with histogram on charge data.

* SMBusBattery_Phi.zip (10.42 KB - downloaded 199 times.)
« Last Edit: June 03, 2011, 07:45:58 pm by FalconFour » Logged

Fresno, CA, USA
Offline Offline
Full Member
***
Karma: 1
Posts: 153
Arduino rocks (literally, with a WaveShield!)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Little update... even though nobody's even downloaded it yet... xD

Charge data view now only updates the screen when the values change (still polls every 500ms). It also creates a histogram next to the values on the screen using 2 LCD characters for each value (10 history values total), and the range is set by the peak values (highest and lowest, starts about in the center). Except for voltage, it reads that from the battery: peak is charging voltage+0.3v, low is EDVF (End of Discharge Voltage, Final = battery usually cuts power to the PC).



(hey, now that would be a useful library to have!)

Now... on with making musical relays! smiley-grin
Logged

Central MN, USA
Online Online
Tesla Member
***
Karma: 65
Posts: 6904
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is very nice! I recognize a few features of my phi_prompt library. Can you upload a video on youtube? I'll read your code when I get back home  smiley-grin

Typing up the last few pages of the phi_prompt documentation in a hotel now.
Logged


Fresno, CA, USA
Offline Offline
Full Member
***
Karma: 1
Posts: 153
Arduino rocks (literally, with a WaveShield!)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Aye, I've got the tripod all set up, and in fact I even finished up another quirkly little project (musical relays) after setting up the tripod and all. Silliness. I guess I still haven't done a video of this because it's harder to capture the function of the program in an interesting way on camera... whereas, hell, just go watch the musical relays video! xD It's so catchy from the first click... this is more, "umm, that's nice and all" kinda thing. I imagine more people will get here via Google than anything, haha... it's sad just how little information there is out there about interfacing with laptop batteries. None, to be exact... none at least that's not for manufacturers, etc. I'm sure this will come up pretty often for people smiley-wink

Still finding bugs in the software, though... I've got like 5 batteries that I can talk to with this thing, 3 that won't, and each of those 5 has revealed another function that's not quite working as intended. SOOOO much trouble working with datatypes and bits... le ugh. I also found out that ALL laptop "smart batteries" (i.e.: all batteries) are compatible with this protocol, so this is a much more useful tool than I originally imagined. It's called the "Smart Battery Specification", and it defines all those commands I built into the program. So I might be able to clean it up even more... getting rid of some of the redundant features (like multiple command sets, when there's only one), and adding more (like using that spec to verify communication, parse a bit field, etc). Augh... I almost think I need to waste my time on more useful endeavors =P
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome!

What's the status on this project?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone !
I have question that is: using the i2cmaster library, i can not write anything ti bq20z95 (using "i2c_smbus_write_word" function) however I can read from bq20z95. I think that it relevants to security mode of bq20z95, can any one tell me the problem ?
Thanks in advanced !
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know that, we should need "unsealed key", however, this key of every laptop's battery are different, can anyone tell me how to restart or where to find the key ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I was looking for a way to charge a lenovo's battery with a diy charger when I found your job. It's amazing and I would love to give it a try but when I tried to compile it I have had several issues due to libraries being modified over the time
My biggest issue is with the lcd_reinit_phi() function since compiler will fail to compile there.
I was wondering if you could please post the versions of the libraries and IDE you used for your project since phi_  libraries have been updated and modified over the years (to the point that phi_buttons no longer exists).
considering the file extension of your code i am trying to compile with arduino IDE 0023 since 1.0 and so would probably give even more problems compiling...

Thank you so much, and nice work! smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello , i have problem with i2c master library
Code:









I2C\twimaster.c.o: In function `i2c_init':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:31: multiple definition of `i2c_init'
I2C\i2cmaster.S.o:(.text+0x10): first defined here
I2C\twimaster.c.o: In function `i2c_start':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:42: multiple definition of `i2c_start'
I2C\i2cmaster.S.o:(.text+0x1a): first defined here
I2C\twimaster.c.o: In function `i2c_start_wait':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:78: multiple definition of `i2c_start_wait'
I2C\i2cmaster.S.o:(.text+0x36): first defined here
I2C\twimaster.c.o: In function `i2c_rep_start':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:130: multiple definition of `i2c_rep_start'
I2C\i2cmaster.S.o:(.text+0x22): first defined here
I2C\twimaster.c.o: In function `i2c_stop':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:141: multiple definition of `i2c_stop'
I2C\i2cmaster.S.o:(.text+0x4a): first defined here
I2C\twimaster.c.o: In function `i2c_write':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:161: multiple definition of `i2c_write'
I2C\i2cmaster.S.o:(.text+0x5a): first defined here
I2C\twimaster.c.o: In function `i2c_readAck':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:182: multiple definition of `i2c_readAck'
I2C\i2cmaster.S.o:(.text+0x96): first defined here
I2C\twimaster.c.o: In function `i2c_readNak':
C:\Users\ugur\Documents\Arduino\libraries\I2C/twimaster.c:197: multiple definition of `i2c_readNak'
I2C\i2cmaster.S.o:(.text+0x92): first defined here

Where is the problem ?
i need this program so much. i am trying to fix all problems . please help me
Logged

Central MN, USA
Online Online
Tesla Member
***
Karma: 65
Posts: 6904
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How did you install the library? Where are the library files?
Logged


Pages: [1]   Go Up
Jump to: