Building a better bike tail light

you obviously don’t live in Virginia, as that would be a terminable offense in VA: such an action would actually be considered suicide-by-cop

FWIW, I finally got back to the firmware for this light. It has some significant improvements now…

  • Added a battery check mode.
  • The modes are now 5 solid modes, 3 dual beacons, 1 heartbeat beacon, and the battery check. In that order.
  • Mode memory is enabled and working, to make sure the light stays on the same level if power gets briefly interrupted by a bump in the road.
  • Timing (in general) and the moon mode are calibrated better now.
  • Managed to reduce the overall ROM size, so there’s room for more stuff if anyone wants to add anything.

The battery check mode will blink 0 to 5 times, wait a couple seconds, re-check the voltage, then repeat. The blinks represent:

  • 0 blinks: < 3.0V
  • 1 blink: 3.0 - 3.3V
  • 2 blinks: 3.3 - 3.6V
  • 3 blinks: 3.6 - 3.9V
  • 4 blinks: 3.9 - 4.2V
  • 5 blinks: > 4.2V

You can basically think of each blink as being 25% of a full charge. I know li-ion capacity doesn’t correlate with voltage on a linear curve, but at least it gives a decent idea when the battery needs to be charged again.

As always, the latest is available here:

http://bazaar.launchpad.net/~toykeeper/flashlight-firmware/trunk/files/head:/ToyKeeper/tail-light/

Is this for the Atmel tiny13a?

Yes, it’s for the common attiny13 used on many common budget drivers. I’m using a one-sided variety with just two 7135 chips. IIRC, it’s called an “AK-47” driver. I’ve used virtually the same firmware on other attiny13-based drivers though.

glad to see that you're still cracking on with this TK :) Garrybunk referred me back to this thread after talking about some different strobe modes. I have to say I completely forgot about the work you were doing, sorry! I'm starting to read through some different firmwares so I can begin understanding what's going on. I should really go and read the manual and learn it properly, but that's competing with me reading at least 3 textbooks too..

So, I figured out that this is the on-and-flashing part:

while(1) {
        if(mode_idx < SOLID_MODES) {
            sleep_mode();
        } else if (mode_idx < DUAL_BEACON_MODES) {
            for(i=0; i<4; i++) {
                PWM_LVL = modes[mode_idx-SOLID_MODES+2];
                _delay_ms(5);
                PWM_LVL = modes[mode_idx];
                _delay_ms(65);
            }
            _delay_ms(720);
 

How do you adjust how many pulses are in the group? Am I right in understanding that it's a 5ms pulse, 65ms wait, 5ms pulse then 720ms delay before repeating? How do you set the ratio - is that mode_idx-SOLID MODES+2? I'm presuming that you select a mode, then the pulse is that mode + 2 mode levels up? So moon flashing = moon on/ med flash? So I can control the ratio between on and flashing by either specifying how many mode levels up the flash is or what the jumps between the mode levels in the code are? What would I need to do to insert this code into JonnyC's Star momentary? (ie. are there any dependencies I need to worry about).

Sorry for all the Qs, I'm right at the beginning of my understanding and some of these Qs will no doubt look painfully embarrassing in a few weeks/ months :) Thanks!

It pulses four times and then rests…

  • High 5ms
  • Low 65ms
  • High 5ms
  • Low 65ms
  • High 5ms
  • Low 65ms
  • High 5ms
  • Low 65ms
  • Low 720ms

So, the total there is 1000ms, with an average power draw of (( low * 0.98) + (high * 0.02)). If low was 100mA and high was 500mA, this would give an average of 108mA… so just 8mA extra in order to dramatically increase visibility.

By default, it flashes between the specified level and two levels higher. I find that this provides a nice ratio, usually. However, the timings and ratios should be pretty easy to modify just by changing some values in that part of the code.

That is a lot less trivial. It’ll involve making up brand new logical structures to facilitate blinky modes, which STAR normally doesn’t have. I’m not sure off-hand what the best method would be; it probably depends on the other details of the interface you want.

So, what kind of interface and modes do you have in mind?

that's pretty much perfect as far as I can tell! The i=4 is the number of intervals? How would you do a double double pulse? I.e. 5ms pulse>45ms (?) rest>5ms pulse>100ms (?) rest>5ms pulse>45ms rest>5ms pulse> 720ms rest. It's a little more eye catching (I spent a commute chasing after someone with a rear light doing that to find out the brand - Dinotte in this case) without much if any power penalty.

[quote=ToyKeeper] [quote=mattthemuppet] What would I need to do to insert this code into JonnyC's Star momentary? [/quote] That is a lot less trivial. It'll involve making up brand new logical structures to facilitate blinky modes, which STAR normally doesn't have. I'm not sure off-hand what the best method would be; it probably depends on the other details of the interface you want. So, what kind of interface and modes do you have in mind? [/quote]

I understand - I spent some time last night looking at Star mom and it's very different with respect to the modes. For a rear light, all I'm after are:

  • 2 on-and-flashing modes - 1 not too bright for riding with others and as a low voltage option, 1 full brightness for commuting.
  • Momentary button controlled (had a lot of problems with clickies)
  • voltage monitoring and response (go to low mode at ~3.2V, switch off at 3V)
  • no memory (could have it I guess, just can't see the need with 2 modes)
  • press and hold to turn off.
My aims for the front light are a bit more complicated, I need to do a lot more reading about the options first!
thanks!

Just change the logic… as long as there’s space left, you can do anything. Either do two shorter loops with a delay between or hardcode each flash one at a time or check for a specific iteration and add an extra delay, or … whatever.

Seems like that shouldn’t be too hard. I included more modes on mine since it’s also usable as a general-purpose red torch. Five regular brightness levels, three two-level flashers, a beacon, and a battery check mode. My front light is more or less the same, but with some extra blinky modes thrown in for fun since it’s also an EDC light.

I’ve been a bit too busy lately to do more on BLF than answering messages, but hopefully I’ll get some time soon.

no worries TK, there isn't a whole lotta rush and who knows, I may end up being able to figure some of this out myself. Unlikely, but not impossible :) I'm going to keep reading different peoples' code and also start on the manual too, see if that helps.

now that a family member is bicycle commuting, this got to be an important subject to follow. Thanks.

Are you saying that the red XP-E2 can handle a direct drive setup?

I currently use the excellent Bontrager Flare R City rear bike light. However, I want an 18650 or 18350 powered light. Is there a right angle headlamp with a red emitter that can be made to flash in low power and higher power as needed? Did this project ever produce this?

Not sure if you realize that, but you'll be blinding everyone who rides behind you. there is absolutely no reason for such light, tail light is not supposed to illuminate, it only supposed to be seen.

Higher power red rear light in fog is good.

Understood, that is why I have the advanced Flare R City light. A remarkable light. However, the desire for an 18650 light is not power output, (why I asked about low power) but longevity, not having to charge the unit itself, and overall maintenance characteristics.

Are you willing to modify firmware? If so, you can buy a d4w from Hank along with the flashing kit. There is a bike flasher mode in Anduril, you would just need it to alternate brightnesses.

D25LR