Squeezing functionality out of an OLED display

Jeremy Harris

Senior Member
I wanted to build a small, light, combined battery pack and power display for a new folding electric bike I'm building, and though I'd see just how much functionality I could get from a budget 16 x 2 line OLED. The 18M2 used on these nice little displays has four spare pins available, c.0, c.1, c.2 and c.5. I needed to be able to measure current (up to 20 or 30 A), voltage (up to 50V), detect when a button was pressed and control a high power switch to run the bike battery on and off. I also wanted to have a circuit that, when turned off, had zero drain from the battery, not even 1µA.

After much experimentation I managed to get the OLED display (an AXE133Y) to drive everything, and give me a nice bar graph "fuel gauge" display of remaining battery capacity. I needed to make a circuit board to carry the big FET power switches and the additional circuitry to control them, plus a Hall effect current sensor and a 5 V regulator to power the Picaxe.

The box will mount vertically on the handlebar stem, with the display and on/off button on the top. The string loop is connected to a magnet that operates a reed switch; when pulled out it disables the on/off button. The Picaxe can "commit suicide" by turning off its own power supply, either if the button is pressed or if it detects that no current has been drawn for a couple of minutes. Doing this makes sure that the bike can't accidentally be left turned on, draining the battery.

Here are some photos of the semi-finished box, if anyone is interested I can post the schematic and code later. There is a commercial brushless motor controller board under the power switch board, so this box is all that's needed to run the bike and display information on power use and remaining battery capacity.

Front view, showing the lithium batteries for the bike, the interface board with the power switch and sensor to the left and the rear of the OLED display:
Battery - controller - display -  front.JPG

Top view, showing display:
Battery - controller - display -  top panel.JPG
 

jedynakiewicz

Senior Member
A most elegant solution, well-crafted indeed! I would love to see both the schematic and the code when you have time to upload it. I am sure that it would be of great value to see how you achieved such a level of integration into the display driver. Most impressed.
 

jedynakiewicz

Senior Member
Jeremy, your code is most educative; thank you. I was particularly taken with the code for ADC sampling where you even have a small routine to reduce the effect of noise in the system. I also appreciated being able to find my way around the code quite easily because it is well commented. I can feel myself lurching towards my prototyping board and an AXE133Y to have a play...

I was fascinated to see how you drop 50 v to 5v for PICAXE - I had thought that a 7805 might be a little out of its spec and then I saw the BZX79s. One question, if I may... why do you have two BZX79s in series? What is the advantage over one?
 

Jeremy Harris

Senior Member
Thanks again.

I think the sampling code could be tidied up a bit, it sort of evolved as I needed to try and over-sample initially (within the 16 bit limit for the cumulative result before division) then I discovered that running the display with an update every 196mS (which was how long it took to run around the 64 sample loop with a display update each time) was too jittery, hence the second loop that ensures that the display only updates less frequently. The capacity bar graph only updates once every 30 seconds, as it uses the built-in time variable to measure amp seconds used over , using the average current drawn over that 30 second period from quite a lot of individual samples (64 times over-sampling, plus around 160 to 170 summed readings from the number of times around the main over-sampled loop, so there are over 10,000 current readings in each 30 second period).

The reason for two zeners was really just because I needed a bit more power dissipation than a single BZX79 could handle, plus I happened to have several BZX79s available. The maximum current from the +5 V supply is around 40 mA, so each 10V BZX79 is dissipating about 400 mW max, inside the 500 mW spec limit. I wanted to make sure that, even with the battery on charge, the input voltage to the 7805 would stay comfortably inside its maximum rating of 35 V.
 
Top