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. 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.

235 Comments or trackbacks to DIY USB password generator

Dimitar Ivanov:
May 3, 2012 at 19:37

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 ?

reply

jokkebk says:
May 3, 2012 at 22:08

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.

reply

Dimitar Ivanov says:
May 4, 2012 at 22:17

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

reply

jokkebk says:
May 5, 2012 at 8:24

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.

reply

Dimitar Ivanov says:
May 10, 2012 at 16:23

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

reply

jokkebk says:
May 10, 2012 at 22:48

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

Dimitar Ivanov:
May 10, 2012 at 18:10

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

reply

jokkebk says:
May 10, 2012 at 22:49

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?

reply

Dimitar Ivanov says:
May 11, 2012 at 9:32

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.

reply

Dimitar Ivanov says:
May 11, 2012 at 9:33

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

reply

jokkebk says:
May 11, 2012 at 9:55

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”

reply

jokkebk says:
May 11, 2012 at 10:00

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 says:
May 11, 2012 at 10:49

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

jokkebk says:
May 11, 2012 at 12:31

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:
May 12, 2012 at 22:10

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

reply

jokkebk says:
May 13, 2012 at 12:20

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.

reply

Dimitar Ivanov says:
May 13, 2012 at 14:06

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

reply

Prough:
May 21, 2012 at 12:28

Can you make a tutorial for dummies?

reply

jokkebk says:
May 21, 2012 at 12:33

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. :)

reply

Joeri:
June 12, 2012 at 0:22

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

reply

jokkebk says:
June 12, 2012 at 8:47

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.

reply

michael:
June 15, 2012 at 7:51

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

reply

jokkebk says:
June 15, 2012 at 9:34

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.

reply

michael says:
June 16, 2012 at 8:53

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

reply

michael says:
June 16, 2012 at 9:30

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/

reply

jokkebk says:
June 18, 2012 at 17:50

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 says:
June 19, 2012 at 23:41

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:
June 20, 2012 at 20:02

Hi jokkebk,

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

reply

jokkebk says:
June 20, 2012 at 21:43

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.

reply

treo:
June 25, 2012 at 20:27

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 :(

reply

jokkebk says:
June 25, 2012 at 22:14

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.

reply

treomika:
July 12, 2012 at 15:29

what should I use;

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

?

thanks

reply

jokkebk says:
July 12, 2012 at 15:47

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…

reply

Hajoe:
August 7, 2012 at 6:02

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.

reply

jokkebk says:
August 7, 2012 at 12:33

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!

reply

Hajoe says:
August 13, 2012 at 20:20

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?

reply

jokkebk says:
August 15, 2012 at 21:37

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!

reply

KevlarGibs:
August 20, 2012 at 23:41

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

reply

carlos:
August 29, 2012 at 17:57

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

reply

jokkebk says:
August 31, 2012 at 11:47

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.

reply

carlos:
September 4, 2012 at 23:19

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?

reply

jokkebk says:
September 6, 2012 at 11:56

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.

reply

Toaster_Chicken:
October 9, 2012 at 19:38

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.

reply

jokkebk says:
October 9, 2012 at 23:55

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)

reply

midijay:
October 10, 2012 at 11:52

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.

reply

jokkebk says:
October 10, 2012 at 12:32

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.

reply

dj_sa says:
December 2, 2012 at 8:29

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.

reply

dj_sa says:
December 2, 2012 at 8:30

My website http://www.indiegogo.com/aladdin-key

reply

Jan:
October 12, 2012 at 13:46

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

reply

andrea astretti:
October 23, 2012 at 9:03

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

reply

jokkebk says:
October 23, 2012 at 9:12

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/

reply

jimmy:
October 27, 2012 at 19:27

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

jim

reply

jokkebk says:
October 29, 2012 at 13:24

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.

reply

jimmy says:
October 30, 2012 at 20:07

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

reply

jokkebk says:
October 30, 2012 at 23:33

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!

reply

jimmy says:
October 31, 2012 at 20:11

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:
November 6, 2012 at 1:07

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

reply

jokkebk says:
November 6, 2012 at 22:14

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.

reply

shandy:
November 22, 2012 at 13:12

thanks the tutorial…

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

reply

shandy:
November 22, 2012 at 13:16

thanks the tutorial..

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

reply

jokkebk says:
November 22, 2012 at 13:55

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.

reply

dj_sa says:
December 2, 2012 at 8:37

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.

reply

Faisy:
December 8, 2012 at 19:16

Such a nice tutorial, just love it.

reply

Andrew:
December 31, 2012 at 19:58

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.

reply

Beom su:
January 4, 2013 at 6:29

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.

reply

jokkebk says:
April 20, 2013 at 16:57

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.

reply

Andrew:
January 8, 2013 at 18:29

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.

reply

jokkebk says:
April 20, 2013 at 16:52

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.

reply

Eldon:
January 23, 2013 at 8:46

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.

reply

miko:
January 31, 2013 at 12:47

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 =)

reply

miko says:
January 31, 2013 at 12:50

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

reply

jokkebk says:
April 20, 2013 at 15:01

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.

reply

BinGoon:
March 1, 2013 at 13:09

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. ^_^;

reply

BinGoon:
March 1, 2013 at 13:16

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

reply

jokkebk says:
April 20, 2013 at 14:05

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.

reply

Peter:
March 5, 2013 at 14:29

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

reply

jokkebk says:
March 6, 2013 at 8:55

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!

reply

Stoqn:
March 10, 2013 at 19:54

Will this work with windows 8

reply

Littledog:
March 12, 2013 at 5:26

Work fine with windows but not work with MacOS

reply

jihadjiinee:
March 23, 2013 at 16:30

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

reply

jokkebk says:
April 20, 2013 at 12:52

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. :)

reply

Martin:
June 7, 2013 at 15:24

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.

reply

jokkebk says:
June 9, 2013 at 14:29

Great information, thanks for sharing!

reply

Martin:
July 3, 2013 at 12:55

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.

reply

Joonas Pihlajamaa says:
December 10, 2013 at 9:52

Thanks for sharing!

reply

Nuno:
July 18, 2013 at 23:06

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!!

reply

jokkebk says:
July 19, 2013 at 10:04

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.

reply

Nuno says:
July 19, 2013 at 18:39

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!

reply

kubix:
October 23, 2013 at 1:23

hello,

is what can you buy one without it is made?

thank you

reply

Joonas Pihlajamaa says:
October 23, 2013 at 12:44

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

reply

nacho:
November 26, 2013 at 20:23

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

reply

Joonas Pihlajamaa says:
November 27, 2013 at 10:40

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

reply

MReza:
January 31, 2014 at 2:06

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

reply

Joonas Pihlajamaa says:
January 31, 2014 at 8:26

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

reply

AleXXX:
May 5, 2014 at 12:30

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 .

reply

AleXXX:
May 8, 2014 at 10:23

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.

reply

Joonas Pihlajamaa says:
May 8, 2014 at 10:45

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!

reply

AleXXX says:
May 22, 2014 at 15:29

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

reply

Joonas Pihlajamaa says:
May 28, 2014 at 10:59

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” :)

reply

theycallmeshua:
May 25, 2014 at 4:31

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.

reply

theycallmeshua says:
May 27, 2014 at 22:03

i meant tiny85

reply

Joonas Pihlajamaa says:
May 28, 2014 at 10:56

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

reply

theycallmeshua says:
May 28, 2014 at 21:18

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.

reply

AleXXX:
May 30, 2014 at 12:13

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/

reply

Joonas Pihlajamaa says:
June 17, 2014 at 11:09

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.

reply

AleXXX:
June 6, 2014 at 14:42

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

reply

Joonas Pihlajamaa says:
June 17, 2014 at 11:10

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)

reply

AleXXX:
June 17, 2014 at 10:54

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.

reply

Joonas Pihlajamaa says:
June 17, 2014 at 11:12

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.

reply

AleXXX says:
June 17, 2014 at 12:09

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

reply

AleXXX:
June 17, 2014 at 12:10

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

reply

AleXXX:
June 20, 2014 at 14:04

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/

reply

ep:
June 27, 2014 at 14:59

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.

reply

Joonas Pihlajamaa says:
July 15, 2014 at 13:13

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.

reply

omer:
August 11, 2014 at 18:53

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.

reply

Joonas Pihlajamaa says:
August 12, 2014 at 9:18

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.

reply

omer says:
August 14, 2014 at 18:14

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

reply
arrow Older Comments

Leave a Reply

Your e-mail address will not be published.


three − 2 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>