Attiny25/45/85 FW Development Thread

It can be hard to follow incremental threads, so here’s a summary of what the ‘bistro’ code does now. Basically, what’s on the menu so far? These things are already working:

  • Choice of 1 to 8 regular modes, plus an optional moon.
  • Choice of low-to-high or high-to-low order.
  • Mode memory, or not.
  • Reversing via medium-press, or not. (requires OTC)
  • Thermal step-down with an easy self-calibration mode to let each person set their heat threshold. Only works in regular modes though; blinkies are not temperature-regulated.
  • 64 brightness levels available, though they’re only normally seen during thermal step-down.
  • Soft start on regular modes.
  • Hidden modes when medium-press is enabled:
    • Two-speed police-style strobe.
    • Volts+tenths style battery indicator.
    • Bike flasher.
  • Most of the code is abstracted to eventually work on either a single-channel or dual-channel (FET+7135) driver.

It’s not done yet, and I know of at least a few things which need to be fixed (like LVP), but it’s getting there. I’m basically putting in as much as I can fit in 2048 bytes. Hopefully it can cover most people’s needs for a clicky-switch light.

Sounds pretty fabulous

These are toggled through the config mode? Same 15 fast click to enter config as blf-a6?

Yes, same method for entering config mode. Fast-tap anywhere between 15 and 30 times (until it stops lighting up) then leave it on.

The config mode makes the timing and counting a little easier now though. Instead of “blink, blink, pause…” for each option it now blinks a number then kind of “buzzes” for a bit to show where the click window is. Click during the “buzz”.

Before:

  1. blink, blink, pause
  2. blink, blink, pause
  3. exit

After:

  1. blink buzz, pause
  2. bl-blink buzz, pause
  3. bl-bl-blink buzz, pause
  4. bl-bl-bl-blink buzz, pause
  5. bl-bl-bl-bl-blink buzz, pause
  6. exit

Some of these options invoke a special secondary mode. Like, to select a mode group, it will go into a beacon-like mode where it’ll slowly blink 8 times then pause, then repeat. Turn the light off after N blinks if you want mode group number N. Or, for the thermal calibration, it’ll turn on in turbo and wait for you to turn the light off to set the maximum allowed temperature.

Eventually I’ll try to make a diagram again, but I haven’t yet.

Bistro revision 185 won’t build for me.

I did try out r175 but only briefly. I’ve been sick and had to work up energy just to download, build, flash. :Sp Also I didn’t / don’t see tk-random.h in the repository so I removed random_strobe.

Oops, I completely forgot to add the random header. Fixed.

About the warning, it’s not a fatal error, is it? For me, it doesn’t prevent gcc from compiling. In any case, adding the missing ‘const’ fixed it, and I re-pushed the changes.

You’re right, it doesn’t appear fatal. :zipper_mouth_face:

I finally put one of these drivers into an actual light and did some temperature testing.

At first I nearly destroyed an LED trying to set a heat limit, since apparently the MCPCB was floating instead of having good contact with the pill. Oops. At least the emitter still works, though moon is much lower than it used to be and there are some tint irregularities.

After fixing that, I’m finding that the pill-to-MCU thermal lag makes things difficult. When setting a threshold, the MCU may not be as warm (yet) as it should be. Then when stepping down later, it can sometimes step down much farther than necessary and then take a long time to come back up. And after it comes back up, it may not go as high as it should because the threshold is too low.

… though on a second test (I left it on turbo longer during calibration), it behaves much closer to how it probably should.

It may be because I’ve got it in a big copper pill, and maybe it would work better on a smaller light. But so far, although it works, it doesn’t work as well as I had hoped. And I may need to add a special state transition to bump it back up to the original level instead of short-tap taking it to the next level.

I ditched my experiments with a temperature controlled mode. If the temperature rises above the threshold I just call the same critical routine as critical voltage and put the light in critical mode (either off or very low output depending on setting). The user has to manually switch modes or restart the light to get out of critical mode, which of coarse will only work if the temperature is lower.

I found that the different heat lag characteristics in different lights made it too much of a hassle to make a generic routine for all lights that wasn’t annoying.

After tweaking it until my battery got too low to heat the light up, I think I might have finally eliminated the thermal “bounce” effect (repeatedly over-shooting the target then rebounding).

… maybe.

I’ll find out tomorrow when the cell is recharged.

The thermal controls might actually need to be adjusted according to the physical host the driver is in, to account for varying amounts of thermal lag. It’ll be interesting to move the driver to a smaller host after I’ve got it working right, to see if it still works.

There’s also now an option to turn off thermal regulation. Just tap the button during the first second of its calibration mode, and it’ll calibrate itself to 255 (hot enough to cook pizza, I think).

For those that are interested in using it, could you add a build time option for an external thermistor to ground (as the temp increases voltage would drop on the attiny pin) instead of using the internal sensor? Attaching a thermistor to the pill with thermal compound should provide less heat lag.

Sure, but I don’t have anything like that to test with so I can’t guarantee it’ll work. :slight_smile:

Do you know what changes the code would need? I suspect that the only thing which would need to be changed is the ADC_on_temperature() function in tk-voltage.h, to tell it to use a pin instead of the built-in channel. Or possibly just the definition of TEMP_CHANNEL in tk-attiny.h, where the rest of the driver layout is defined.

(I know, the naming schemes there suck… needs to be renamed better)

Oh, drat. I just realized this needs a slightly deeper change. The built-in sensor rises with temperature, but you say the thermistor value drops with temperature? I bet that could be worked around with a one-line change somewhere… like adding “temp = 255 - temp;” just before the end of get_temperature(). It’d be easier than swapping all the <s and >s, at least.

The thermal lag, etc is not a problem. The things do not heat up fast enough to a level where it causes problems. If you are worried, you can adjust the trip point down a little to compensate for the lag/lack of direct thermal coupling, etc. Besides, a proper thermistor circuit is MUCH more complicated than just hooking the thermistor to ground and relying on the internal pullup (or an external resistor) to drive the thermistor.

Here is my guess. Hoping you could tell me if I’ve missed anything. Well, besides the change needed since the pin voltage would drop with increasing temp. :~

tk-attiny.h:
#define TEMP_CHANNEL PB4

Plus add another digital input disable like on otc pin and voltage pin
#define TEMP_DIDR ADC4D // Digital input disable bit corresponding with PB4

tk-voltage.h ,
#ifdef TEMPERATURE_MON :

You already have this waiting
//DIDR0 |= (1 << TEMP_DIDR);

Yeah… I originally tried to set DIDR, but the compiler didn’t recognize any of the symbols I used so I suspect it might not be relevant for the internal sensor. TBH, I’m not 100% sure I’m doing it right… but it does at least work. :slight_smile:

It should be straightforward for a pin-based sensor, if I look up the symbols it uses for the lone unused pin. It’s probably the same as setting up voltage or OTC, only with a different pin.

Just checked, looks like it is ADC2D for PB4.

#define TEMP_DIDR ADC2D // Digital input disable bit corresponding with PB4

Bistro is fabulous. Using it on a tiny85.

I hope you’re feeling better.

Also, you’re probably the first person to try bistro. Detailed feedback would be helpful. :slight_smile:

It’s not really made for my personal use; I’d hardcode everything if it was for me, and put in a lot more blinkies. Bistro is more about making things configurable enough to cover most people’s preferences without reflashing. The initial setup may be a little obnoxious, but hopefully it only needs to happen once.

BTW, I’m trying to decide how to use the remaining space. One option is extra blinkies, like a stop-motion party strobe or a smooth pulse beacon. Another option is adding a factory reset config option. Another option is possibly a timer to shut off the light after a while (or maybe ramp it down gradually then turn it off). Or maybe other stuff. Thoughts?

Thanks. Still holding on. :ghost:

I would have tried it a few days sooner but I had an odd problem at first. It was freaking out, changing brightness modes randomly, no response to clicks. It was most odd in that reflashing didn’t help and even my v177 bistro.hex (which had been working fine during a brief test the other day) was freaking out the same. Went back to blf-a6 and the driver worked fine.

Haven’t used all the options much yet. The configuration method (blink current option then stutter) does work nice. And I would think click off during stutter will be easier to understand for people. Imo the stutter brightness seemed a bit too low.

Code wise, that you’ve simplified how hidden modes are specified is really great. I could see a lot of people getting a bit stuck there.

I like the idea of a factory reset option.