Navigate

Check these out

Tag: V-USB

Happy New Year 2016! After a long hiatus in electronics, I have been quite busy in the last month or so. I have a bigger (USB MIDI related) project posting coming up, but just wanted share a small nugget already.

I ordered a big chunk of things recently from Adafruit shop and Sparkfun. Among them was the lovely Adafruit Trinket (which actually came as a free bonus because I spent way too much on black friday :).

Now I am planning a project which involves transforming the very compact, but already USB-enabled Trinket into a USB MIDI device. However, there are two problems:

Adafruit examples for USB come in Arduino form

There are no USB MIDI examples

I somewhat dislike the high-level Arduino environment in cases where low-level performance is needed (and the V-USB implementation is one of those places), and for my later MIDI part, I will need fine-grained control to juggle serial communication and USB. Also, all USB MIDI examples are on “bare metal”, so the Adafruit example Arduino code would require deeper knowledge of Arduino inner workings than I have.

I’ve been quite busy with work and had a few fully booked weekends, so no updates in a while. Well, it’s going to change now, as I have two more updates in the pipeline already! The first one is an interesting project that’ll surely interest those that have read my USB tutorials: Alvin Chang has started a USB password generator project at indiegogo!

Mr. Chang’s project is inspired my USB password generator hack, and builds upon the (GPL licensed) codebase it also used. Many people have expressed the desire to get the USB password generator as a ready-made device, so if you’re one of those, check out the project and decide yourself if you want to participate funding in the Aladdin key project:

There still seems to be a lot of traffic to my V-USB tutorials, so I thought I’d write a short follow-up post on USB keyboards. I already did a USB HID mouse post earlier, so you might want to check that out to understand a bit about HID descriptors and associated V-USB settings (in short, human interface devices send a binary descriptor to PC telling what kind of “reports” they send to the host on user activities).

As a basic setup, you’ll need a working V-USB circuit with one switch and one LED attached. Here, I’m using ATtiny2313 with the LED wired to PB0 and switch to PB1. The ATtiny is using 20 MHz crystal, so if you’re following my USB tutorial series and have that circuit at hand, remember to change that frequency in usbconfig.c before trying this out. Note the cool breadboard header I have, there will be more posts about that one to follow soon!Continue reading USB HID keyboard with V-USB

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:

I promised to commenter Marek to post an example of using usbFunctionRead() to return larger amounts of data. So building upon the ATtiny85 version we made in last part, let’s add one more command to usbtest.exe:

One guy at Hack a Day remarked on the long wire runs in my V-USB tutorial breadboard setup. So I thought I’d build upon the part 4 of the tutorial but modify the setup a bit to run the AVR at 5 volts and use zener diodes to drop D+/D- voltage, thus eliminating the need for a regulator. And why not stop there. ATtiny45 and ATtiny85 are smaller than ATtiny2313 and have an internal oscillator that can be calibrated to provide 16.5 MHz clock, accurate enough for V-USB to do its magic. I challenge anyone to drastically shorten these wire runs!

All right. Now that we got the basic USB code working in part 3, it’s time to wrap things up in this tutorial series. This fourth section will explain how to send data from your device to PC and also the other way around. I may later do a fifth part on how to make a USB HID device like a keyboard or mouse, so if you haven’t already, I’d recommend subscribing to the RSS feed to get updates.

Sending data from device to PC

If you look carefully at our command-line client code, you probably noticed that the control messages sent to toggle the led are of type USB_ENDPOINT_IN and we have a 256-byte buffer in place to receive any data the device sends. So far we have not received any data and the return value stored in nBytes has been zero. Let’s change that.Continue reading AVR ATtiny USB Tutorial Part 4

This is the third part of my USB tutorial for ATtiny2313 and V-USB library. In the second part we got the breadboard setup more or less covered, and now is the time for actual code! This will most likely be the longest of the three parts, so let’s get started.

Adding V-USB as a part of your project

Unzip the archive and copy the usbdrv subfolder to your project folder (the whole folder, not just contents). Go to the subfolder and make a copy of usbconfig-prototype.h with the name usbconfig.h. Locate the #define lines for IO port and port bits and clock rate, and update them as necessary to reflect our configuration where D+ is in PD2 and D- in PD3 and clock rate is 12 MHz:

This is the second part of my USB tutorial for ATtiny2313 and V-USB library. In the first part we learned how to get 3.3V from USB to power our circuits. In this part, we will expand our setup with following parts:

Larger breadboard and additional jumper wires

ATtiny2313

12 MHz crystal oscillator

Two 27 pF ceramic capacitors to stabilize the crystal

Two 68 Ω resistors between USB data lines and the microcontroller pins

1 MΩ pullup resistor for D+ and 1.5 kΩ pullup for D-

6-pin header for programming the ATtiny and 4.7 kΩ pullup for reset pin

Update: Some people have noted that the setup I’m using here runs ATtiny2313 at 12 MHz with only 3.3V VCC, which is outside the specified range (frequencies over 10 Mhz require 4.5V or more). I’ve never had any problems, and many others have succeeded with this setup, but if you encounter persistent problems, I suggest you to power the ATtiny2313 straight from 5V of the USB line and use zener diodes on D+ and D- lines to drop their voltage, as is done in my later tutorial with the ATtiny85 microcontroller.

Breadboard setup

This time I will not walk you through every connection. Instead, I’ll just outline the steps needed and show the pictures of end result. Here is the schematic we’re building: