Early in November we took a look at a one of the best Raspberry Pi laptops we had ever seen, using the shell of a Sony VAIO. Laptops used to be hulking beasts, and that played into [Frank Adams’] hands as he got rid of the motherboard and had enough space to replace it with a Raspberry Pi and a few other support boards. This took advantage of the laptop’s screen, keyboard, LEDs, etc. But what’s a laptop without battery power? [Frank] hadn’t cracked that nut until now.

Adding battery power is trickier that it sounds, but [Frank] managed to get the Raspberry Pi to talk to the original Sony VAIO internal battery. His work on the project is shared, but this part of the story is best found starting on page 29 of his PDF project details.
Using the original battery is a good move since it’s designed to fit and has a charger ready to interface with the port on the laptop case. But these batteries have logic inside them, and there’s the rub. Communications use the 2-wire System Management Bus (SMBus) which is well documented. But the when trying to use the Pi’s I2C [Frank] couldn’t figure out to send a repeated start command.
He ended up writing his own C program that bit-bangs the communications he needed and now has the Pi speaking to the battery and listening to what it hears coming back. Reading through his description of this is fun since he includes his observations from a logic analyzer captures. He suspects an occasional bad read is due to Linux interrupting code execution. He watches for and catches these bad reads in software and can now reliably read all the battery vitals.
The hack leaves him with a system that functions in much the same way the original computer did: plug it in and it charges. He did add some hardware that lets him take a voltage reading from the battery using an ADC on the Teensy that was already present to control the keyboard and case LEDs. This adds a small constant draw on the battery, but for now he doesn’t leave the battery connected when the laptop is not in use.
If you’d like to read our original coverage of this laptop, here it is.
>But the when trying to use the Pi’s I2C [Frank] couldn’t figure out to send a repeated start command.
Blegh. Peripherals. You’d think something like the Raspberry Pi would have this sort of thing worked out, but you never know where you’ll find quirks and small hardware errata. It seems like it’s always the peripherals where those end up.
Hey, does this sound familiar? “Errata: In order to , must be set.”
Huh, it ate my pointy brackets. Well, fill in the blanks: [I2C/SPI/USART] \ [Completely unrelated bit in some random-ass register]
Not to take away from Frank’s work (which is awesome!) but why the hell do we need to go through all of this mess to add batteries with fuel gauges to our hobbiest embedded projects. A raspberry pi would be infinitely more valuable if it included some darn proper power management. I’ve tried every UPS shield and board (sparkfuns lipo babysitter is about as close as it gets) and nothing seems to work. PLEASE PLEASE PLEASE UNTETHER ME FROM THE 5v MARSHMALLOWS AND LET ME READ THE DARN BATTERY STATE FROM THE SOC. /half thought out rant.
Well done… at least now he has working I²C. The I²C master on the Raspberry Pi is an idiosyncratic beast, so I wouldn’t be surprised if the chip isn’t “doing it right”.
Maybe now that he got it to “work”, optimising using the
i2c_gpio
kernel driver might be the next logical step:https://raspberrypi.stackexchange.com/questions/37796/how-to-use-i2c-gpio-with-raspberry-pi