Project Log : Arduino USB
Description
Project log for developing USB expansion shield for Arduino and associated code.
See also: Learning About Arduino and AVR-USB
Notes
- ( 7 March 2008 )
- Have started construction of "mini" expansion shield on a piece of strip board.
- Connected USB "B" socket to board and wired ground and +5V (Vbus) from USB to Arduino to power it successfully.
- Helpfully found the required 2.2KOhm and 68 Ohm resistors needed in the latest box of electronics bits I purchased. (Of course they were in the last set of the resistors I looked through though.)
- Started drawing schematic in KiCad. Used USB "B" socket symbol from con-usb.lib from http://www.kicadlib.org/. Used Arduino pin layout from http://uchobby.com/.
- Also using Arduino Atmega168 pin mapping details. Note: INT0 == PD2 == IC Pin 4 == Arduino Digital Pin 2, INT1 == PD3 == IC Pin 5 == Arduino Digital Pin 3
- FIX: Schematic should probably have a diode to prevent powering Vbus accidentally.
- The source for usbdrv.h says, regarding the hardware:
USB lines D+ and D- MUST be wired to the same I/O port. We recommend that D+ triggers the interrupt (best achieved by using INT0 for D+), but it is also possible to trigger the interrupt from D-. If D- is used, interrupts are also triggered by SOF packets. D- requires a pullup of 1.5k to +3.5V (and the device must be powered at 3.5V) to identify as low-speed USB device. A pullup of 1M SHOULD be connected from D+ to +3.5V to prevent interference when no USB master is connected. We use D+ as interrupt source and not D- because it does not trigger on keep-alive and RESET states.
- For a 5V source it seems the pullup on D- needs to be 2.2K to 5v.
- Other circuits: usbasp, usbtinyisp, avrusb
- Socket pin outs: USB overview and Plug and Receptacle pinouts
- Soldered up zener diodes and pull up resistor.
- Plugged into linux host, produced this from tail -f /var/log/syslog :
Mar 7 04:52:38 localhost kernel: [685132.128973] usb 1-2: new low speed USB device using uhci_hcd and address 9 Mar 7 04:52:38 localhost kernel: [685132.252884] usb 1-2: device descriptor read/64, error -71 Mar 7 04:52:38 localhost kernel: [685132.480711] usb 1-2: device descriptor read/64, error -71 Mar 7 04:52:39 localhost kernel: [685132.696583] usb 1-2: new low speed USB device using uhci_hcd and address 10 Mar 7 04:52:39 localhost kernel: [685132.816506] usb 1-2: device descriptor read/64, error -71 Mar 7 04:52:39 localhost kernel: [685133.040335] usb 1-2: device descriptor read/64, error -71 Mar 7 04:52:39 localhost kernel: [685133.256203] usb 1-2: new low speed USB device using uhci_hcd and address 11 Mar 7 04:52:40 localhost kernel: [685133.663904] usb 1-2: device not accepting address 11, error -71 Mar 7 04:52:40 localhost kernel: [685133.775828] usb 1-2: new low speed USB device using uhci_hcd and address 12 Mar 7 04:52:40 localhost kernel: [685134.183550] usb 1-2: device not accepting address 12, error -71
- Above result "new low speed device" indicates pull up is in correct place. The error messages are because it's only the bare board plugged in. (Apparently strip board doesn't accept addresses.) :-)
- I'm using 3.6V, 0.5W Zener Diodes (1N5227) although I hear .25W is preferred, and apparently 1W don't work (according to a forum post).
- FIX: Change diodes in schematic to zeners.
- Modified PowerSwitch usbconfig.h file. Compiled with make on Ubuntu 7.10 machine.
- Before plugging in, remember to: upload firmware, change power jumper to "none", disconnect Arduino usb socket cable, attach shield, attach cable to expansion usb socket.
- Doesn't work. :-(
- Used this to upload (from OS X):
hardware/tools/avr/bin/avrdude -Chardware/tools/avr/etc/avrdude.conf -v -v -v -v -pm168 -cstk500v1 -P/dev/tty.usbserial-<id> -b19200 -D -Uflash:w:<path>main.hex:i
- Need to edit Makefile to set DEVICE to atmega168!
- Need to edit main.c
- Works!
- Using lsusb shows the device appearing/disappearing:
Bus 001 Device 040: ID 16c0:05dc
- Using sudo lsusb -v gives something that includes:
iManufacturer 1 www.obdev.at iProduct 2 PowerSwitch
- Edited EasyLogger enough to init okay.
- ( 8 March 2008 )
- I've now got the powerswitch usb echo demo working from an Arduino sketch as I'm flashing an LED every second. The Usbduino shield is in the house. :-)
- BTW an error message of the form "error: invalid conversion from `void*' to ..." is because C++ requires that casts from void * are explicit not implicit.
- BTW also, an error message of the form "error: expected initializer before int" or "error: expected initializer before int" may be because PROGMEM isn't recognised because you need to include the pgmspace.h file. Use gcc's -save-temps command to look in the .ii file to see if PROGMEM is replaced.
- ( 18 March 2008 )
- Trying to get IDE to compile library correctly from bare source—but it doesn't compile '.S' files at least...
- Try this in library directory first:
hardware/tools/avr/bin/avr-g++ -Wall -Os -I. -DUSB_CFG_CLOCK_KHZ=16000 -mmcu=atmega168 -c usbdrvasm.S
- Hmmm, so it seems the IDE doesn't do the compile the other things correctly either, so we need also:
hardware/tools/avr/bin/avr-g++ -Wall -Os -I. -DUSB_CFG_CLOCK_KHZ=16000 -mmcu=atmega168 -c usbdrv.c
- I guess that's why I compiled the other test by hand... :-)
- So the above commands will produce usbdrv.o and usbdrvasm.o files.
- Still not getting working keyboard data on OS X...
- On Ubuntu I can get some data out by doing: (depending on the usb device address)
sudo cat /dev/input/by-path/pci-0000\:00\:14.2-usb-0\:2\:1.0-event- | hexdump
- This produced when pressing the button: (index 1 // KEY_A // 4 ?)
0000000 86c7 47de 05cc 000b 0001 002a 0001 0000 0000010 86c7 47de 05d7 000b 0001 001e 0001 0000 0000020 86c7 47de 05d9 000b 0000 0000 0000 0000 0000030 86c7 47de da7f 000c 0001 002a 0000 0000 0000040 86c7 47de da89 000c 0001 001e 0000 0000 0000050 86c7 47de da8c 000c 0000 0000 0000 0000
- This produced when pressing the button: (index 2 // KEY_B // 5 ?)
0000000 88e5 47de a4c7 000b 0001 002a 0001 0000 0000010 88e5 47de a4d0 000b 0001 0030 0001 0000 0000020 88e5 47de a4d2 000b 0000 0000 0000 0000 0000030 88e5 47de 9ec5 000c 0001 002a 0000 0000 0000040 88e5 47de 9ece 000c 0001 0030 0000 0000 0000050 88e5 47de 9ed1 000c 0000 0000 0000 0000
- ( 21 March 2008 )
- ( 28 March 2008 )
- Discovered today that on Linux it's now working okay for HID, seemingly. (Although the first few key presses seem not to be recognised.)