Battery level monitoring with an ATTiny85

Various user-contributed guides for software-related things
User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Battery level monitoring with an ATTiny85

Post by Camble » Thu Nov 03, 2016 1:36 pm

GitHub Repo: https://github.com/Camble/RPi-I2C

I thought I'd maybe start a thread to keep track of my progress with my attempts at battery monitoring. This won't be a simple "the battery is too low!" alert, but hardware monitoring using analog pins of an ATTiny85 development board. I bought the male version, so the USB fingers can be removed to save space.

At the moment, I'm at the stage of sending and receiving single bytes of data to the ATTiny. It simply flashes the activity LED and sends the same character back. The plan is to have a script on the Pi send requests to the ATTiny at a pre-set interval, and the ATTiny will respond with the information requested. Initially, this will be battery voltage, but it can be exploited to pull other analog information too.

The reverse is also possible, it's possible to have the ATTiny's settings changed by the Pi. For example; the ATTiny could independently handle a low battery LED, the voltage level stored in a variable. The user would be able to adjust this level, or even change the colour if RGB LED is used.

I do plan to integrate the ATTiny85 chip into a future board, but for the moment, this thread will serve to help anyone who wants to build something similar.

Below is my testing setup. The breadboard is so I can quickly remove the connections to re-flash the chip. The USB connection is just an extension lead and I haven't connected the battery to the ATTiny yet. Also pictured is my Safe Shutdown switch for the BangGood power supply.

Image

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Battery level monitoring with an ATTiny85

Post by sotasystems » Thu Nov 03, 2016 1:45 pm

This a cool idea, I actualy did something similar with an Arduino (ATmega328) in my build

It constantly reads the battery voltage, and when the battery drops to a specific level (in my case 3.54 Volt), a red LED will come on. The user then has around 10-15 minutes of playtime on battery until the battery reaches 3.20 Volts. If the user did not decide to shutdown the system/plug in external power until it reaches 3.20 Volts for some reason, the Arduino will perform a safe shutdown via the Pi's GPIO.
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

Justblair
Posts: 21
Joined: Wed Oct 05, 2016 7:48 am
Location: Glasgow, Scotland
Has thanked: 3 times
Been thanked: 5 times
Contact:

Re: Battery level monitoring with an ATTiny85

Post by Justblair » Fri Nov 04, 2016 7:41 am

Why not have the attiny send keystrokes to the pi when certain voltage levels are detected, then run a background service to listen for and react to the voltage levels?

I was thinking about doing this over the last few days....

Ah holdon, I see you are using the hardware serial for the purpose/

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Battery level monitoring with an ATTiny85

Post by Camble » Fri Nov 04, 2016 7:45 am

@JustBlair Another good idea, and I think my original thought was to connect it via USB. But this way, the Pi is in control and can request the information when it's needed.

Justblair
Posts: 21
Joined: Wed Oct 05, 2016 7:48 am
Location: Glasgow, Scotland
Has thanked: 3 times
Been thanked: 5 times
Contact:

Re: Battery level monitoring with an ATTiny85

Post by Justblair » Sat Nov 05, 2016 3:09 am

Another thought, why not use the analogue input of an arduino (already in use in a lot of builds) to monitor battery voltage?

I know that analogRead is a slow activity, but I doubt it would be slow enough to degrade play.

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Battery level monitoring with an ATTiny85

Post by Camble » Wed Nov 16, 2016 9:18 am

@JustBlair Yes, also entirely possible. My build doesn't have a Teensy though and I wanted to build something separate.

cobramike
Posts: 230
Joined: Sat Oct 29, 2016 12:31 am
Location: Gelderland, Netherlands
Has thanked: 55 times
Been thanked: 60 times

Re: Battery level monitoring with an ATTiny85

Post by cobramike » Mon Nov 21, 2016 2:06 pm

Hi Cable. How is the project going. Do you have screenshots how it looks like.
Whooo Stop befor ask in a post. First use the search or the wiki befor you make a topic.. Just saying.........

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Battery level monitoring with an ATTiny85

Post by Camble » Tue Nov 22, 2016 4:41 am

@cobramike I briefly looked at the linux framebuffer, which can be used to draw an overlay on the screen, but my priority is getting the ATTiny code working.

Currently, the ATTiny reads the battery voltage every second or so and averages the last few readings. I'm also including power management stuff, so the code will watch the power switch and also handle keep-alive during Pi shutdown.

cobramike
Posts: 230
Joined: Sat Oct 29, 2016 12:31 am
Location: Gelderland, Netherlands
Has thanked: 55 times
Been thanked: 60 times

Re: Battery level monitoring with an ATTiny85

Post by cobramike » Tue Nov 22, 2016 5:04 am

Camble wrote:@cobramike I briefly looked at the linux framebuffer, which can be used to draw an overlay on the screen, but my priority is getting the ATTiny code working.

Currently, the ATTiny reads the battery voltage every second or so and averages the last few readings. I'm also including power management stuff, so the code will watch the power switch and also handle keep-alive during Pi shutdown.
Ill keep on the lookout of your progress. Thanks for the info
Whooo Stop befor ask in a post. First use the search or the wiki befor you make a topic.. Just saying.........

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Battery level monitoring with an ATTiny85

Post by Camble » Thu Nov 24, 2016 8:14 am

I've removed the power switch monitoring stuff from the ATTiny85 code, as 6kb isn't a lot to play with for the sketch. As I also have an ATTiny167, I have a separate repo for this, which will handle the power switch and a probably few other things.

The ATTiny85 will just be for adding battery reading and nothing more.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest