Guide: how to flash ATtiny13a based drivers (NANJG, QLITE, etc.) with custom firmware

269 posts / 0 new
Last post

Pages

Hoop
Hoop's picture
Offline
Last seen: 5 days 13 hours ago
Joined: 12/20/2012 - 05:33
Posts: 744
Location: Spokane, WA
Guide: how to flash ATtiny13a based drivers (NANJG, QLITE, etc.) with custom firmware

This is a short “quickstart” guide on how to flash drivers that use the ATtiny13a MCU such as Qlite, AK-47, 105a/c/d, etc. Flashing drivers that have an ATtiny25/45/85 is similar but the “fuses” and firmware will be specific to the MCU being used. Achieve success with the ATtiny13a and work up from there.

References and relevant links:
http://flashlightwiki.com/AVR_Drivers
USBASP V2.0 user guide
ATtiny13a datasheet
Flashlight Firmware Repository by ToyKeeper
Attiny25/45/85 FW Development Thread
BLF A6 FET+7135 Light Troubleshooting and Mod thread
STAR Firmware by JonnyC – Source Code and Explanation
howto: Use Atmel AVR Studio 5 to make a .hex file
howto: flash ATtiny with AVRDude and command prompt

Required hardware:
USBasp V2.0 programmer (ebay, fasttech)
Pomona 5250 SOIC clip (Digi-Key) (Cheaper alternative. See post #167)
40-pin Splittable Ribbon Cable (20cm) (FastTech)
USB extension cable (optional but helpful) (EBAY)

Required software:
Atmel Studio
AVR Tools (download page)
USBasp driver

THE PROCESS:

Step 1) Wire the Pomona 5250 SOIC clip and USBASP V2.0 properly:
Here’s a “coloring by numbers example.” Put the wires straight across like this:

The USBasp V2.0 should correspondingly be wired like so:

What these wires are, functionally, is detailed on the flashlight wiki and in the USBasp V2.0 users guide.

1) MOSI
2) VCC
3) GND
4) TCK
5) RESET
6) RXD
7) SCK
8) GND
9) MISO
10) GROUND

The pins of the ATMEL ATtiny13A chip itself on the driver are as follows:
1) RESET
2) INP
3) INP
4) GROUND
5) MOSI
6) MISO
7) SCK
8) VCC

(Image credit: flashlightwiki.com)

Step 2) Install USBasp V2.0 driver:
Available here. If you have trouble with installation, refer to the USBasp V2.0 user guide.
Extract the zip contents to a folder on the desktop. Plug the USBasp device into your computer. It should fail to install properly on its own. In Windows, bring up the device manager. You’ll see the USBasp device with a triangle notation. Right click on it, click update driver software, and then select browse for the driver manually. Select the root folder on your desktop where you put the .zip contents. It should then install without any issue.

Step 3) Install the necessary software:
Install AVR Tools.
Install Atmel Studio.

Step 4) Acquire firmware:
ToyKeeper has created the flashlight firmware repository where pretty much all relevant firmware is located and kept current. Refer to the INDEX to see descriptions of most of the available firmwares, though not all of the firmwares in the repository are listed in the index; there are a few hidden gems in there. Firmwares are grouped into folders by author, then by firmware title. Refer to the META files for information. Note that not all firmware in the repository is for the ATtiny13a.

Most of the custom firmwares come as a .c file, which can be opened with wordpad or Atmel Studio and read as text so that we may edit the code. Ultimately we need a .hex file to load onto our driver, which is not human readable.

Step 5) Flash the driver:
After the desired edits have been made to the code, use Atmel Studio to convert the .c file into .hex. Comfychair has written an excellent guide which details the process HERE.

So now that we have a .hex file we are ready to load it on the driver. Create a folder on the C drive and call it avrusb. This is the working directory we will read from and write to during the driver flashing process. This is where the .hex file we obtained should be put and where we will store and backup driver related files as well.

Have your USBasp plugged in and the Pomona SOIC clip connected to the driver. Connect the SOIC clip so that pin 10 (GND) is connected to pin 4 (GND) of the ATtiny13A according to the illustrations above. Just to note, it shouldn’t matter if you have the jumper on the USBasp at 3.3V or 5V, but I recommend 5V. The ATtiny13A’s Operating Voltage range is 1.8 – 5.5V.

Open the start menu and navigate to MHV AVR Tools folder. Click MHV AVR Shell. This gives us the cmd window in which we will execute commands to write to the ATtiny13A. (Optional: WarHawk-AVG has written a nice guide on a process in which a .bat file is created and commands are executed by means of it.)

The command: avrdude -p t13 -c usbasp -n is a test command and will let you know if the chip is wired correctly.
If you get the “initialization failed” message, you aren’t getting a good connection.

The command: avrdude -p t13 -c usbasp -u -e will erase the contents of the chip so that it can be re-written to.

Now that the chip is empty it is ready to be flashed with fresh firmware. Change the “current directory” by executing cd C:\avrusb so that AVRdude can find the file.

Finally, flash the driver with the new firmware: (change the star.hex part to whatever you named your .hex file)

avrdude -p t13 -c usbasp -u -Uflash:w:star.hex:a -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m
Be mindful of the value of the fuses; they may change from firmware to firmware. In the above example, the “low fuse” is 0×75 and the “high fuse” is 0xff. Generally all firmwares will state the proper fuse values in the .c file.

Commands are case sensitive. The functions of the commands (-e, -p, -u, -U, etc.) are explained in detail in the Option Descriptions section of the AVRdude users manual.

Know that it is also possible to download the settings and firmware from the driver and dump them into the ‘current directory’ with the command:

avrdude -p t13 -c usbasp -u -Uflash:r:flash-dump.hex:i -Ueeprom:r:eeprom-dump.hex:i -Ulfuse:r:lfuse-dump.hex:i -Uhfuse:r:hfuse-dump.hex:i
This reportedly does not work to salvage the factory code, only code you had previously written to the driver that you wish to extract and save. This section of the wiki has more about this command.
Edited by: Hoop on 06/21/2016 - 21:12
Hoop
Hoop's picture
Offline
Last seen: 5 days 13 hours ago
Joined: 12/20/2012 - 05:33
Posts: 744
Location: Spokane, WA

reserved

koyotee
koyotee's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 11/22/2012 - 11:12
Posts: 1630
Location: Slovenia

Thanks for puting this together!

Finaly, proud owner of a Powerex Maha mh c-9000 for my Eneloops:)

MRsDNF
MRsDNF's picture
Offline
Last seen: 3 hours 53 min ago
Joined: 12/22/2011 - 21:18
Posts: 10941
Location: A light beam away from the missus in the land of Aus.

+ 1 Hoop. Thanks.

My current and or voltage measurements are only relevent to anything that I measure.

Budget light hobby proudly sponsored by my Mastercard and unknowingly paid for by a hard working wife. 

djozz said "it came with chinese lettering that is chinese to me".

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

djozz
djozz's picture
Online
Last seen: 7 min 50 sec ago
Joined: 09/07/2012 - 17:04
Posts: 10071
Location: Amsterdam

That looks very well written, thanks to this more folks will be encouraged to flash their own MCU's.

(not me, I'm scared of computer programs)

DanielM
DanielM's picture
Offline
Last seen: 3 days 8 hours ago
Joined: 05/09/2014 - 01:31
Posts: 1804
Location: Romania

Thanks a lot Hoop, I have all the hardware and software ready, all I need is courage Big Smile . Can I flash a Nanjg105/101 or does it have to be a Qlite?

Old-Lumens wrote:
I love modding, but I don't have much use at all for flashlights in general.
NightSpy
NightSpy's picture
Offline
Last seen: 2 months 4 weeks ago
Joined: 08/30/2011 - 18:24
Posts: 794

(subscribed)

RMM
RMM's picture
Offline
Last seen: 13 hours 2 min ago
Joined: 07/23/2013 - 13:47
Posts: 3895
Location: USA

DanielM wrote:
Thanks a lot Hoop, I have all the hardware and software ready, all I need is courage Big Smile . Can I flash a Nanjg105/101 or does it have to be a Qlite?

Any driver with the attiny13a MCU will work.

 

@OP: Thank you for posting this!

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

Hoop
Hoop's picture
Offline
Last seen: 5 days 13 hours ago
Joined: 12/20/2012 - 05:33
Posts: 744
Location: Spokane, WA

You’re all welcome! Big thanks to all those BLF’ers whose posts made it possible for me to figure this out! Party And for the efforts of the likes of DrJones, JonnyC, Tido, and others for creating and sharing their code!

djozz wrote:
(not me, I’m scared of computer programs)

Do it djozz!
wight
Offline
Last seen: 5 months 12 hours ago
Joined: 11/27/2013 - 16:40
Posts: 4955
Location: Virginia, USA

Good job Hoop, I like this compilation guide. Those are all great resources you tapped into there and I think you’ve put them together well. We’ve been needing for someone to do this.

In order to repair the forum software’s butchering of your command line text, you can try using the HTML PRE tag. – http://www.w3schools.com/tags/tag_pre.asp After bracketing your text with the PRE tag you’ll have this:

avrdude -p t13 -c usbasp -u -Uflash:w:star.hex:a -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m 

Still taking a break. Smile
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

B42
B42's picture
Offline
Last seen: 15 hours 39 min ago
Joined: 03/07/2013 - 21:03
Posts: 1849

Very nice Hoop, I think you may have just pushed me enough over the edge into buying the equipment.

Now if I can only learn to solder 8 more 7135s proficiently to the QLITE REV.A 7135*8 3.04A, I’ll have the 5A Eagle Eye X6’s I wanted for around $5 more each instead of $15! Smile

Maybe an addition of everyone’s modes and examples would be a good addition?

wight
Offline
Last seen: 5 months 12 hours ago
Joined: 11/27/2013 - 16:40
Posts: 4955
Location: Virginia, USA

It’s probably worthwhile to add instructions on the Pomona SOIC clip [5250]. I think the general consensus is that it’s superior in every way and worthwhile over the eBay contraption. It should cost <$20 shipped in the US, but it does not come with cable. I currently have mine hooked up with a harness made from one of these 40-wire female-female strips. Ordering the Pomona clip from Mouser or Digikey is a perfect time to stock up on small components like resistors, capacitors, diodes, FETs, extra ATtiny13A’s, etc.

Still taking a break. Smile
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Chazzy
Chazzy's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 06/23/2013 - 13:24
Posts: 292
Location: California

Nice work Hoop! Concise and well written.

"Whoa that's a bright light!" ... Yea I guess.

Mods: [HD2010] http://www.reddit.com/r/flashlight/comments/2tw09v/w

jcs0001
Offline
Last seen: 2 months 1 week ago
Joined: 05/21/2013 - 21:29
Posts: 109
Location: western canada

I have been procrastinating – this write up may push me over the edge Smile

John.

CRX
CRX's picture
Online
Last seen: 10 min 40 sec ago
Joined: 04/02/2013 - 15:27
Posts: 1749
Location: Scotland

No excuses now Wink

Mike C
Mike C's picture
Offline
Last seen: 2 hours 43 min ago
Joined: 01/22/2014 - 08:03
Posts: 1565
Location: Sweden

I wrote a post in another thread with perhaps some useful info: http://budgetlightforum.com/node/32095#comment-598339

At least the info on what AVR Dude responds with if it can find the programmer or not, and then if it can find the chip or not, is of interest. I was having problems and it took me a while to figure it out.

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 2 months 1 week ago
Joined: 01/04/2014 - 06:47
Posts: 4949
Location: H-Town

Nice! Good Howto:

Good job!

Not as hard as it seems is it Wink

freeme
freeme's picture
Online
Last seen: 3 min 18 sec ago
Joined: 11/14/2013 - 22:00
Posts: 4187
Location: freedailydeals.org

Thanks for providing the SOIC8 eBay link. I discarded the idea previously when I found 3M SOIC8 cost about $48 from element14 in my country. I will give it a try when I get hold of the components.

bibihang
bibihang's picture
Offline
Last seen: 23 min 44 sec ago
Joined: 11/10/2011 - 09:32
Posts: 2321
Location: Malaysia

Thanks! Great job and this is very nice compilation indeed. Smile

ChibiM
ChibiM's picture
Offline
Last seen: 3 days 19 hours ago
Joined: 05/09/2011 - 10:25
Posts: 5316
Location: Holland/Japan

Love it!

I like having all useful info in as few posts as possible!

When I flashed a few of mine (never done it again after) I had to ask people through PM, and most information was hidden deep in threads..

luckily you have made a good overview.

you could even change the title to "Guide: How to flash a "you name it" with custom firmware."

edit: it would be very nice if there would be a thread where everyone can post their codes in, so people can copy and paste them....without having to reinvent the wheel.

willie
willie's picture
Offline
Last seen: 2 weeks 6 days ago
Joined: 08/16/2011 - 14:19
Posts: 821
Location: Houston

Thanks Mr Hoop. Seem to remember that you and I had a reflector transaction a few years back. Hoop is a real stand up guy.

NeilP
NeilP's picture
Offline
Last seen: 5 months 4 days ago
Joined: 12/01/2014 - 04:07
Posts: 246
Location: Jersey Channel islands

Any reason why the wiring is changed at BOTH ends? I mean pulling out the delicate pins on the SOIC clip, when you have already had the connector open a the other end. I’d be inclined to do all the wire swaps at the black plug end

From Jersey, the Island, not New Jersey, but old Jersey..the real one Wink

wight
Offline
Last seen: 5 months 12 hours ago
Joined: 11/27/2013 - 16:40
Posts: 4955
Location: Virginia, USA

NeilP wrote:
Any reason why the wiring is changed at BOTH ends? I mean pulling out the delicate pins on the SOIC clip, when you have already had the connector open a the other end. I’d be inclined to do all the wire swaps at the black plug end
Simply put: you’ve misunderstood which section is the most fragile.
  • The fragile part of the SOIC clip is the “next” section, the section after the part Hoop shows that you need to change. There are 16 pins in the clip itself. The delicate part contains the 8 pins which interface with the IC (they are retained somewhat precariously by melting plastic, glue, etc). The top section of each of those pins is nicely nested inside the middle of the clip and interfaces with it’s mating pin. From that section up is very solid and easy to assemble/disassemble.
  • The IDC connector and ribbon cable is quite sturdy… as long as it’s a cohesive whole. Once you start taking it appart things get worse. Once you start attempting to manually punch things down into those pins without a punchdown tool, it doesn’t feel as sturdy. Once you don’t have a ribbon cable at all and have to tear the ribbon up for 5 centimeters back in order to trade the pinout around…. it really feels like crap. If you broke the cap when you took the IDC connector apart you’re really sunk at that point.

The provided cable (IDC to ribbon to male pins) does not give all necessary signals. It’s an 8 conductor ribbon and 10 pin connector; two of the 10 female pins of the connector do not make a connection to the ribbon. It’s missing MISO. Nobody would take apart the IDC connector if they didn’t need to get MISO. Once you’ve got the appropriate 8 connections on that end swapping the other end is super easy. The end result is as sturdy as a person can expect to get at this price point.

Still taking a break. Smile
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

NeilP
NeilP's picture
Offline
Last seen: 5 months 4 days ago
Joined: 12/01/2014 - 04:07
Posts: 246
Location: Jersey Channel islands

I don’t know which piece is more delicate than the next.

I was just going by what was posted in the very first post of this thread, where he says, in relation to the clip

Quote:
On the clip end, use needle nose pliers and pull on the pins to take them out of the clip. The connections are delicate so if you pull on the wires themselves rather than the pins they can sever and you’ll need to repair by soldering.

It just seemed to me easier to only open and tinker with one end. But as long as it wired correctly, it won’t matter

From Jersey, the Island, not New Jersey, but old Jersey..the real one Wink

Sonofspectrum
Sonofspectrum's picture
Offline
Last seen: 1 day 16 hours ago
Joined: 01/02/2012 - 11:44
Posts: 139
Location: England

Great job thanks for writing this up. Its just what I needed to get me started.

It's moments of madness that keep us sane.

wight
Offline
Last seen: 5 months 12 hours ago
Joined: 11/27/2013 - 16:40
Posts: 4955
Location: Virginia, USA

NeilP wrote:
I don’t know which piece is more delicate than the next. I was just going by what was posted in the very first post of this thread, where he says, in relation to the clip
Quote:
On the clip end, use needle nose pliers and pull on the pins to take them out of the clip. The connections are delicate so if you pull on the wires themselves rather than the pins they can sever and you’ll need to repair by soldering.
It just seemed to me easier to only open and tinker with one end. But as long as it wired correctly, it won’t matter
Well now you know. The part that gets killed is the “business end”. You’ll see wearing out clips mentioned in other SOIC-clip related discussions here on BLF. Damaging the solder joints like Hoop warns about is nothing but an annoyance. Once you have one in hand you’ll understand.

Still taking a break. Smile
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Hoop
Hoop's picture
Offline
Last seen: 5 days 13 hours ago
Joined: 12/20/2012 - 05:33
Posts: 744
Location: Spokane, WA
NeilP wrote:
Any reason why the wiring is changed at BOTH ends? I mean pulling out the delicate pins on the SOIC clip, when you have already had the connector open a the other end. I’d be inclined to do all the wire swaps at the black plug end

Good idea NeilP. I’ll have to try that and see if it’s any easier.

FmC
FmC's picture
Offline
Last seen: 45 min 32 sec ago
Joined: 03/31/2013 - 05:23
Posts: 1779
Location: AU
wight wrote:
The provided cable (IDC to ribbon to male pins) does not give all necessary signals. It’s an 8 conductor ribbon and 10 pin connector; two of the 10 female pins of the connector do not make a connection to the ribbon. It’s missing MISO.
NeilP
NeilP's picture
Offline
Last seen: 5 months 4 days ago
Joined: 12/01/2014 - 04:07
Posts: 246
Location: Jersey Channel islands
FmC wrote:
wight wrote:
The provided cable (IDC to ribbon to male pins) does not give all necessary signals. It’s an 8 conductor ribbon and 10 pin connector; two of the 10 female pins of the connector do not make a connection to the ribbon. It’s missing MISO.

but only 6 conductors used, so no big issue.

From Jersey, the Island, not New Jersey, but old Jersey..the real one Wink

wight
Offline
Last seen: 5 months 12 hours ago
Joined: 11/27/2013 - 16:40
Posts: 4955
Location: Virginia, USA

NeilP wrote:
FmC wrote:
wight wrote:

The provided cable (IDC to ribbon to male pins) does not give all necessary signals. It’s an 8 conductor ribbon and 10 pin connector; two of the 10 female pins of the connector do not make a connection to the ribbon. It’s missing MISO.
but only 6 conductors used, so no big issue.
One of us does not understand the other. What are you getting at?

Still taking a break. Smile
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

NeilP
NeilP's picture
Offline
Last seen: 5 months 4 days ago
Joined: 12/01/2014 - 04:07
Posts: 246
Location: Jersey Channel islands

I was not understand what you were getting at with a quote without any text of your own.

It is a 10 pin connector, with an 8 pin cable, we know that, and only 6 are used for programming the driver chip
The connector has to be opened up to move one wire over from pin 8 to pin 9, which is the MISO output, this is then connected to pin 5 on the ‘crocodile clip’.

Hoop mentions that pulling the pins at the crocodile SOIC clip is ‘iffy’ as the connectors and solder joints are delicate.

My initial post was merely to ask why the complete swap of all the wires was not done at the IDC plug.

Hoop got what I was saying, but you thought that moving the IDC pins was more ‘risky’ than moving the pins at the crocodile plug without a proper insertion tool.

all of these little connections are difficult, so my thought was simply one to try to keep the risk at just one end of the cable..so only have to fiddle at one end.

When I have done these IDC connectors before, I don’t recall any problem with them in relation to not having a proper insertion tool.

I could not quite not quite get what you were getting at quoting the post from earlier.

From Jersey, the Island, not New Jersey, but old Jersey..the real one Wink

Pages