Code and Life

Programming, electronics and other cool tech stuff

Supported by

Supported by Picotech

DIY USB password generator

Having done half a dozen V-USB tutorials I decided it’s time to whip up something cool. As USB keyboards were an area untouched, I decided to make a small USB HID keyboard device that types a password stored in EEPROM every time it’s attached. A new password can be generated just by tabbing CAPS LOCK a few times (4 times to start password regeneration and one tab for each password character generated, 10 is the default password length). Below you can see the device in action:

The place I work at requires me to change my password every few months so this would be one way to skip remembering a new password altogether (as long as I remember to write it down before regenerating a new one so password can be changed :).

What is inside?

The device is powered with a simplified version of the hardware I used in my ATtiny85 USB tutorial – I stripped away the LCD, reset pullup and both capacitors. If you’re better in cramming components inside enclosures I suggest adding at least a 0.1 uF capacitor between VCC and GND, but it seems to work fine even without it:

The enclosure was graciously donated by an old 512 MB flash drive. I couldn’t make myself to break the USB connector from the circuit board inside, so I stripped appart a short USB cable instead (shown on left):

After some thinking and iterative soldering, I managed to cram everything on a tripad veroboard with 2×8 pads with the following initial setup:

I soldered the connector first, then the zener diodes, then resistors and jumpers, and finally VCC, GND and the ATtiny itself. I used the following tricks to make all ends meet:

  • D+ zener diode goes to the pad under ATtiny that is connected to GND pin
  • After the D- zener diode, only 1 pad is left for 2k2 pullup and 68 ohm resistor, so I used a jumper wire to the next pad
  • 2k2 pullup goes to a pad connected to ATtiny VCC
  • VCC goes to the pad under the ATtiny using a black jumper wire
  • I soldered the D+ 68 ohm resistor to a wrong tripad, so I used another jumper wire just barely visible behind the top left black jumper wire for GND

I was pretty satisfied the result and the fact that it actually worked! The board did not initially fit into the very snug space in the plastic enclosure, so I had to use a Dremel to trim its insides a bit, but after that, everything snapped right back (click for larger versions):




Update: For those who are building this project – I recommend you first build it on a breadboard, and only when you have it working, solder it to a veroboard. Here are two additional, extra-large pictures of the configuration I used to help you in the component layout:


Software

The device presents itself to the computer as a USB HID keyboard. To enable communication to the device, it is a boot-compliant keyboard that can receive LED status changes from the computer. HID descriptor is from Frank Zhao’s USB business card example and I also looked at Frank’s code to understand how LED state is sent to the device (in short, PC sends a control message with 1 byte of data, the LED state bit mask).

The code is mostly based on my USB HID mouse example except for the usbsconfig.h and HID descriptor changes required to implement a boot keyboard. Update: You may also want to read my USB HID keyboard post if you want to learn more. I’ve documented the code but here are some highlights if you want to understand it better:

  • PASS_LENGTH defined in the beginning controls the length of generated passwords
  • SEND_ENTER can be defined to 1 if you want the device also to send ENTER after typing the keyboard
  • measuring_message and finish_message contain the messages that are displayed when generating / saving a new password
  • buildReport() is called by the program main loop to send keypresses to PC one by one – it translates characters in messageBuffer to USB key codes on the fly
  • usbFunctionWrite() is implemented to receive the 1-byte LED state from PC – it calls caps_toggle() function every time the LED state changes
  • generate_character() is used to return random keypresses – it is currently written to return alphanumerics, hyphen and underscore (64 symbols make it simple to select one so each has equal chance of being selected without additional logic)
  • caps_toggle() does the caps-lock counting and password generation/saving

I’ve packed the source files with the schematic, critical pictures and a Makefile. In addition to “make flash” you of course need to update the fuse bits to use the PLL clock source – see details from my previous tutorial for that. I also very strongly recommend testing the device using a breadboard before soldering it, because otherwise reflashing will be a major pain.

And of course, if you build it, try it at your own risk – and remember that once you reprogram the password, nothing will be able to restore it. I recommend storing passwords generated with the device to a safe place just to be sure.

Update: Getting it from SparkFun

I found out yesterday that SparkFun is carrying an almost identical piece of hardware, the AVR Stick. So if you order one and reprogram it with this firmware (pin configuration in usbconfig.h needs to be updated in that case), you can avoid some soldering (although not all, you’ll likely need to solder in the programming header).

I asked SparkFun if they’d be interested to make a “2.0” model of their AVR Stick with actual USB connector and enclosure to go with the package, and my password generation firmware preloaded. If you think that’s a good idea, now would be a great time to send them feedback. I’d also be interested in covering additional hacks and tutorials with such a device. :)

Update 2: Indiegogo project

Alvin Chang is currently (December 1st 2012) running a Indiegogo project to build a device very similar (and inspired by) my DIY version. In case you’re interested in getting a ready-made version, be sure to check Mr. Chang’s project out: Aladdin: The Key to Your Computer.

223 comments

Stu:

Excellent work there.
I’m really interested in making one of these for myself with your bits and pieces, many thanks!
Just one thought, you could also include a special operation on a keypress to make it change your password (for Windows 7) by getting it to do the Ctrl-Alt-Del shortcut, down arrow, down arrow, down arrow, then enter. It can then put in the known old password, and update the new password for you automatically!
This method has the obvious advantage of having NEVER been displayed on the screen in Notepad, etc.
Thanks!

jokkebk:

Great idea for the Windows 7 -specific key combo, I’ll see if I time to do that at some point!

Meanwhile, it’s pretty easy to add on your own, especially if ctrl-alt-del can be sent in a single HID report – you could just invent special characters for that and the arrow keys (like ^ and _) and concatenate everything into the messageBuffer while regenerating password (first the old password, then the key sequences, and finally the new password two times) – of course messageBuffer needs to be at least 64 bytes then. :)

Stu:

Hi jokkebk (Sorry, I don’t know your name!)
I would have a go myself, but I’ve been over your code, and some USB coding in the past, I’m still somewhat mystified as to why USB has to be so darned difficult to use, even with libraries like v-usb!
I only write simple code for my PIC chips (PIC16F88 so far), so I’m not grounded in AVR at all, I’m reading more about it now though.
But I’m perfectly content to shell out £2 for a USB serial to TTL chip off ebay and interface to my PIC chips directly on my PC via a USB virtual COM port. Good olde RS232 still serves me well.
Of course making HID keyboards requires USB, so I’m prepared to put the effort in, but for now, I’ve got an AWFUL lot of reading to do. For starters I’ll be compiling your code or just trying out the provided HEX file, thanks! Its important to know as much as possible when diving into all this, even if your code does it all for me…
You’re definitely a credit to the hardware hacking community! Thanks!

jokkebk:

Hi Stu,

Yeah I have to admit USB is a hard nut to crack, and the only way I was able to do it was to start from ground up, first building the simplest possible circuit with V-USB, and then adding layer after layer: first a easy circuit, then lighting a LED, then reading and writing data, then simplyfying the circuit and getting rid of the oscillator, then HID devices, and finally the HID boot keyboard. Even understanding the keyboard reports takes some thinking and because one has to emulate key presses instead of just sending characters, another layer of complexity is added.

I recommend you to check my V-USB tutorial from the beginning, by starting from something less complex the amount of learning in each new iteration stays small enough to absorb. You are absolutely right that USB to serial TTL is a good option well worth the cost, I myself tackled USB more because it seemed challenging than absolutely useful.

Joonas a.k.a. JokkeBK (my home page is well hidden on the right hand navigation pane ;)

marcus:

nice work!!
just a simple question..what happen if u lost this dongle..ha ha

Trev:

Any chance you’d be willing to make me one if I paypal’d you some money?

Adam Miner:

Would you be willing to make/sell/ship these?

jokkebk:

Hi Adam & Trev,

My soldering skills probably wouldn’t cut it for commercial production, and I’d also price myself out of business in any case. :) Those who want a ready solution might want to check out YubiKey. If there’s enough interest, a provider like SparkFun might be able to do a DIY/preassembled kit based on this project, I might just ask them about it.

Joonas

thierry69:

nice job…
is it possible to have the file to program the chip?
thank you

jokkebk:

thierry69,

The source package contains the .hex file you can use to program the chip. If I recall correctly it is a version that does not send ENTER, so you need to recompile using WinAVR or AVR Studio if you want to enable that functionality.

kenny:

Great job! Another question here, does the USB need any driver to work in Win7? Or the driver is already included inside the ATtiny chip? Likewise the USB can use it at any computer, plug-and-play?

jokkebk:

kenny, from computer’s perspective the device is a USB keyboard, so no driver at all is needed for PCs.

However, OS X does things differently and it does not work for Macs (it seems Macs don’t send caps lock status accross keyboards, so communicating with stick using status LEDs do not work – also, OS X has “intelligent” keyboard recognition that does not work very well with non-interactive devices). I haven’t tried Linux yet.

Untouchab1e:

Nice project. Ive made something similar with my Teensy 2.0. However, from what I understand, if I stole your usb device, plugged it into my computer and opened notepad, I would get the password out in clear text, correct?

So while the device is a cool way to not having to remember a given password, the security of it all completely relies on you having control over the device at any given time.

If you have somehow taken measures to mitigate this that I somehow missed, please enlighten me :)

jokkebk:

Untouchab1e: Yes, it’s much like a key in a keychain – if it’s stolen, there’s nothing to stop the user from taking advantage of it, as long as he/she knows where the key fits.

Unfortunately there’s very limited space on USB stick to add any kind of keypad for pin code – the best option probably would be to implement a “secret knock” using the caps lock key – e.g. three short taps followed by three long ones would trigger the device to to output its password. However, you’d either need to hard-code it or whip up a very elaborate setup on how to program the device.

Implementing a special software to program the device using caps lock is one option but you’d quickly lose any “simplicity benefits” against an encrypted USB memory stick.

Norman:

Very cool Joonas.

Vedfolnir:

Outstanding!

Roman Smetanin:

Tell please you can make and send by mail this device? And how many it will cost with delivery?

jokkebk:

Hi Roman,
As I said earlier in the comments, I won’t be making these – I doubt people would be willing to pay me 30€/hr for soldering such a simple circuit. However, I think I’ll check if some electronics supplier would be willing to offer this is a kit, either in finished or solder-it-yourself form.

thata:

That great man now I wanna make one but I need the flash to submit a username and pass would, should I go the same route? and do you have any other suggestions?

jokkebk:

@thata: The hardware is identical and software (or firmware, if you like) would not need much tweaking to achieve what you want – just send username first (you’d need to hardcode that into flash), then a TAB, then the saved password and ENTER and you’d be good to go.

salman:

fantastic,superb,awesome buddy lookin ahead eagerly for more such innovations…

mck:

For everyone who wants to buy a pre-made one, there is nothing that I can see that would prevent the Sparkfun AVR Stick from working. It has the same ATtiny, and comes pre-programmed using the same USB library, so its compatible. http://www.sparkfun.com/products/9147

jokkebk:

@mck: Yes, I realized that yesterday. The hardware is all there, but an enclosure would be nice, as would an actual connector instead of “on the board USB traces” (some people complained that it doesn’t get contact in all cases).

I suggested a “2.0 model” to SparkFun with enclosure and this firmware preloaded and some additional improvements. If you’d like to see this happen, now would be a good time to tell SparkFun that!

I also promised to cover additional hacks and tutorials for the 2.0 version if they decide to make one. :)

Nicolas:

What a great use of the vusb library.
I got the tools and time to assemble some kits, if enough people are interested and you dont mind jokkebk. Cost of parts + shipping. Maybe a custom pcb down the line (theyr cheap anyways)

jokkebk:

@Nicolas: I don’t mind at all, I think it’s great if someone wants to build them!

David:

Fantastic project, have just ordered some attiny85 so I can have a go.

Thanks

wm:

Super Cool idea..

How would you address this?

Good Security Practices include disabling auto mount of anything..

As I read the piece auto mount is essential to the function of your device.

Again.. Fantastic piece of creativity and Thank you so much for sharing it.

Philip:

When I try to compile main.c I receive an error indicating that LED_PIN is not defined. What value did you use for LED_PIN. I couldn’t find where it was defined in anywhere in your source.

main.c: In function ‘main’:
main.c:293:13: error: ‘LED_PIN’ undeclared (first use in this function)

Thanks for sharing this project.

jokkebk:

Philip: Oh no, I forgot to remove that last reference to LED_PIN. You can either remove the offending line or define LED_PIN to PB3 or PB4 (or straight numerical values of 8 or 16).

I have fixed the source code now, so alternatively you can just re-download the zip.

jokkebk:

wm: In many cases, attaching a USB keyboard might not be considered “auto-mounting” (I believe the term mounting is mostly used for storage devices), so the device might still work even if certain USB devices are not automatically mounted.

One way to check before building the device would be to plug a normal USB keyboard in when the machine is waiting for password, and see if it gets recognized and you can type in your password using that.

Of course, if your employer or similar directly prohibits the use of any devices to input password, I do not recommend you to use this project…

Brillow:

I flashed the chip, build the circuit on a breadboard, but my computer doesn’t know what to do with it. It tells me, that it’s an “Unknown device”. Any ideas why this is happening?

jokkebk:

@Brillow: Good thing that you built it on a breadboard so you can debug! On my experience, Windows plays a “message sound” that a USB device is connected even if the firmware wouldn’t work, so if you do not get that, I suggest you double-check the connections (you can see an example layout for breadboard on my ATtiny85 USB tutorial page).

Also, you can check with a multimeter that voltages are OK – for example, D- should be about 2.9-3.3V because of the pullup + zener. I recommend <1W zener diodes, one person had issues with too "heavy" zeners. Double-check also that zeners are connected the right way (black line away from GND).

And of course, if you're using a breadboard you could attach a LED to a free pin and use some debug programs to check that the program does not hang before getting into main loop...

Daniel:

Same problem als Brillow… The computer tell’s me “unknow device”. I checked the connections and D- Voltage and it’s ok. Any ideas? Shouldn’t PB5 be connected to a pull-up to avoid the reset? (I tried but it did the same thing :-/) Please help! :-P

Brillow:

Hmm, Voltages seem ok and I’m using 0,5W Zeners (inserted the correct way ;) ). The search continues…

jokkebk:

@Daniel: Hmm, weird problem! Unfortunately I soldered my last ATtiny85 into this project and would like to avoid prying it out of there to retest the circuit with a breadboard.

First suggestions would be to try if adding a 1 uF capacitor or so between GND and VCC to see if that would help, and testing the USB cable that there isn’t cold solder joints that conduct poorly (mine shows 0.0-0.6 ohms for each of the four wires).

I think reset has a small internal pullup but if you attach an additional LED and light it once you get the circuit running and turn it off when you reach the main loop, you can check that the device does not reset before its time.

Also, double-checking the fuses is always a good idea.

I think I’ll order a few additional MCUs soon and try the configuration out myself once more, will get back to this when I get the parts.

Daniel:

@jokkebk: Thank you for your fast answer! I already try to pull up the reset line and to solder a capacitor between vcc and gnd. I directly solder the usb connector to my pcb and there’s no poorly conduction. :-/
Did you use the 20Mhz version or the 10Mhz one of the Attiny85?(I got the 20Mhz one)
And are you sure of your hex file? (I read upper that there were a mistake in the source code with LED_PIN)

jokkebk:

@Daniel: I used the 20 MHz version with fuses set to 0xE1 (low) and 0xDD (high). The .hex file should work as the compile problem only related to source code I had edited after compiling. Unfortunately I cannot check the .hex file as I have only 10 MHz ATtiny45 at my disposal and it probably won’t support 16.5 MHz from PLL.

If you upload a picture of your PCB I can take a look at it if I can spot any problems there.

Brillow:

I finally got it too work, it seems I forgot to set the fuse bits. This way it seems that I destroyed 2 of my chips, at least I can’t see to connect to them anymore.

mck:

Is there anything special I’m supposed to be doing for the SFE board? I changed the pin definitions to PB0/PB2 for D-/D+, respectively, and it doesn’t cooperate. Is there something I’m missing?

Rik:

Well, first of all many compliments for the nice development.
I have some problems though and I am wondering if somebody working with OSX Lion can assist me.
The hardware assembly looks fine and the voltages are 2.47 V on PIN no 6 and ~0 on PIN no 7 of the ATTiny85.

I installed the needed software as described here: http://www.ladyada.net/library/avrdevtut/setup-mac.html

Plus I installed the precompiled version of libusb.

Than I downloaded the usb_passgen package and run: “make” and “make flash” and this is the message that I get:

make flashavrdude -p attiny85 -c usbtiny -v -U flash:w:main.hex

avrdude: Version 5.11, compiled on Mar 24 2012 at 00:34:11
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is “/usr/local/etc/avrdude.conf”
User configuration file is “/Users/rik/.avrduderc”
User configuration file does not exist or is not a regular file, skipping

Using Port : unknown
Using Programmer : usbtiny
avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

avrdude done. Thank you.

I don’t know what is wrong there… Any idea???

Thank you in advance.

jokkebk:

@Rik: I checked out Lady Ada’s instructions and tried out “easy method”, i.e. CrossPack for Mac from Obdev (by the way, amazingly useful thing to have). After installing and plugging in my usbtiny, I could flash with avrdude just like in Windows.

So as the error says, it seems there are communication problems with your USBtiny. I assume the USBtiny is the programmer you are using, so unless you have a faulty programmer, double-check the USB connection (you should get a completely different error if USBtiny fails to communicate with the ATtiny85).

Also, if you are powering the circuit from USB, check that you have not accidentally left the USBtiny “power jumper” on, which might cause malfunction when the MCU is getting 5V from USB. As last idea, triple-check the 6-pin header connections that you have not mistakenly wired ground, VCC or anything else to wrong places (in worst case it’s a good way to brick your programmer).

Hope you get it working!

Rik:

@jokkebk Sorry for the dumb question… but how can I check if I didn’t “have accidentally left the USBtiny “power jumper” on”???

I don’t know what you mean with USBTiny. I only have the ATtiny85 wired with resistors and diodes of the right value and a usb cable going to the breadboard in a way similar to what you show in the other tutorial (a 4 pins plug inserted in the breadboard to allow connecting the usb cable) and that is it…

Thanks in advance!

jokkebk:

@Rik: Ah now I understand! You need a programmer like this USBtiny to flash the chip, it doesn’t work with just the project circuit plugged into a computer:

http://www.ladyada.net/make/usbtinyisp/

I thought you had it because you were referring to the guide from Lady Ada on how to use this on a Mac. There are also a dozen other ISP programmers available with various designs, but the USBtiny is probably the most commonly used.

Alternatively, you can use an Arduino to do the programming, I just did on blog post on that. It also shows how I have detached the USB cable when programming, with USBtiny you can just set the jumper as I said and avoid that:

http://codeandlife.com/2012/03/21/using-arduino-uno-as-isp/

Also a word of warning: Even if you program the device with a Mac, OS X handles USB keyboards in a different way, causing the USB password generator not to work on a Mac (in a nutshell, Macs don’t send LED status changes to keyboard when you toggle caps lock on the native keyboard, and my device waits for this status change message before it sends anything…). So it’ll only work on PCs.

However, if you add a button and use that to trigger the sending of keypresses, you might have success. I haven’t tried that myself yet.

Rik:

@jokkebk Well, well… this make now a lot of sense… I will try to get one of this usbtiny from Adafruit or Sparkfun and then try again…

Clearly there was some big piece of equipment missing!!!

Thanks indeed, I’ll tell you if I manage!

-R

jokkebk:

@mck: Hmm, I don’t have the SparkFun board myself, but the first thing I’d check is that did the original firmware work, reporting temperatures via text input (or any other voltage measurement, it would probably report something like zero if there’s no temp resistor attached)?

Once you get the “original plan” working, you can be sure that the card gets proper contact to USB port, and can then just double-check the differences in EasyLogger usbconfig.h and my USB password generator’s usbconfig.h. I can’t think of much else than the pin definitions, though. Some people had issues with the LED voltage regulation used in SparkFun’s version, and needed to use a USB HUB to get it working.

Also, as noted in my other comments, the USB password generator does not work on Macs due to the way OS X handles these kinds of devices.

David:

Hello, I have managed to finally program the attiny (after loosing alot of hair and many different methods) however i am a complete noob at reading circuits even simple ones is there any chance anyone could provide a diagram on veroboard for the component layout. I am getting the same issue as others when I plug it in that the device is unknown but i think this is becaus I have not put it toghether as it should be.

Thanks
David

jokkebk:

You _should_ be able to see all the components in this picture on the veroboard, just look at my veroboard sketch first so you can visualize in you mind which groups holes are connected.

I added two new pictures in large resolution to help you even more. If I had the knowledge, I would’ve created a gif animation of the build process, but alas it’s too late now.

jan:

Hi jokkebk

Thx for the passgen.
Mine works like a charm with win7.

Some remarks
– win7 – mine did load a driver at first startup from microsoft
– never did it again :D and is working since then

– linux – does not work.

– kernel 2.6.38.2 message is :

[ 3144.219114] usb 3-3: default language 0x0409
[ 3144.228145] usb 3-3: udev 9, busnum 3, minor = 264
[ 3144.228154] usb 3-3: New USB device found, idVendor=4242, idProduct=e131
[ 3144.228160] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3144.228166] usb 3-3: Product: Passgen
[ 3144.228171] usb 3-3: Manufacturer: codeandlife.com
[ 3144.228417] usb 3-3: usb_probe_device
[ 3144.228429] usb 3-3: configuration #1 chosen from 1 choice
[ 3144.231139] usb 3-3: adding 3-3:1.0 (config #1, interface 0)
[ 3144.231296] usbserial_generic 3-3:1.0: usb_probe_interface
[ 3144.231307] usbserial_generic 3-3:1.0: usb_probe_interface – got id
[ 3144.231369] usbhid 3-3:1.0: usb_probe_interface
[ 3144.231377] usbhid 3-3:1.0: usb_probe_interface – got id
[ 3144.241875] input: codeandlife.com Passgen as /devices/pci0000:00/0000:00:04.0/usb3/3-3/3-3:1.0/input/input11
[ 3144.242434] generic-usb 0003:4242:E131.000A: input,hidraw3: USB HID v1.01 Keyboard [codeandlife.com Passgen] on usb-0000:00:04.0-3/input0
[ 3144.242513] drivers/usb/core/inode.c: creating file ‘009’
[ 3144.242598] hub 3-0:1.0: state 7 ports 6 chg 0000 evt 0008

-> so it is recognized ok.

what it does on linux :

it spits out the last 7 bytes (characters) of the password at first plugin and the last 8 chars of the password at every plugin afterwards. The first 3 (2) characters are always missing.
I compiled your code on linux and flashed the chip with linux avrdude and an arduiono isp programmer. Works great.

what it does not on linux : it does not recognize tabslock / led status change
-> it does not generate new passwords

At the current state of code it is not usable with linux.

Any hint is welcome.

THX again for this great idea and support with schematics, parts, code … blog …

Jan

jokkebk:

USB HID devices seem to take a while (two seconds or so) to initialize themselves, so any characters sent before that are lost. With first attempts, I had a delay timer to wait a few seconds before sending the characters.

But after I added the support for receiving LED state changes, I assumed that the device is initialized when the first LED state is received – obviously this is not the case in Linux. You’d need to add a initial delay – for example increment some counters and only start sending after counter reaches a given value.

jan:

OK, there seems to be a timing problem with usb on linux. So far i was not able to set a reasonable waiting time in the main loop. I tried up to 3 seconds waiting time before sending the password.
And i found another obstacle on my way. Keycodes are different for win7 and linux. What a surprise LOL Special characters are interpreted in a different way:
win7 linux
” 2
= 0
$ 4
( 8
…and so on ..

If you set your password on win7 to use it on linux you r screwed if you rely on your notes in case of trouble. You have to translate your password to your linux keycodes (just look at your keyboard …). Or you you have to stick to your operating system …

And there are more problems on linux as no keypress or LED-change seems to be recognized by your current code on linux.Probably linux doesnt send it in a way your soft can recognize it? There seems to be no way to generate a new password. Probably we are stuck like in OSX. I wouldnt mind to set a new password in win7 if i can use it on any OS afterwards.

Seems to me i have to go through your usb tutorial
… and understand it before i can contribute anything useful
this might take a while …
Keep in mind : N E V E R change a running system!
Your system works perfectly for the OS you created it for!

THX for your advice and help.
Happy Easter :D

Jan

009:

I use the V-USB, when i plug the usb, the program is running.
When the pc loaded the drivers completly, the program had run a half,
how can the avr know if the drivers is loaded completly on PC,

I have finded the function USB_SET_ADDRESS_HOOK、USB_RX_USER_HOOK and USB_RESET_HOOK.
which can i use, and how?

is there any sample?

sorry for my pool english.

jokkebk:

Yes that’s the hard part. A simple way is to add a delay loop of a few seconds after initialization before the main loop (you’d likely need to call USB polling function also in there), but that will not work the first time when Windows looks for drivers and installs them.

If you have a custom software on PC side, you could implement a “activate” command that you send over USB to tell the device to start doing its job.

For HID devices that have no PC side component telling them to start, the only choice is the delay loop. On Windows, the HID keyboards implementing boot protocol can also wait for first LED state change message (which is sent after initialization to tell the “initial” LED state) and then start doing things. But that won’t work on Linux or Mac, I think.

009:

Have you used these functions yet? USB_SET_ADDRESS_HOOK、USB_RX_USER_HOOK and USB_RESET_HOOK.

I have searched everywhere, and can’t find any example.

jokkebk:

My password generator uses USB_RESET_HOOK, check out usbdrv/usbconfig.h – it calls a function that is then defined in main.c. I would guess the other two hooks would be similar.

009:

sorry for disturb you again and again.
i have unzip the usb_passgen.zip and can’t find any code about hook in main.c but only usbconfig.h
#define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();}

does this hook can resolve my problem that program had run a half when pc had loaded the drive completly ?

jokkebk:

The #define in usbconfig.h means that the code after it is executed when USB device is reset:

if(!resetStarts){hadUsbReset();}

Basically, the if clause will call hadUsbReset() when resetStarts is false (zero). The V-USB library basically has this kind of code somewhere in usbdrv.c:

USB_RESET_HOOK(1); // reset starts
// do reset stuff
USB_RESET_HOOK(0); // reset ends

So only thing needed in main.c is to define hadUsbReset() function which the above lines will call, thanks to that #define in usbconfig.h.

Reset hook is called some time before PC accepts any data from your USB device, so it probably does not solve the issue. You need to start a timer before the main loop, and only start sending anything after certain period has passed. You can find many AVR timer tutorials by googling – just don’t use interrupt versions (unless you understand the requirements V-USB has for interrupts and can accomodate for them).

009:

Thanks a lot,
now i have used a witless way to detect if the driver is loaded completly.
i emulate to press the CapsLock key in the loop, and checked the CapsLock counts, if the counts > 2 , it means the drivers is loaded completly.

it seems to work fine ^_^

FLAR:

Hello jokkebk,

how can switch form CAPS LOCK to a other button for new Key?
the usbFunctionWrite is only start to klick CAPS LOCK and I find not the call.

thanks for help,
FLAR

jokkebk:

Hi FLAR,

Unfortunately the only thing that a USB keyboard will receive from PC is the LED status for CAPS LOCK, NUM LOCK and SCROLL LOCK. The password generation counts LED state changes and starts generating after three of them (currently any of the three will work) are received.

So it is not possible to change the key, sorry.

Joonas

c4d:

Take a simple step… password combinations on windows login type “win” or something simple then plugin key. Therefore your password for login would be “win” and your keys password…

For a or a login to a website such as Facebook… type “fb” then insert your key

Dimitar Ivanov:

Hi,I am programming Attiny85 threw Arduino UNO making it ISP.
And I wan’t to ask you is there a way to give me a code which I can put in Arduino IDE and prgoram it threw UNO ?

And where to enter the password string I mean where I have to enter these methods in order to use them ?

jokkebk:

To program the ATtiny85 through Arduino, you first need to upload the ArduinoISP sketch with Arduino IDE to your UNO – that sketch is included in the default Arduino installation. After that, you can just change the programmer in usb password generator makefile from “usbtiny” to “arduino” and it should work.

(the makefile compiles all the needed .c and .S files into .hex file which is then programmed to ATtiny85 using the avrdude utility, which takes programmer type as parameter, in this case “arduino”)

The current code I have provided does not have a hard-coded password – you just connect the device and press CAPS LOCK repeatedly and it generates a password for you.

Dimitar Ivanov:

Well I tried programming the attiny85 threw arduino uno as ISP (atmega328)
And I get this error :
http://store.picbg.net/pubpic/F4/A5/9f2eb7db2c4af4a5.png

jokkebk:

Based on the screenshot it looks like both Arduino UNO and the ATtiny85 are responding OK, but your main.hex file is either corrupted or missing. If you have the WinAVR compiler pack on your pack and are trying to flash one of my projects, just edit the “Makefile” to make sure the DUDEFLAGS and CFLAGS have attiny85 as their part/MCU and run “make main.hex” to recompile the main.hex file.

Dimitar Ivanov:

can you compile one for me , because I am not able to do it :)

Dimitar Ivanov:

oh and do you have any idea how to solve this ? –
http://store.picbg.net/pubpic/07/D1/feae360ffea407d1.png

jokkebk:

Well I did, here’s a main.hex for ATtiny85. I haven’t tried it myself, but I think it should work. Here were the commands I used to make the .hex file:

avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -c usbdrv/usbdrv.c -o
usbdrv/usbdrv.o
avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -c usbdrv/oddebug.c –
o usbdrv/oddebug.o
avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -x assembler-with-cpp
-c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o
avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -c main.c -o main.o
avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 usbdrv/usbdrv.o usbdr
v/oddebug.o usbdrv/usbdrvasm.o main.o -o main.elf
avr-objcopy -j .text -j .data -O ihex main.elf main.hex

jokkebk:

No idea. Seems like the .hex file is again corrupt. Are you using “avr-objcopy -j .text -j .data -O ihex main.elf main.hex” to generate the .hex file, or some other method?

Dimitar Ivanov:

All I do is to connect my arduino Uno programmer with usb to computer then connect attiny85 to uno in order to program it , then I open and extract every single file from the rar archive and use avrdude to upload it.

Dimitar Ivanov:

using this command: avrdude -P COM7 -b 19200 -c avrisp -p attiny85 -U flash:w:main.hex

jokkebk:

I mean, how did you get the main.hex file, as AVRdude says it is corrupted. Sounds like it is in invalid format. Anyways, I suggest you ask this on AVRfreaks forum or similar place, they may be able to help you better.

Also, I think newer avrdude versions support arduino directly, so instead of “-c avrisp” you should use “-c arduino”

jokkebk:

Hmm, actually… You have for some reason placed avrdude.exe in the same directory as the project itself – the proper way would be to install avrdude somewhere and add that directory to PATH so you can run avrdude anywhere you need without specifying its location.

Secondly, you are running the command from a different directory than the .hex file. AVRdude will look for the .hex file in the current working directory, that does not include the .hex file and therefore it fails. AVRdude does not assume the .hex file is in the same place as the avrdude.exe, for the reason I mentioned above (it is usually in a totally different directory than the .hex file).

So first change to the directory where the .hex file resides, then run avrdude. If you read the avrdude error, the reason seems quite self-evident.

Dimitar Ivanov:

But the .hex file is in the same directory as avrdude.exe ?!

jokkebk:

Yes, but this does not make any difference. When a program starts, it runs in the directory where you executed the command. A program could check it’s location yes, but it usually does not, as it is assumed that the user is running commands that he/she wants to execute in the current working directory.

So if you run a program when you are at C:\Folder1, and the program itself is in Folder2, all relative file references are still relative to Folder1, not Folder2. It’s the way it has been since the 80s. Of course instead of main.hex you could specify C.\Folder2\main.hex and it would likely work.

And as I said, there should be no need for the avrdude.exe to even be in the same folder. For example, I have avrdude.exe installed with WinAVR and it resides in C.\WinAVR\bin, but because I have that folder in PATH, I can run “avrdude” in whichever directory I want, without specifying the path.

So to summarize: All file name arguments are usually done relative to your current working directory, not the program directory. If you run “C:\Folder2\avrdude.exe” in C:\Folder1, the program is still run in C:\Folder1, the .exe code is just fetched from another directory.

Dimitar Ivanov:

I finally uploaded the hex file :)
But now it looks like that windows 7 can’t recognize it , any solution for that ?

jokkebk:

Sorry, I cannot help you much; only suggestions I have are to double-check connections and that USB lines are connected to the correct pins, and maybe make sure that your ATmega is definitely running at the 16.5 MHz (fuses should be updated with AVRdude to allow this).

As an additional tip, if electrical connections are correct, Windows should play the “bell sound” when device is connected, even if the firmware has some issues. If you don’t get that, it’s likely some connector / pullup / etc. issue. Also, zeners connected the wrong way or too “heavy” zeners may cause issues. That’s about all I can think of.

Dimitar Ivanov:

All connection are fine , all components are in there place.
Am hearing a beep sound from my pc,and I am hearing it twice,because the device connect – show error 43 and then disconnect

Prough:

Can you make a tutorial for dummies?

jokkebk:

Could you please elaborate? If you follow my USB tutorial from part 1 to part 4, then port the project to ATtiny85, and finally study the USB HID mouse tutorial, this password generator should be fairly understandable.

Of course, if there’s a specific area that you feel is yet unaddressed, I could as well consider writing additional material on that. :)

Joeri:

I Like this project. Is it possible to expend the code so that it will transmit whatever it’s receiving via serial connection?

jokkebk:

I’m quite sure it is, probably using AVR integrated UART functionality is the easiest way to do this, you just have to use the interrupt flags to check if a byte has been received and then schedule for transmitting that – blocking UART input (i.e. waiting for the next character) without calling usbPoll() all the time will not work.

michael:

hello i am trying to figure out were all the wires and parts go im looking at the pictures but some wires and parts are not shown clearly and i dont know witch pin they go in can some one help me out with a more detailed layout of the board im trying to write up a grid system to help understand the layout heres what i have layed out so far
the grid is maked in units each unit is measured by the holes
a b c d e f g h
1
2
3
4
5
6

zener diode 1A TO 5B
zener diode 2B TO 3E
JUMP 1B TO 1C
JUMP 6B TO 5C
2k2 pullup 6C TO 6G
VCC 6A TO 4H
JUMP 3A TO 1E
68 ohm resistor 4C TO 6F
68 ohm resistor TO 6G

any help is greatly appreciated thank you you can ether post it here of by email at michael040990@gmail.com
thank you soo much and awsome project

jokkebk:

Hi Michael!

Excellent work on the reverse engineering of that picture, it might be that I could use your method of marking to help interested builders. I checked your notes against my device, here’s the results:

2k2 pullup should go from 6C to 6H so it reaches the last ATtiny pin, VCC

Second 68 ohm resistor goes from 3C to 6G

Also, you could label the 3A to 1E connection as “GND” like you did with VCC. :)

USB connector GND goes to 2A, D+ to 3B, D- to 4B and VCC to 5A

ATtiny in 2E-2H and 5E-5H, oriented so that pin 1 is at 2H (reset), and pin 8 at 5H (VCC)

With the above you should be good to go. Major risks are of course bad contact and cold solder joints, but with care it should work.

michael:

thank you for your responce i will be working up a board with that in mind fist i will see if i can get it built on a program called fritzing http://fritzing.org/ a prototype project once done would you like to check out the board and make sure everything is were it should be before i start soldering to a real one

michael:

ok i think i have it figured out here is a picture of my board
http://i48.tinypic.com/2ezob5j.jpg

and here is the project file im relitivly new to making boards

http://uploading.com/files/7a381e9e/attiny85%2Bpas.fzz/

jokkebk:

Everything else is OK, but the 1 space jumper wire on top row is one hole too far right, it should be from B to C, not C to D.

If you fix the drawing, I’d be happy to incorporate it to the post for any future builders – if that’s OK with you, please send it to me (either via comments or e-mail, jokkebk (sign) codeandlife.com)

michael:

i have sent you a zip containing all the files i have made and also containing all your files and some additional pictures and documents my email is michael040990 (sign) gmail.com

Ernie:

Hi jokkebk,

Would it be to difficult to have it also insert the user name then tab and then the password and enter?

jokkebk:

No, not very. There’s already code to write static messages, only thing that would be needed is using similar code to add (hardcoded) username and tab character (see my recent usb keyboard post on links to relevant HID tables) before entering the password.

treo:

Hello can somebody post the HEX file ? I tried to compile that many times and after program attiny85 thats only connecting and disconnecting but writing nothing :(

jokkebk:

I added the .hex file into project zip, don’t have the device at hand at the moment so I cannot check that it works, but there shouldn’t be any reason why it wouldn’t.

On Mac, the device doesn’t seem to receive LED state changes. If you’re still experimenting on a breadboard, you could try to add a LED and alter the code so that the LED toggles every time the device receives keyboard LED state change (in usbFunctionWrite() method) – there might be even some hardware issue.

treomika:

what should I use;

ATTINY85V-10MU
ATTINY85V-10SU
ATTINY85V-10PU
ATTINY85V-15MT

?

thanks

jokkebk:

You’ll want the one in PDIP package (through-hole component), unless you have etching capabilities for custom pcb and good solder hand for SMD parts. However, I doubt the models requested can do 16.5 MHz, even 15MT would likely need 12 MHz crystal. You’ll want a 20PU version I think. The ones you posted are all from low voltage “V” line which has limited frequency…

Hajoe:

Hello,

Thanks for a great Article. I was wondering about the Zeners, they seem to influence the proper functionality of this device a lot. Also if some of you could post the specs of your zeners that worked, also the ones that did not work. The reason why i need these is because the 1 watt zeners are totally worthless. The 1/2w zeners are functional to the point of getting the device to be seen but the (EMI?) error keeps reconnecting them. I am just trying to figure out how to get this device going.

Thanks a lot in advance.

jokkebk:

Yes, the electrical characteristics for USB devices seem to be a bit painful. I personally used 1/4 W spec’d zeners, and they’ve been working nicely.

Hopefully you’ll get it working!

Hajoe:

OK with a 1/2w Diode it did show up a lot more consistently with

ls it shows

Bus 005 Device 002: ID 4242:e131 USB Design by Example

and with dmesg

[ 2423.440101] usb 5-2: new low speed USB device using uhci_hcd and address 2
[ 2423.682894] input: codeandlife.com Passgen as /devices/pci0000:00/0000:00:1d.0/usb5/5-2/5-2:1.0/input/input10
[ 2423.683163] generic-usb 0003:4242:E131.0001: input,hidraw0: USB HID v1.01 Keyboard [codeandlife.com Passgen] on usb-0000:00:1d.0-2/input0
[ 2423.683206] usbcore: registered new interface driver usbhid
[ 2423.683211] usbhid: USB HID core driver

but no message at the caps tap and no password entry after that. I went through the code line by line but no reason for it to not work after that.

My question is, is there another way to see what the device is doing once its connected and registered into the system?

jokkebk:

Nice to hear. If I recall correctly, someone got even better result with 1/4W zeners.

I haven’t used AVR 1-wire debugging so I don’t know if that could be used to see what happens, and if it would work in this case. One option is to add a LED and turn it on and off at given points, that might give you an idea where the execution “goes” (e.g. if you light the LED and turn it off when you reach main loop, you’ll see if it turns off…).

Also, there’s a possibility that Linux doesn’t send caps lock to the device like windows does. I know OS X doesn’t…

Good luck with your efforts!

KevlarGibs:

I’ve been thinking about trying this project for a while now, but I have zero experience in this space… Would something like this: http://www.kickstarter.com/projects/digistump/digispark-the-tiny-arduino-enabled-usb-dev-board work for this project? I don’t mind working the software side of things, but I’d rather not make a mess of the soldering if I can help it

carlos:

hello ..please help-me.. congratulations for the project … but please help me
How can my program with the USB reset password generator and make it (tx)deliver the password again

jokkebk:

I’m not sure I understand your question. Do you want a program on the PC to make the device send the password again?

One way would be to modify the “caps lock listening” code so it would differentiate between caps lock and scroll lock, and use the former to regenerate password, and latter to resend it (e.g. 4 scroll lock toggles would send the password again). Of course you need to first find a way to toggle num lock programmatically on PC side.

If manual resend is enough, re-attaching the device or adding a reset button to it is also an option.

carlos:

Thanks for the reply … I need is a hardlock, I believe that this design can easily be modified to send the 10 characters only when ordering the software. could you help me?

jokkebk:

A hardlock is a lot easier to do with a custom USB device (or a custom USB HID device, I have no experience on those), but of course that would require drivers. Use my USB tutorial if you want to go that way.

However, a simple copy protection using a HID keyboard like this device is easily circumvented – just start the program, change focus to Notepad and the device spills out the password. Then one can just copy-paste the password without the device.

You would need some type of challenge-response authentication using a shared secret, and either use a USB custom device or implement some type of caps lock / scroll lock signalling system as I described before. Both are out of scope for me to answer, but I’ll take under consideration that I might write a post about it in the future.

Toaster_Chicken:

My etched version of this board.
I mounted and used the zener diodes on the opposite side of the board instead of using any bridging wires. Nice and compact layout. If I had some double sided PCB’s I’d do an SMT version with an ISP header that would inevitably be even smaller.

jokkebk:

Wow, that is really cool! One almost might be able to route it 1-sided SMT, or at least with partial SMT (although there wouldn’t be much point for that, probably)

midijay:

would it be possible to program a Ctrl+Alt+Del keypress? I think there’s a market for this solution as many touch-screen-only devices need to be connected to AD domains that require Ctrl+Alt+Del for logon and it can only be achieved with a physical keyboard. It would be very cool to insert a USB stick and voila the login box opens. Then you can use a virtual keyboard for the password….you just can’t use a virtual keyboard for Ctrl+Alt+Del. Honestly: if any can do this I would buy some immediately.

jokkebk:

Adding custom keypresses in front of the login credentials is easily done – all you need is to add 3 keypresses and 3 key releases in front of the queue.

However, currently those wanting these features need to make the necessary changes themselves (or have a friend do it), just like soldering it together is needed. Another alternative is to request commercial providers like YubiKey to add such functionality.

I may consider revisiting this project at some point in the future, though, to make such changes to firmware a bit easier, but I cannot give any guarantees as to when this would happen.

Jan:

Hi jokkebk

My passgen stopped working on win7 some time back :-(
I tried all kinds of stuff, removing driver, installing libusb.dll, different timings etc …
The passgen still worked on WinExp but not on win7!

The solution i found was :
Use an USB-Hub (mine is a cheap one from Lo***Link)
Now its working again.

Hope this helps somebody else

Cheers Jan

andrea astretti:

Hi! I have a question about the circuit, i’d like to reproduce the password generator on my breadboard but i haven’t any 68 ohm resistor. Can i use a bigger one?
How can calculate the maximum value?
Thank you very much

Andrea

jokkebk:

Hi! I’m not sure what the limits are, but 48 ohms worked nicely, too. I wouldn’t try much lower values, but something around 100 ohms might work too. Exact value is not critical, but I doubt that something like 330 ohms will work very well anymore.

See also my recent post about a PCB that a person I know had designed for this: http://codeandlife.com/2012/10/22/usb-password-generator-pcb/comment-page-1/

jimmy:

can i not just buy one from you?i would appreciate it

jim

jokkebk:

Sorry, I don’t have any manufacturing capacity, and handling the ordering of parts, soldering, payment, shipping to interested parties, and possible support and returns issues is something that I’d rather not do, but rather focus on learning new stuff and writing about that in here (if I’d price my time, the password generators would also become prohibitively expensive, something like 40€ a piece). Of course, if you like the blog, you’re also welcome to donate via PayPal (donations over $10 get a free ATtiny2313 header PCB while they last :).

I recommend you to check out YubiKey, which is a commercial solution that’s in many ways superior (consumer-grade, more versatile) to the DIY solution if you’d rather like to buy a ready-made unit. And as said, Ben might still have boards if you have a solder iron and the parts (and ISP programmer) yourself.

jimmy:

all right men i understand, yes ofcourse i like your blog. but i’m just started so i dont know much stuff, that is why i also don’t know what a ATtiny2313 header PCB is. and also no what isp is. but thanks anyway for your reply and your link.
but if anyone else like to help me to learn stuff like that i would appreciate it and you’re welcome to reply

jokkebk:

Sure, didn’t mean to be rude either, just thought to explain in detail why not! :) If you are just starting, take a look at my V-USB tutorial, it’s rather beginner-friendly and contains some pointers to get you started. I can also recommend avrfreaks.net forums, they have a nice tutorial section. Welcome to the world of electronics!

jimmy:

I think this is a misunderstand because i didn’t thought that you where rude ;) so it’s okay. I defenetly wil take a look for that tuto’s. again thanks for the link, and i wish you the best with your blog

alex:

how would i change the pin configuration for the spark fun avr stick to work with this?

jokkebk:

If I recall correctly, AVR Stick has the D- USB data line tied to PB0 instead of PB1. Just modify usbconfig.h to reflect this pin configuration, recompile, and flash. Also, be sure to check the fuse settings, although they should be OK because the default firmware contains the V-USB temperature logger example, that also requires same crystal settings.

shandy:

thanks the tutorial…

can i write password to usb password generator manual with pc keyboard??

shandy:

thanks the tutorial..

i want write manual the password in usb password generator.
anyone can help , how to write password manually???

jokkebk:

Most straightforward way would be to use the ISP programmer that’s used to write the firmware to also write EEPROM, I’m sure there are examples out there if you google something like “avrdude write eeprom”.

Another way would be to change the firmware so that after a delay, it resets and shows itself as custom USB device and you have custom PC side SW to update the password. But I don’t know how that is done exactly myself, either.

dj_sa:

I was experimenting with Win-L to lock my computer when the key was plugged in. Ctrl-Alt-Del can be achieved similarly. See my website for details.

dj_sa:

I made mine respond to USB packets to change the stored password with the user inputs. You’d still need an ISP to programme the firmware in though. Check out Joonas’ latest blog for details.

Faisy:

Such a nice tutorial, just love it.

Andrew:

Nice tutorial and very helpful answers to questions. Thanks! My question is, I want to build one of these for the many passwords we have at work. I know the IT guys would lose it if they knew..but hey. So I need to use my password not a random one as for example to get the laptop off screen lock it’s always the same password..I am just friggin tired of typing it. So I need it to remember 3-4 passwords. Maybe use small buttons to select which pass to enter. Will that work with the tiny85 or do I need more space??
Thank you.

Beom su:

Hello..
I have a question.
When compiled with AVR Studio + Toolchain,
An error occurs.

C:\Users\computer\Documents\main\default/../main.c:160: undefined reference to `usbMsgPtr’
C:\Users\computer\Documents\main\default/../main.c:211: undefined reference to `usbMeasureFrameLength’
C:\Users\computer\Documents\main\default/../main.c:304: undefined reference to `usbInit’
C:\Users\computer\Documents\main\default/../main.c:319: undefined reference to `usbPoll’
C:\Users\computer\Documents\main\default/../main.c:323: undefined reference to `usbTxStatus1′
C:\Users\computer\Documents\main\default/../main.c:325: undefined reference to `usbSetInterrupt’

I’ve included usbdrv.h, but an error occurs.

Sentence is strange
Please understand.

Andrew:

Can I just take the main.c and open in a text editor and then paste it into a new sketch? I am using a MAC. So it seems ok , but the include lines

#include
#include
#include
#include
#include

#include “usbdrv.h” Are these libraries I need to add into my library folder? I don’t have an avr/ directory do I need to modify those first few lines?
I am trying to get a handle on this , your help would be great.
Thanks.

Eldon:

Hello, for all time i used to check blog
posts here in the early hours in the break of day, for the reason that
i enjoy to find out more and more.

miko:

Hi, just done mine !
Working but as i’m in an AZERTY os, there is a mismatch with ascii table and it output qwerty to me.

The ascii translation is done “by hand” ine the software or is there a keyboard description flag to says it ouput qwerty/azerty ?

Where should i look before doing ascii translation in the firmware ?

thanks =)

miko:

Maybe i’m using wrong compilation options ?
(i’m not using your makefile, since I imported your project in eclipse-avr successfully)

BinGoon:

I made a korea version avr password generator.
Thank you Who helped

I can’t speak english

Though Thank you
Who teach English for me. ^_^;

BinGoon:

I’m a high school student.
blog : mnco.tistory.com/46

Peter:

Can you help please I want to make this USB. But my Windows 7 Home Premium 64bit does not see any usb at the windows sign in.Do you know why this is, in your video you are using a window o/s and you don’t have any problems
Thanks

jokkebk:

I also did the original project with Win7 64bit, so it shouldn’t be a problem. However, the project is quite susceptible to HW problems, so long wiring, bad solder joints, too heavy zeners, etc. can cause it not to work. Also, make sure you have correct fuses set so the calibration works. You may want to read earlier comments, I think I’ve outputted almost exchaustive list of things to try in there. Good luck in the project!

Stoqn:

Will this work with windows 8

Littledog:

Work fine with windows but not work with MacOS

jihadjiinee:

hello, i have developed a program to enter passwords for whatever program,app or website you want when you plug in a usb but i have yet to master a piece of code to do this from logon screen. i am useless when it comes to this device, i have tried about 15 times and spent over $100 dollars for this build, would it be possible to buy one or two off u that’s already setup and working, name ur price money is no factor to me.please reply or email me asap as the eta i have on this program has been pulled back three times and the deadline is december. please help me

jokkebk:

Hi! Sorry to hear about your problems. I’m not sure if I can help – I only have 1 compact device (the one shown in the article) and it is burned in with the firmware that only sends the password. Do you just need a working prototype HW on a protoboard, or a device that can log in already, or a device that interoperates with PC software, or something else?

Anyways, you can e-mail me at jokkebk / codeandlife.com if you’re interested in the (possibly very limited) help I can give. :)

jokkebk:

Very nice, congratulations! You seem to have gotten the ENTER key also working well, and the PCBs look nice. Oh and I’m sure you will learn English just by reading interesting stuff, I know I did. :)

PS. Removed a previous duplicate comment of yours, so now there’s only one.

jokkebk:

I think the operating system usually does translation (you have made the setting somewhere in internationalization options), or then the keyboard makers of AZERTY keyboards just have a different firmware in place in the keyboards, because as far as I know, nothing will tell the device if the O/S will view it as qwerty, azerty, dvorak etc. one.

Because the device cannot know which will it be, it’s quite O/S and setting specific which keys will actually be outputted. So you’ll need to make custom translation routines for your device, and it won’t work the same with someone who has O/S expecting QWERTY keyboards… It’s likely a design feature in USB spec – the device is stupid and just sends keys, and the O/S interprets them as it sees fit.

jokkebk:

The easy way out is to have all V-USB files in same directory, but it’s slightly more elegant to have them in a sub-folder, and then just add that directory to include directories (and add the necessary C and assembler files to your project) in the development tool you are using. With avr-gcc the include directory means just adding -Iusbdrv to command line options.

jokkebk:

Those are defined in V-USB source files – you need to compile them, your own code, and link all together. This can be done in AVR Studio by adding several .c and .S files to a single project. There’s mention which files are needed (usbdrv.c is one) in the tutorial.

Martin:

Hi, nice device. However I tried it on Linux and because of some problems with CAPS LOCK LED I could not generate password. So I wrote small script, witch make automatic LED turn on and off.

#!/bin/bash
# Script, that automaticly make "password generation" process

setleds -D +caps;
sleep 0.5;
setleds -D -caps;
sleep 1; # Passwd generator create new passwd and write it to console

# Now toogle CAPS LOCK
for i in {1..5}
do
setleds -D +caps;
sleep 0.3;
setleds -D -caps;
sleep 0.3;
done

echo ""

And one more thing. With avr-gcc-4.6 make process fail. It is because of missing “const” before PROGMEM macro. After fixing that everything works.

jokkebk:

Great information, thanks for sharing!

Martin:

Hi again,
I’ve some notes for Linux systems, hopefully it helps to someone.
1) In console (Ctrl+Alt+Fx) Caps Lock works as expected
2) In KDE there are some problems -> solution: in function caps_toogle() change number 4 in if condition to 6. and before main loop add this one:

#define DELAY_AFTER_INIT 1000
volatile int j;
// Small delay before sending data (1000ms)
for(j=0 ; j<DELAY_AFTER_INIT ; j++)
{
wdt_reset();
usbPoll();
_delay_us(800);
}

while(1)....

3) When function usbDeviceDisconnect(); is moved to first line in main() and then this code is removed

usbDeviceDisconnect(); // enforce re-enumeration
for(i = 0; i<250; i++) { // wait 500 ms
wdt_reset(); // keep the watchdog happy
_delay_ms(2);
}

Everything works nice under Linux and Windows, so why is there this code?
4) Keyboard layout – when use different keyboard layouts there can be problem with numbers and ‘-‘ or ‘_’ (in CZ keyboard instead of number there are special characters). So there is my solution:

#define ONLY_LETTERS 1 /* If we want generate only letters. Else
* also generate "numbers" and "-" or "_".
* This option is useful when user use
* different keyboard layout. When is this
* option on, then generated password contains
* only letters (exclude y,Y,z and Z)
* 1 - only letters
* 0 - and "numbers"
*/

uchar generate_character() {
uchar counter = TCNT0 & 63;

if(counter < 26)
{
// If user want keyboard independent password
#if ONLY_LETTERS == 1
// If 25 'z' or 'y'
if(counter == 25 || counter == 24)
{// Change to 'x'
counter = 23;
}
#endif
return 'a' + counter;
}
else if(counter < 52)
{
#if ONLY_LETTERS == 1
// If 51 'Z' or 'Y'
if(counter == 51 || counter == 50)
{// Change to 'X'
counter = 49;
}
#endif
return 'A' + counter - 26;
}
// Test if user wants only letters
#if ONLY_LETTERS == 1
else
return 'q';
#else
// Or even "numbers", "-" and "_"
else if(counter < 62)
return '0' + counter - 52;
else if(counter == 62)
return '-';
else
return '_';
#endif
}

When ONLY_LETTERS is enabled then ,because of security reasons, user should increase a little bit PASS_LENGTH.

Nuno:

Hello,

I’ve found this and just this this is super great.
I’m now considering to build one of my own (even having an YubiKey) but I need to know what is the “USBtiny programmer” that you refer in the code…

Can you tell me more details on the hardware needed to program the device or upload the HEX to the device?

Thank you in advance!!

jokkebk:

USBtiny is Adafruit’s inexpensive AVR programmer (just google it) which is one way to flash the firmware in the ATtiny85 chip. Another way is to use Arduino (http://codeandlife.com/2012/03/21/using-arduino-uno-as-isp/ and http://arduino.cc/en/Tutorial/ArduinoISP). There are of course tons of others. If you plan to do much AVR stuff, a dedicated programmer is useful, otherwise Arduino works well enough, and you can do lots of stuff with Arduino alone, too.

Nuno:

Hi,

Thanks for the reply. I’ll give this a try but will wait 1 or 2 weeks for a friend that has both AVR and PIP programmers and will let me use the AVR one.
And most important, he also know about this subject as I am a total newbie.

I’ll get back if something gets burn… :)

Cheers!

kubix:

hello,

is what can you buy one without it is made?

thank you

Joonas Pihlajamaa:

You may want to check out Yubikey (just google them), they build a similar product that looks nice and has even extra features.

nacho:

Hello I love the project but not as connections go, do not see anything good in the pictures, you can upload the schema to do so?

many thanks

Joonas Pihlajamaa:

I’m sorry I cannot quite understand what you are asking. There is a schematic showing the connections, and a veroboard picture with textual explanation of one possible component placing. Unfortunately the connections are cramped so tight that I’m not sure a drawing with connections would be much easier to understand. :( You might also want to take a look at the higher res version of the project: http://codeandlife.com/wp-content/uploads/2012/03/detail-1.jpg

Joonas Pihlajamaa:

Thanks for sharing!

MReza:

Hi,
this is a great tiny project :)
I have a Question and that’s: can I use ATtiny13 instead of tiny45/85?
thanks,

Joonas Pihlajamaa:

The firmware is over 2 kB, I’m not sure but I think 13 would have only 1 kB.

AleXXX:

Sorry from my English. I collected device.Flashed Fuse-bits. Windows recognizes the flash drive as an unknown device. OS Windows 7. Controller – attiny85V. Firmware on the programmer Phyton, file from the archive – main.hex .

AleXXX:

Hello

I soldered your USB password generator, but Windows recognizes the flash drive as an unknown device. I can not understand what the problem is.

I flashed Fuse-bits. OS Windows 7, XP. Controller – attiny85V. Firmware on the programmer Phyton, file from the archive – main.hex .

Please, help me.

Joonas Pihlajamaa:

The V-versions are usually limited to 10 MHz, where the password generator requires 12 MHz. You might have better luck with ATtiny85 without the V. I’d try on a breadboard first before soldering. Hope you get it working!

AleXXX:

Сhanged controller. Windows recognizes the flash drive as an unknown device. What else can advise?

theycallmeshua:

hello, im also having a similar problem as alexxx, as where windows 7 and vista both see the usb as an unrecognized usb device. has this been tested in these more current OS. im using a tiny84 20pu. and this is driving me crazy. i have some modifications id like to make after i get this working but cant past the “getting it working” part lol.

theycallmeshua:

i meant tiny85

Joonas Pihlajamaa:

I developed the gadget with Win7 64bit so it should work well with that. The USB keyboard spec hasn’t changed much in past 10 years so everything from WinXP should work. In OS X the caps lock works differently so it cannot be used there.

Most “unrecognized usb device” problems in my USB tutorials section have turned out to be electrical problems (too heavy zener diodes, different pull-up resistor strengths for some USB buses, wrong pins used, solder problems, etc.) so that would be my first guess. Using a breadboard and possibly following my USB tutorial to build this thing gradually might help, as you would be adding components one by one and solder problems are eliminated. But I have no 100 % certain answers available, unfortunately. :-d

Joonas Pihlajamaa:

See my comments to theycallmeshua below, step-by-step construction on a breadboard first is the best recommendation I can give, as you can separate the “do I have working components and is everything wired correctly” part and the “did I solder the device OK and am I sure nothing is touching anything it shouldn’t” :)

theycallmeshua:

thanks, ill keep looking into it. could be my diodes i guess but it shouldnt be. thanks for you help. i originally was working on a breadboard but it kept connecting and disconnecting rapidly so i moved to a soldered board. which caused that to stop but its still unrecognized. ILL KEEP WORKING! i havent given up yet.

AleXXX:

I took a photo of my device. Checked all the diodes and resistors, everything is normal. Windows recognizes the flash drive as an unknown device.
http://iscr.ru/1401440939/

AleXXX:

What may be missing some drivers. Therefore, the computer sees the device as unknown. What drivers should be installed?

AleXXX:

Dear Joonas Pihlajamaa, can be laid out last revision of your project contains any error. Otherwise, what else can you explain the problems that occur not only at me one last time. Please refresh the files.

Joonas Pihlajamaa:

The picture is quite blurry.

Which way is your connector, GND in bottom or top? If GND is bottom, it looks like you have wire from GND to RESET pin, which will keep RESET at 0V and cause the device never to boot up.

For some reason, bottom pin (GND still?) is connected via (58ohm?) resistor to ATtiny GND, this would limit the current to device and probably cause it not to work. Or maybe it’s not connected to the GND at all?

I don’t see where zeners are connected on the bottom of the board. Actually I don’t know how your perfboard holes are connected to each other, if at all, so it’s impossible to check connections from the picture.

No connections apart from VCC pin go to right side of ATTiny on top, do you use the same pins for D+ and D- as in my example? In that case, there should be connections there, too.

To summarize, it’s hard to say anything from the picture, and also I’m not sure I would have the time to debug it, an electronics forum might have more eyes and people with lots of time at their hands.

Joonas Pihlajamaa:

The USB HID drivers should be available in every operating system, so no additional drivers should be needed here (in contrast with my USB tutorial device which does need drivers)

Joonas Pihlajamaa:

Dear Ale XXX, I’m not sure what you are saying? If there are several people (including me) that got it working. If you have an improved schematic that does work better than the version presented, please share.

AleXXX:

I meant that the files could be wrong, maybe in the final firmware file main.hex. Remake it please.

AleXXX:

I meant that the files could be wrong, maybe in the final firmware file main.hex. Remake it please.

AleXXX:

Found punched 3V6. Added 2 resistors 68 Om. The breakdown is fixed, but the flash drive is still not detected. Below is a photo of the front and rear.
http://iscr.ru/1403261886/
http://iscr.ru/1403261939/

ep:

sir how to change the password means what is logic behind this.
if i change the password as you told then which logic is used to change password.

Joonas Pihlajamaa:

The device measures the amount of time between caps lock presses – human reflexes are quite random so you can get several bits of true randomness with each press. See generate_character() comments in main.cc for details.

omer:

Hello,

I made it! Thank you, it works well with Windows XP and windows 7, it did not work with one of windows 8 but i cant tried with another windows 8 machine. when it comes to Linux (ubuntu 14.10) first two digit of password gone missing. It types 8 digits. why this behavior? i checked code what may encounter this issue but couldn’t find problem.

Joonas Pihlajamaa:

It might be that Linux has a longer delay between the “keyboard” being recognized and starting to accept keypresses, so the first two characters are ignored. A longer delay would correct it if that is the case.

omer:

I tried at console and it just worked correctly. First two digits gets lost at UNITY desktop environment (X window maybe).

Jhin:

i am trying to do this project but im getting this error.. do you know where i got it wrong?

https://drive.google.com/file/d/0B6GhTg-puxGrQkxCX0M3UE53QnM/edit?usp=sharing

hope you can help me..
thank you

Joonas Pihlajamaa:

Seems like usbconfig.h is not found. Which dev environment uses the .inc files? Arduino? I would make sure usbconfig.h is in the usbdrv directory, and if required by the dev environment, usbdrv is added to include path (and the .c and .S files to project)

link:

Please let me know if you’re looking for a article writer for your weblog.
You have some really good posts and I believe I would be a good asset.
If you ever want to take some of the load off, I’d absolutely love
to write some material for your blog in exchange for a link back to
mine. Please shoot me an e-mail if interested. Many thanks!

Gary:

Extremely fascinating and useful tips. Saved as a
favorite ! Appreciate the amazing read.

Joonas Pihlajamaa:

Thanks! Also visited your blog, good work! By the way, never write short comments like this that have no context to the post you are commenting, I get 10 of these a week and all are just spam pointing to goldonlinenow.ch or something. Even with the sensible blog in your URL I was still only somewhat sure this might not be spam. :)

nimpoz:

I made this awesome thing for university project. But I have some problem. I test by plug it with many labtops but just a few laptop that the USB-driver can install successfully.
How can I solve this problem ? I am stuck in this black hole for 2 weeks.

Ps. I flash ATtiny85 by using HEX file you give in your project by setting fuse in PLL mode.

Thank you very much !!

Amirreza:

Thank youuuuuuuu for your awesome article.
I’ll try it but can you say which attiny85 you’ve used? because I’m new in electronic and it’s a bit hard for me to understand these things.

Joonas Pihlajamaa:

I think they only make one model of the ATtiny85. :) For Attiny2313 Atmel has both normal and 10PU version (2313V), and the latter is limited to about 10 MHz – for those, the normal version is the one you should get.

Upamanyu:

I have been trying to compile the C file that you provided in the source package. But I have been getting these errors.

When I try to compile with the version of ‘usbdrv’ you provided, it gives me this error: http://cl.ly/image/3J1k2P1p0K3Z/error%201%20-%20old.png

And when I try to compile it with the newest version of ‘usbdrv’ downloaded from the V-USB website, it gives me this error: http://cl.ly/image/3J1k2P1p0K3Z/error%201%20-%20old.png

Please help.

Upamanyu:

Sorry the error with the new compiler is: http://cl.ly/image/253A022v0U1G/error%202%20-%20new.png

Miad:

Hoooray!
Finally!I get it working after three days.
Here is the result:
GMKjkQcLjQ
GMKjkQcLjQ
Starting generation…
cLm9IqJSCT
cLm9IqJSCT
^_^
———–THERE IS A BUT!——————
But! when I touch the circuit(It’s on bread board).It disconnects and reconnects a few times (windiwos diling! sound) and then doesn’t work after.but when I touch it again and mess around with it, it works perfect!.
I don’t know If you see what I’m trying to say or not.
Anyway thank you for the great tutorial :)

Jonas Sam:

Hello !

Please tell me how to adapt the code to have azerty layout please !!

Thanks !!!!

Joonas Pihlajamaa:

The password generator sends a random password, does it matter if instead of wHDcQ3 it is zHDcA3? And as I said in the other reply, it might be that USB keycodes are the same regardless of your keyboard layout. If not, a quick google search probably knows more about the matter than I do. (e.g. “USB HID keyboard layout” or “azerty usb keycodes” etc.)

hyun:

hello
i try make it. but it doesn’t work. i used attiny45-20pu.
and i using avr studio 4.19
i connect usb to pc but pc can’t recognize this device
i setup fuse bit high is 0xDD, low is 0xE1.
main.hex is run only attiny85??
please reply about this problem. i need your help.

Joonas Pihlajamaa:

I’d think the firmware would work as well in 45 as in 85, as they only differ in flash memory amount. Often in similar problems there has been some hardware glitch, so double-checking that side might help. Good luck in your project!

live-cd:

Thanks designed for sharing such a pleasant idea, piece of writing is pleasant, thats why i have read it completely

kkis:

hello! i want to change this program.
input password not automatically.
i want using alt key.
if i push alt key three times, now enter password.
but i don’t know how to use this method.
i need you help.
please show me your solution.

Joonas Pihlajamaa:

A USB keyboard does not receive alt-keypresses from another device, only caps lock, num lock and scroll lock, so you are limited to those three.

You can see the code for example on how to trigger password regeneration on four caps lock presses, you should be able to adapt that to trigger password input (for example, regeneration with num lock, input with caps lock).

kkis:

Thank you for your answer.
But i dont know hid device how to get information about push caps lock key. Also how to adapt num lock key?? please give me some example. I want caps lock is regenerate pw. And numlock is input. I need you help.

Joonas Pihlajamaa:

The password generator example code already gets information from caps lock key, so you can just read the example code and adapt from that. Also, you can find another post in this site that has the receiving code with ready-made constants for caps, scroll and num lock:

http://codeandlife.com/2012/06/18/usb-hid-keyboard-with-v-usb/

andreas:

Cool article about attiny85 HID password logger http://dptechnology.jimdo.com/projects/hidhid/

Chuck:

For many obvious reasons, this is marketable. If you don’t have a patent, get one and wile we are on that subject you may want to check this site out “https://www.kickstarter.com/”. I am in no way affiliated with kickstarter but I think they would be able to get such a project started. The primary reason I am responding to this is that I would like to ask…

May I please buy one from you?

Joonas Pihlajamaa:

Yeah it’s a nice hack. However, Yubikey has been manufacturing a similar one (less DIY of course) for a while, and from what I understand it is smaller and a lot more robust:

https://www.yubico.com/products/yubikey-hardware/yubikey4/

I only have the one in the picture and the other with an actual PCB but no cover, I think you’ll be better served with the Yubikey than my fragile soldering attempts :)

Dan:

In Vista works. In Windows 10 not works. Why?

FredouilleZeus:

Hi,
Here the link to a video for an USB key for enter profil and password for Windows, gmail, linkedIn, … with an Attiny85 Digispark.
https://youtu.be/pNGhR91GGVM

Ömer:

Hello,

I want to upload the program, but I have not an Atmel programmer. So can I do it with an Arduino ISP ?

Joonas Pihlajamaa:

Yes you can, I wrote a post about using Arduino some years ago, that or google will be your friend. :)

Ömer:

Hey,

thanks for reply. Now I have an problem. I have done everything, but know windows dont recognize the device. What could I do?

thanks.

Uthaya:

Hi i have Digispark Attiny85 USB,

I tried below code,

Keyboard.print(“password “);
Keyboard.sendKeyStroke(“KEY_ENTER “);

but the output is keepon continuing……
How can i stop with one time.

Joonas Pihlajamaa:

It probably sends that in some kind of loop. If you are running the loop yourself, just make “one-time” variable:

char pwSent = 0; // initially false

...

while(1) { // the loop
if(!pwSent) {
Keyboard.print(...);
pwSent = 1; // true
}
...
}

If you run Arduino-like code:

char pwSent = 0;

void loop() {
if(!pwSent) {
// same code as in while-loop
}
}

Carlo:

Hello, I have a problem! It operates at 50% of the time the other does not recognize my device. I double checked all hardware etc is all ok
Any suggestions? It can be for the socket that I put to ATtiny?
Thanks Carlo

vidhya:

I am getting the errors detailed at the bottom of this post.
Arduino: 1.6.11 (Windows 10), Board: “ATtiny25/45/85, ATtiny85, External 16 MHz”

sketch_dec27a:24: error: variable ‘measuring_message’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

PROGMEM uchar measuring_message[] = “Starting generation…”;

^

sketch_dec27a:25: error: variable ‘finish_message’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

PROGMEM uchar finish_message[] = ” New password saved.”;

^

sketch_dec27a:39: error: variable ‘usbDescriptorHidReport’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {

^

sketch_dec27a:39: error: conflicting declaration ‘char usbDescriptorHidReport [63]’

In file included from C:\Users\admin\Desktop\usb_tiny85_passgen\sketch_dec27a\sketch_dec27a.ino:15:0:

C:\Program Files (x86)\Arduino\libraries\usbdrv1/usbdrv.h:477:6: note: previous declaration as ‘const char usbDescriptorHidReport []’

char usbDescriptorHidReport[];

^

exit status 1
variable ‘measuring_message’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

Joonas Pihlajamaa:

Hi! The examples are a bit dated, I think AVR libraries and compilers may have changed a bit since the writing of this article. Unfortunately I don’t have time to upgrade the code so you’d need to google around to solve the issues.

However, I noticed you mentioned Arduino in your message, I’m not sure you can compile this with Arduino, avr-gcc and using ‘make’ from command-line would likely work a lot better.

vidhya:

which IDE should I choose to compile this USB password generator code.

Alan:

Hello Friend!

Your posts are great, especially this one. I have a query regarding this project, could you explain how buildReport () works? That is, how do you send the “pressed” keys to the PC? I would be more than grateful if you help me understand.

Many thanks!

Joonas Pihlajamaa:

It’s essentially a state machine (you can see my tutorial on C state machines http://codeandlife.com/2013/10/06/tutorial-state-machines-with-c-callbacks/ for reference), that starts from the beginning of password buffer, then every other call it sends key down message for next password character, and every other call keyup, and advances the pointer that points to the next character to be sent from the buffer. So if the buffer was “123”, it would send “1 down”, “1 up”, “2 down”, “2 up”, “3 down”, “3 up” and after that just idle. Hope this clarifies!

Bluemoon:

I think the problem is with driver in windows 8 and 10

resolve the third party inf problem then install the driver
it will work

Niel Nielsen:

I have made some changes to make it compile on never avr-gcc versions
https://github.com/nieldk/usb_tiny85_passgen

John:

I’ll try it but can you say which attiny85 you’ve used? because I’m new in electronics and it’s a bit hard for me to understand these things.

Aminul Islam:

Good Job Bro keep It up..

Aminul Islam:

Download and watch any movies or video on https://www.download-movie.ml

flat stomach:

The best protine sames are the lean ones – egg whites, lean meat, turkey, chicken, and fish.
If sometimes into good condition is important to
you personally then due to the fact will not likely enable you to achieve
that. The results were dried out skin and mental fuzziness not to mention cravings for fatty
foods.

fatemeh.arjmand4511:

Thanks! , good work! By the way

sexykinkycouple20:

Everything is very open with a really clear clarification of the issues.
It was definitely informative. Your website is very useful.
Thank you for sharing!

isrever:

Hi, i want to try to compile the source myself, to get an understanding of avr-gcc etc, i tried to use avr-gcc. but got some errors. just wondering if you could possibly help out. thanks
https://imgur.com/a/ephm7Bh
also thanks for taking the time to make this

isrever:

Figured it out, didint add all the .o files when i c tried to create the .elf
in the end this worked for me. incase anyone else is stuck using avr-gcc, though i used it on windows

avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -c main.c

avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 usbdrv/usbdrv.o usbdrv/oddebug.o usbdrv/usbdrvasm.o main.o usbdrv/usbconfig.h -o main.elf

avr-objcopy -j .text -j .data -O ihex main.elf main.hex

Though if you want to change the device name, serial number etc.
you have to edit. usbconfig.h and then recompile into usbdrv.c to usbdrv.o

avr-gcc -Wall -Os -Iusbdrv -mmcu=attiny85 -DF_CPU=16500000 -c usbdrv.c