# Getting Started

This page is a walk through describing how to connect a AT90USBKey for the first time and setting up a simple HID device.

1. Run Generic HID
2. Select the Microcontroller
3. Edit Properties
4. Enable Stock Items
5. Plug in the Device
6. Programming
7. Test the Device

## Run Generic HID

### Windows

Launch the Generic HID application, this is generichid.exe in the directory that you unzipped the application.

If you get such-a-such error, you haven't installed libusb-win32

#### Linux

Run generichid.

You should see an empty screen...

## Select the Microcontroller

For this example we are going to use the Stock AT90USBKey. That's the first component in the toolbox. Click on the item and drag it onto the design surface.

## Edit Properties

Click on the Stock AT90USBKey that has just been placed on the design surface. This will select the item and display its properties in the property window. The Help window will show a description of the selected item.

## Enable Stock Items

In this demo, we are only going to enable the stock devices installed on the AT90USBKey. In the properties windows, make the following changes...

Property | Change To
Name | Funky Device
Use LEDs | True
Use Voltage Monitor | True
Use Temperature Sensor | True
Use Joystick | True
Use HWB | True

## Plug in the Device

Plug the device into the system.

### Using Windows XP

Generic HID has only been tested on Windows XP, but should work on newer Windows operating systems.

When you plug the device in, windows will detect the new device and try to install drivers. This is optional. The AT90USBKey comes preprogrammed as a mouse, a hid device and a flash drive. You may be prompted to install drivers, and then you can play with the device. The flash memory contains online manuals, data sheets and sample code for the at90usb1287 microcontroller. You can save this if you wish, but it is not needed for Generic HID, and most of the data is available on the Atmel website.

### Using Ubuntu

Generic HID has been tested using Ubuntu 10.04 and 12.04, but should work with any linux with udev.

When the device is plugged in, linux will silently detect the device and load the necessary drivers. You can use the command `dmesg` to list the system logs and see what has happened. For example...

`

frankt@linuxpc:~$ dmesg
[1378539.954506] usb 1-1.4.4.1: new full speed USB device using uhci_hcd and address 28
[1378540.095368] usb 1-1.4.4.1: configuration #1 chosen from 1 choice
[1378540.107341] input: ATMEL AVR USB KEY COMPOSITE DEVICE as /devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4.1/1-1.4.4.1:1.0/input/input21
[1378540.148835] input,hidraw5: USB HID v10.01 Mouse [ATMEL AVR USB KEY COMPOSITE DEVICE] on usb-0000:00:1d.0-1.4.4.1
[1378540.160307] hiddev96hidraw7: USB HID v10.01 Device [ATMEL AVR USB KEY COMPOSITE DEVICE] on usb-0000:00:1d.0-1.4.4.1
[1378540.360820] usbcore: registered new interface driver libusual
[1378540.380720] Initializing USB Mass Storage driver...
[1378540.385105] scsi4 : SCSI emulation for USB Mass Storage devices
[1378540.386534] usbcore: registered new interface driver usb-storage
[1378540.386540] USB Mass Storage support registered.
[1378540.387730] usb-storage: device found at 28
[1378540.387733] usb-storage: waiting for device to settle before scanning
[1378545.378702] usb-storage: device scan complete
[1378545.381697] scsi 4:0:0:0: Direct-Access ATMEL AT90USB128 M S 0.00 PQ: 0 ANSI: 0
[1378545.387684] sd 4:0:0:0: [sdc] 32768 512-byte hardware sectors (17 MB)
[1378545.390677] sd 4:0:0:0: [sdc] Write Protect is off
[1378545.390682] sd 4:0:0:0: [sdc] Mode Sense: 1b 00 00 00
[1378545.390684] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[1378545.399660] sd 4:0:0:0: [sdc] 32768 512-byte hardware sectors (17 MB)
[1378545.402662] sd 4:0:0:0: [sdc] Write Protect is off
[1378545.402667] sd 4:0:0:0: [sdc] Mode Sense: 1b 00 00 00
[1378545.402670] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[1378545.402675] sdc: unknown partition table
[1378545.491544] sd 4:0:0:0: [sdc] Attached SCSI removable disk
[1378545.491587] sd 4:0:0:0: Attached scsi generic sg3 type 0

`

Being a secure operating system, linux will not let just any application directly access a USB device. Permissions must be set so Generic HID can access the device while it is a HID device, and when it is program mode. See this section for details on how to set up permissions.

## Programming

In Generic HID, select the Microcontroller | Program... menu option. The programming window will appear...

Note that all the lights are red and the buttons are disabled. The AT90USBKey is running in Mouse/HID/Flash Drive mode and the Generic HID software cannot recognise it. For it to be recognised, it needs to either be programmed as a Generic HID, or be running in bootloader mode.

Normally bootloader mode can be entered just by pressing the "Start Bootloader" button. Because this is the first time we are going to program the device, we need to enter bootloader manually by using the buttons on the board...

1. Press and hold the HWB button
2. Press and release the RST button
3. Release the HWB button

The device should now enter bootloader mode. This sequence can be used anytime the device appears unresponsive.

The program window should now detect the device...

Press the Program button. A progress bar will show the programmer in action.

When the programming is complete press the "Restart Device" button. Now the Generic HID device should be detected. The Program dialog box will now identify the device. If it doesn't, press the RST button on the board, or unplug the device and plug it in again.

## Test the Device

Close the Program dialog box. Then select the Test panel. If the Generic HID device is connected, it will automatically appear...

The Test panel shows the parts on AT90USBKey that appear as a HID items...

DFU | This is the way the bootloader is started. Nothing can be done with this.
Temperature | There is a thermistor on the AT90USBKey - a resistor that changes value with temperature. It is R29, between the USB connector and the microcontroller (the larger black square) placing a finger on it will cause the temperature to rise and the value to go down.
Voltage | The voltage field reports the external battery voltage connected to the device. Its scaled and converted to an integer and doesn't move. Divide the number by 22 to get the approximate voltage. Without an external power supply the floating voltage is meaningless.
Joystick | The joystick on the AT90USBKey is a switched type joystick, or hatswitch. The joystick is the small black rectangle with white lever on the end of the board opposite the USB connector. Push the stick sideways to activate it.
JoystickButton | Pushing down on joystick lever will activate the joystick button
HWBButton | The HWB button can be pressed. It will toggle the Red/Green software light when it does.

LED2

The colour of LED2 can be changed by moving the slider. There are 4 different values...

0 | Off
1 | Green
2 | Red
3 | Red-Orange