How To Build a Flashlight With Perfect Modes (picture heavy)

863 posts / 0 new
Last post
bmmeadors
Offline
Last seen: 7 years 5 days ago
Joined: 02/15/2011 - 16:56
Posts: 9
Location: Arkansas

I'm very much interested in this topic, being a Computer Science major and a flashaholic. I'm curious to know if anyone has used this programmer: http://www.solarbotics.com/products/50844/. The price is good. Of course, I would have to get an 8 pin cable for it. It's based on the USBtinyISP, so I would think it would work with the ATINYs. Great work, guys. It's impressive what can be done with a little curiosity and some ingenuity.

Don
Don's picture
Offline
Last seen: 12 months 1 day ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

Welcome to BLF bmmeadors

 

Have a good time here.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

bmmeadors
Offline
Last seen: 7 years 5 days ago
Joined: 02/15/2011 - 16:56
Posts: 9
Location: Arkansas

Thanks, Don. I have viewed many threads on this site. Finally became a member now.

By the way, I found another source for AMTMEL driver boards (supposedly, since they're the same ones as ShiningBeam's). There's a 3 mode 1.4A and a 2.8A version. Craig at IlluminationSupply has them, along with XM-L emitters and various other DIY pars. Already received an XM-L along with an empty P60 module and some teflon coated wire. Great stuff.

http://illuminationsupply.com/mod-parts-c-12.html

I've got two of the 1.4A drivers and an XM-L on the way. Maybe I can order that USB programmer now that I have an excuse. Laughing

JonnyC
JonnyC's picture
Offline
Last seen: 5 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Thanks for the link bmmeadors.  It's good to have another US supplier.

 

So, I'm done programming.  The 8 pin clip is giving out.  After connecting it to a MCU probably 20-30 times, it's falling apart.  I tried fixing it, but there's nothing that can be done now.  Is there any place to get a higher quality clip?  The only other way I can see doing this is soldering 6 tiny wires to the pins on the MCU just for programming, then removing once I have the program I want.  That would be really tedious though.  For now I'm just going to stick with the program that came on the boards to build lights Sad

fishinfool
fishinfool's picture
Offline
Last seen: 2 years 2 months ago
Joined: 03/09/2010 - 00:30
Posts: 4342
Location: Hilo, Hawaii

Aloha and welcome to BLF bmmeadors!

Don wrote:

"But as I said long ago, you are more likely to be killed by a dead fish dropped by a seagull in the Sahara Desert than by a lithium ion

Don
Don's picture
Offline
Last seen: 12 months 1 day ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

JonnyC wrote:

Thanks for the link bmmeadors.  It's good to have another US supplier.

 

So, I'm done programming.  The 8 pin clip is giving out.  After connecting it to a MCU probably 20-30 times, it's falling apart.  I tried fixing it, but there's nothing that can be done now.  Is there any place to get a higher quality clip?  The only other way I can see doing this is soldering 6 tiny wires to the pins on the MCU just for programming, then removing once I have the program I want.  That would be really tedious though.  For now I'm just going to stick with the program that came on the boards to build lights Sad

 

Is this with the chip in the circuit or loose? I suppose the clip is the only way once the chip is soldered down - my first thoughts ran to a ZIF socket. When I have fiddly things like that to repair, I consult my dentist - dental casting resins are amazingly useful. They are not cheap but you don't need a lot.

The people who make false teeth might be worth consulting too - dental technicians they are called here - they are used to fabricating small items with very high precision. And work a lot cheaper than dentists.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

Tido
Offline
Last seen: 3 years 3 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Hi bmmeadors, welcome to the BLF.

I'm currently using the Bus Pirate for programming ATMELs. It's a really handy tool that can do much more than just flash-program MCUs. As for the debugging clip, I use one like this. It may cost twice as much as the cheaper ones, but mine has been in use for a few months now and is still in good shape.

bmmeadors
Offline
Last seen: 7 years 5 days ago
Joined: 02/15/2011 - 16:56
Posts: 9
Location: Arkansas

Tido, that Bus Pirate looks pretty cool. Looks like I'd have to break out an Ubuntu live CD(or other distro) to use it. I used to dual boot with Ubuntu, but I eventually gave up that partition, as I found that I didn't use it very much.

sixty545
Offline
Last seen: 2 hours 50 min ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

Have been thinking a long time of how to make the best mode arragement (for me). The last one I made was 4 lm - 16 lm - 64 lm - 250 lm with memory (XP-G in WF-502B) where modes repeated in ring: verylow -> low -> mid -> high -> verylow etc.

The memory was handy but the number of tabs to reach a certain mode from turn-on of course depended on the memorized mode. The goal is to reach the most used modes with the fewest tabs.

A light with no memory would fullfill that and always have the same number of tabs to reach a certain mode and disco modes could even be added at the end:

low -> mid -> high -> verylow -> strobe -> SOS -> Beacon -> low etc.

For a XM-L light this could be:

32 lm -> 125 lm -> 500 lm -> 4 lm -> strobe -> SOS -> Beacon -> low etc.

I think that 32 lm would be a fine standard level for close use and the light would always start in that level. But for other uses it would be better to start in another level. That gave me the idea to combine the no-memory list with a memory giving this mode array:

last_mode -> low -> mid -> high -> verylow -> strobe -> SOS -> Beacon -> last_mode etc.

When the light is turned on it will start in the memorized mode. One tap wil bring it to low, two taps to mid and so forth. If the last_mode was low, one tap of couse should go to mid but that is easy done in programming.

The memory could kick in after staying a few secs in a mode or 1 sec after switch-off.

 

If memory is made after switch-off it opens up for an alternative arrangement with normal modes in one chain and disco modes in another:

Turn-on, wait 1 sec  -starts in normal modes chain:

          last_mode -> low -> mid -> high -> verylow -> last_mode etc.

Turn-on + fast tab   -goes to Disco modes chain.

          strobe -> SOS -> Beacon -> strobe etc.

 

Now I "only" have to modify Tido's program to test all this.

EDIT: For implementation: Look at post #254

JonnyC
JonnyC's picture
Offline
Last seen: 5 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Just to update you guys, I took your advice and ordered the 3M clip from here...

http://search.digikey.com/scripts/DkSearch/dksus.dll?KeyWords=923655-08-ND

They are only a state away, so it arrived really fast and shipping was cheap.  The clip really locks on to the chip tight, but the contacts just barely didn't reach.  So I had to trim the plastic down a bit, and then it wouldn't stay on Sad  After trimming it down multiple times, I think I have it working.  However, I don't have a working chip anymore to test my latest program.  Hopefully the shipment from Kaidomain will arrive shortly and they will have the Atmel chips.

Tido
Offline
Last seen: 3 years 3 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

...just really busy.

I started at a new job last week and I'm still looking for a flat. So it might take a few weeks before I find time to hack the driver code again.

We apologise for the inconvenience.

Don
Don's picture
Offline
Last seen: 12 months 1 day ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

I'm glad you can find some time to be around here - thanks for all you've contributed here.

 

And good luck with finding a place to live, that is just about my least favourite task.

Hop it doesn't take too long.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

Buwuve
Buwuve's picture
Offline
Last seen: 4 years 5 months ago
Joined: 02/11/2011 - 14:49
Posts: 1975
Location: Germany

ordered: 16 Feb 2011

Recieved 04. March.

 5x 105C ATtiny13A

Light up the darkness.

sixty545
Offline
Last seen: 2 hours 50 min ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)


This is a follow up on post #249.
I finally managed to squeeze the code for my dream light in. The space for code is 1024 bytes and I needed 1070. It finally came down to 1018 bytes mainly by rewriting the delay code and avoid using sleep_ms() and sleep_sec().

What about a light that tells the battery voltage?
It could certainly save a lot of unscrewing the tail cap to check the battery. Well, it is here now.

My wish list was:
1. Most used levels first. No need for programmable.
2. Many modes including flashing modes at the end of menu.
3. Memory, but no tapping through disco modes to get back to the first levels.
4. Battery read-out.
5. Shall decrease output gracefully at about 3.0V (for non protected cells)
6. Beacon mode should be the soft on, soft off type (byte-hungry).

The solutions:
1. Start with 'low' which is 44lm for this XM-L based light. Then higher plus a low-low.

2. Se mode list in point 3.

3. It memorizes a mode when used 2 secs.

[EDIT apr.15-2012] Memory can now be switched off, look here.
At turn-on after being off for more than 1 sec it starts in the memorized mode which alway has the first place in the menu which can be tapped through:

Last_mode ->
 44lm -> 168lm -> 690lm -> 6lm -> strobe -> police strobe -> Beacon -> SOS -> (folds back to 44lm, NOT Last_mode)

By tapping from Last_mode it always go to 44lm*)
*) skips to 168lm if Last_mode was 44lm

4. Battery read-out is build into the Beacon mode. One second after the full power beacon-flash the light makes a number of countable blinks, separated 0,5 second. The level is 1 (1/255 of full power), the lowest possible.
examples: Vb= 4.2V -blinks 12 times
Vb= 3.8V -blinks 8 times
Vb= 3.2V -blinks 2 times
Vb= 3.0V -blinks 0 times
It is very stupid to look into the light to count pulses, the beacon flash each 8 secs is formidable, but using the reflection from close distance from a wall gives an easy count.

5. Output is cut in half in all modes each time battery voltage sinks to 3.0V until only the driver uses (a very little) current. This process can take 2-3 hours and optimizes output.

I have build this into a Solarforce L2 copy with XM-L and driver 105C plus into two WF-502B with XP-G R5 and driver 101-AK.

I'm a little euphoric about that L2 and it shows how far Tido's initiative from nov.2010 can take you.

Don
Don's picture
Offline
Last seen: 12 months 1 day ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

Very nice. And all in 1018 bytes!

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

Subterranean
Offline
Last seen: 10 years 2 months ago
Joined: 03/21/2011 - 01:18
Posts: 4
Location: UK

Hi all, first post here. I was just directed to this post and found it quite an interesting read.

I did the same thing nearly a year back now (doesn't feel that long ago) rewriting the uCs on the 7135 drivers. I am in the position of using various Cree LED emitters of different max current ratings (XRs, XPs, XC-E and hopefully I’ll get my hands on an XM-L soon) always with single Li-Ion voltages (though usually a few cells I've welded in parallel and wrapped, for increased run-time). This meant it was just as efficient to use these linear drivers as making a buck driver, though not as flexible.

I must admit that I found programming PICs in general to be much easier and user friendly than the Atmels. I ended up getting the basic software PWM down to around 22 bytes and the entire program down to around 210 bytes. My uC was independently controlling 2 different LEDs by monitoring 2 input switches, allowing the user to program up to 10 modes per LED. Of course changing this to just one LED and one input would be easy enough.

Of course this was all in assembly which I'm surprised to see has not been used by anyone on this thread. Given how basic the chips are, and how simple the program is it would seem an ideal place to use it.

Personally I do hope the drivers start using PICs again Silly But I have seen that the couple of people who are doing the programming in this thread didn't get on with them so I guess its swings and roundabouts. 

Tido
Offline
Last seen: 3 years 3 months ago
Joined: 05/28/2010 - 15:28
Posts: 189
Location: Berlin, Germany

Actually, I have successfully ported the driver to the PIC12f629, I just didn't have the time to clean up the code enough for a release. I hope I'll come around to it once I'm settled down again.

Don
Don's picture
Offline
Last seen: 12 months 1 day ago
Joined: 01/12/2010 - 16:32
Posts: 6617
Location: Scotland

Welcome to BLF Subterranean.

 

Good to have you here.

 

The numbers from my light tests are always to be found here.

https://spreadsheets.google.com/ccc?key=0ApkFM37n_QnRdDU5MDNzOURjYllmZHI...

fishinfool
fishinfool's picture
Offline
Last seen: 2 years 2 months ago
Joined: 03/09/2010 - 00:30
Posts: 4342
Location: Hilo, Hawaii

Aloha and welcome to BLF Subterranean!

 

Don wrote:

"But as I said long ago, you are more likely to be killed by a dead fish dropped by a seagull in the Sahara Desert than by a lithium ion

cessnapilot
cessnapilot's picture
Offline
Last seen: 4 years 6 months ago
Joined: 02/28/2011 - 22:15
Posts: 159
Location: USA

I have read through most of this thread, but it is packed with somewhat confusing information...can someone give a quick recap of it?

 

What components do I need to order to reprogram my own drivers?

 

PS:  I have never done any programming with code but I am pretty computer savvy and hopefully can figure it out Smile

JonnyC
JonnyC's picture
Offline
Last seen: 5 months 4 weeks ago
Joined: 01/14/2011 - 19:12
Posts: 1148
Location: Green Bay, WI - USA

Hey cessna,

That's a good idea to summarize this thread.  It's always a pain digging through all posts.  So here's my summary of what I have been able to do.

 

Programmer:  USBTinyISP - it's a parts kit, but the assembly is quite easy as long as you have a soldering iron with a small tip and thin solder.

Clip to connect  on the microcontroller:  http://search.digikey.com/scripts/DkSearch/dksus.dll?KeyWords=923655-08-ND - however, you will NEED a ribbon cable to hook this up to the programmer.  I used one from the cheaper clip (blue one) I had which broke, otherwise you can find combo deals on ebay by looking up "SOIC clip", just make sure it's an 8 pin.

AVR Studio if you want to write your own code:  http://www.atmel.com/microsite/avr_studio_5/default.asp 

AVRDUDE program Tutorial for flashing the chip:  http://www.ladyada.net/learn/avr/

 

From there I was able to buy some 7135 based chips with the Attiny13A chips from Deal Extreme or Kaidomain, download Tido's code (which includes a great README and pre-configured builds all set to flash), simplify his code to remove voltage monitoring and implement my own UI (and to understand what it's doing), connect the programmer up to the chip using the 3M SOIC clip, flash it, then solder it up and test it out.

Hopefully that helps?

- Jon

brted
brted's picture
Offline
Last seen: 3 days 4 hours ago
Joined: 01/12/2010 - 19:44
Posts: 2371
Location: Atlanta

Maybe we could write a Wiki for how to do this? I have set up a page and done a rough draft. Since I've never actually gotten this to work (I think I need to buy a new clip, but maybe a new programmer as well) I won't be able to offer a lot of expertise.

Anybody can sign up at Flashlight Wiki for an account and then PM me to activate it so you can actually edit things:

http://flashlight-wiki.com/AVR_Drivers

kingkong
Offline
Last seen: 1 year 6 months ago
Joined: 04/07/2011 - 15:06
Posts: 49
Location: Houston, TX

sixty545,

 

can you share your code?

 

kong.

sixty545
Offline
Last seen: 2 hours 50 min ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

kingkong wrote:

sixty545,

 

can you share your code?

 

kong.

Of course I can share the code. I have DropBox, but have not tried to share files before, so I have to try first.

I use both kinds of memory that Tido's program support, memory after 2 sec on to remember the last used mode, but to distinguish tapping from longer_time_off I use memory_after_off which Tido calls "pin switching" because the function depends upon a capacitor connected to a pin of the MCU. At short "taps" the pin voltage is high, at longer "off" the voltage has bleeded away through a resistor. This function is discussed from post #166 onwards and calls for mounting 3 small components on the driver like this:

The 3 tap-detector components mounted on an AK47. Notice also how I connect the driver to the pill with a piece of multi-strand wire. I can then easily access the component side for re-programming by lifting the driver opposite the wire which is twistable.

I think it should take only a small modification to the program to avoid the additional components and use the 2 sec timing also for tap-detection. Of course the benefit of pin-switching will then be lost. I will try making such a version before sharing so it will take a while. But I will report back here when ready for sharing.

 

[EDIT]

Unfortunately it seems to be quite difficult to avoid having to add the 3 SMD components to the driver as the program code grows to be 48 bytes too big by omitting pin-switching. It think part of the programme has to be written in assembler to fit the available space of 1024 bytes.

For those still interested in my 8 mode driver with special memory and battery read-out I have made a zip-file here.

 

kingkong
Offline
Last seen: 1 year 6 months ago
Joined: 04/07/2011 - 15:06
Posts: 49
Location: Houston, TX

sixty545,

Thanks for sharing your code.  I have an on STK500 dev kit with some spare Atmel 12 and Atmel 13.   I can try to convert the code to assembly.  I will need some help with the electronic..

 

kong.

cessnapilot
cessnapilot's picture
Offline
Last seen: 4 years 6 months ago
Joined: 02/28/2011 - 22:15
Posts: 159
Location: USA

is this clip sufficient? (12 dollars shipped) It looks like it has a nice small head for tight spaces, and it comes with a cable with a 10 pin female plug.

does this programmer look ok? (10 dollars shipped) It has a male 10 pin on the board, and the clip above has a 10 pin female.  That should be a direct plug in right?

So with those 2 components in hand it comes down to software and the knowledge to do the programming? This is exciting!

 

ps great job on getting the wiki started brted!

Subterranean
Offline
Last seen: 10 years 2 months ago
Joined: 03/21/2011 - 01:18
Posts: 4
Location: UK

cessnapilot wrote:

is this clip sufficient? (12 dollars shipped) It looks like it has a nice small head for tight spaces, and it comes with a cable with a 10 pin female plug.

does this programmer look ok? (10 dollars shipped) It has a male 10 pin on the board, and the clip above has a 10 pin female.  That should be a direct plug in right?

Both those will work, they are both the cheapest (and most likely to break quickest) versions, but if you're going to flash a handful of drivers you probably don't need anything more expensive

.
However, it probably won't be a direct connection; you will need to change which pin on the clip each wire from the programmer connects to. To do this, find the pinout of the programmer (all similar AVR programmers will have the same pinout) and match it to the pinout of the attiny13 (and hence the clip). Depending on how the wires are connected to the clip you might need to desolder/solder but someone who’s done this already can better advise.

fishinfool
fishinfool's picture
Offline
Last seen: 2 years 2 months ago
Joined: 03/09/2010 - 00:30
Posts: 4342
Location: Hilo, Hawaii

Aloha and welcome to BLF kingkong! 

 

Don wrote:

"But as I said long ago, you are more likely to be killed by a dead fish dropped by a seagull in the Sahara Desert than by a lithium ion

sixty545
Offline
Last seen: 2 hours 50 min ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

cessnapilot wrote:

is this clip sufficient? (12 dollars shipped) It looks like it has a nice small head for tight spaces, and it comes with a cable with a 10 pin female plug.

does this programmer look ok? (10 dollars shipped) It has a male 10 pin on the board, and the clip above has a 10 pin female.  That should be a direct plug in right?

So with those 2 components in hand it comes down to software and the knowledge to do the programming? This is exciting!

 

ps great job on getting the wiki started brted!

Post #54 can be a big help!

Benik3
Benik3's picture
Offline
Last seen: 7 months 4 weeks ago
Joined: 04/13/2011 - 14:30
Posts: 47
Location: CZ

Hi everybody.

On our czech forum forum.fotonmag.cz we would reprogram this driver: http://www.kaidomain.com/ProductDetails.aspx?ProductId=9906

But, we don´t know if it´s possible and also we don´t have this driver at home, because we don´t know it Sad

And the second thing is, that we don´t know, how to make a program Embarassed But if the ATMEL is some and the connection is some we could use your program.

Do you have someone this driver?

Thanks Smile

Sorry for my English Sealed

Pages