in-flashlight voltage readout stuff, WIP

Here’s another half-started project.


Here is the Eagle BRD file.

As you can see, there are two boards here. They are really standalone boards, but at the moment I’m working on them at the same time. Both boards are 16mm or less in diameter.

The board with the rectangular cutout is an LED board, it holds 4x 0603 or XQE LEDs (oops, I guess those pads on the right prevent XQE for now). The large rectangular cutout and round pads are there with the intention of laying this on top of a “16mm” Noctigon. The LEDs are layed out in end-to-end pairs next to the XM-L emitter. The cutout is a rectangle instead of a square to account for the 0.1in chamfer that the end-mill will leave when cutting the hole.

The other board is simply an STP16CPC26 LED driver all wired up: on the bottom you have the STP16CPC26 itself, the current setting resistor, and pads for Vdd, GND, CLK, SDI, and LE. On the top you have 16 LED outputs (wired to the cathode of the LED). The LED outputs are controlled with a shift register, so this requires 3 pins on the ATtiny13.

So you simply convert whatever you want to display (probably battery voltage) to a 4-bit number in firmware and bit-bang it out to the STP16CPC26. You wire up any number of LEDs from 2-16 to those outputs, skipping spaces evenly.

Here is some code: ~~http://pastebin.com/ndzQqQhP~~

It’s just a function to output a 16-bit value to the shift register. I’m not sure that I’ve got it right, those bitwise operators are tricky for me. As noted in the comments, output maaaay be inverted.

Here is additional code: void shiftOut(uint16_t val){ uint16_t i; for (i = 0; i < 16; i - Pastebin.com. I often create code with type casting errors, so this probably needs at least that much fixed.

The second function allows you to convert an 8-bit number to an output compatible with a strip of 16 LEDs. You’d then plug that into the first function to set the LEDs, followed immediately by pulling the latch pin up and back down.

There’s really a lot that has not been accounted for here. The two things that stick out to me are:

  1. why am I using an arbitrary value of 16 LEDs in the conversion? As long as the output function always outputs 16 there is no problem with doing our conversion based on less LEDs. I suppose that it doesn’t matter. With lots of LEDs (6, 8, 12, 16, etc) you just space them out evenly on the pads. With very small numbers (2, 3, 4) you would want to manually define thresholds for turning them on/off. Clearly thresholds would be handled in a separate function.
  2. I have not created any provisions for bi-color LEDs or LEDs which only turn on as a low battery warning. The current implementation is simply written with the idea of a 0-16 fuel gauge in mind.

I love half started projects. I have about a billion. I think some people here will make good use of this read out device :)