Poll
Question: I am trying USB keyboard on ATM328, has anyone done this
pl advice me
My os is vists

Pages: [1] 2 3 ... 5   Go Down
Author Topic: AVRUSB running on Arduino hardware with minishield  (Read 9661 times)
0 Members and 1 Guest are viewing this topic.
New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all...

Just a quick update on getting AVR-USB to run with the Arduino.

I've just managed to put together a "mini" expansion shield with a USB "B" socket and the 2 diodes and 3 resistors needed to create a USB connection to the Arduino hardware. (Have plans to upload schematic/diagram/photos eventually.)

After some code modifications (to fit using ATmega168 etc) I got Linux and OS X recognising the demo devices. I'm currently trying to get HID keyboard data to be recognised.

So, while it's not yet integrated with the Arduino libraries it's at least progress to have a shield working and the code running on the Arduino hardware.

You can follow AVRUSB on Arduino progress here.

--Phil.
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Logged

FR
Offline Offline
Full Member
***
Karma: 0
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice
Where did you get the USB receptacle and how much did you pay for ?

Nicolas
Logged

Montréal, Qc
Offline Offline
Full Member
***
Karma: 1
Posts: 185
Practice safe hex!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

digikey, sparkfun, futurlec all carry them and they are usually around $1.
Logged

"Pilots believe in a clean living... they never drink wisky from a dirty glass."

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've now got the PowerSwitch USB echo demo working from an Arduino sketch as I'm flashing an LED every second.

This test sends a character from the host (a Linux box in this case) and the USB device responds with the same character.

I haven't made any changes to the core Arduino code which will probably result in an issue if an interrupt happens at the wrong time.

But it's something, and it's currently flashing away happily. :-)

Here's the exciting screenshot:

Code:
sudo ./powerSwitch test
test succeeded

(Imagine LED still flashing here.)

--Phil.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh man!  This is awesome, I will most definitely be following your progress.

Chris
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a quick update that last night I managed to get the Arduino to function as a USB HID keyboard (with one button!) when connected to a Mac OS X 10.4 machine. I had previously had some success connected to an Ubuntu box.

I managed to send standard characters, modified keystrokes (e.g. Command-B), arrow keys and function keys--the latter of which I used to bring the Dashboard up on screen whenever I pushed the button attached to the Arduino. :-)

So, the short answer does seem to be that at least at some level AVRUSB and Arduino can be compatible--I'm not sure if there is a point at which one or other of them will break as I haven't tried anything very sophisticated.

I'm hoping that my web server will be back on line soon so I can upload more details.

--Phil.
Logged

berlin
Offline Offline
Sr. Member
****
Karma: 0
Posts: 295
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley good news
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's sweet!  Please post a reply when you get this up on your website - I am very interested in doing something similar to this, and a simple howto / tutorial would go a long way!

Cheers
Logged

British Columbia, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Freeduinoing and loving it
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm hoping that my web server will be back on line soon so I can upload more details.

Great learning about this with you on IRC, thanks a lot.  Now we all know you really really want to upload some kicad files for us ;D

Best wishes...
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, okay...

I have just uploaded photos of the USB mini-shield for Arduino on my 9 July 2008 project log entry which I think should be enough for you to recreate it on strip- or vero-board. (Real board layout not...er, "complete". :-) )

For those that care, the current implementation isn't 100% ideal because it would be nice if the "device present" resistor could be controlled by the microcontroller to be "more polite" in conjunction with the bootloader  but that's not a huge deal. (But at the cost of an extra microcontroller pin it might have some benefits at a later date.)

Let me guess, now you'll be asking for some code & compilation instructions? smiley-razz

--Phil.

Edit: I've now added a link to a schematic exported from KiCad in SVG format to the page.
« Last Edit: July 08, 2008, 12:28:41 pm by follower » Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

Just a quick note to say I've uploaded the arduinousb library and an example sketch--both tailored to create a USB HID keyboard device.

Here's the guts of an example:
Code:
#include "UsbKeyboard.h"

# ...[snip]...

void loop() {
  
  UsbKeyboard.update();

  if (digitalRead(BUTTON_PIN) == 0) {
    //UsbKeyboard.sendKeyStroke(KEY_B, MOD_GUI_LEFT);
    
    UsbKeyboard.sendKeyStroke(KEY_H);
    UsbKeyboard.sendKeyStroke(KEY_E);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_O);

    //UsbKeyboard.sendKeyStroke(KEY_B, MOD_GUI_LEFT);
    UsbKeyboard.sendKeyStroke(KEY_ENTER);

    delay(200);
   }
}

--Phil.
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Another quick update, I've added links to the project page of user-submitted code contributions implementing USB mouse and keyboard functionality.

Thanks Michel!

--Phil.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having a bit of trouble getting this to work:
Code:
hardware\libraries\UsbKeyboard/UsbKeyboard.h:139: error: 'byte' has not been declared

hardware\libraries\UsbKeyboard/UsbKeyboard.h:143: error: 'byte' has not been declared

hardware\libraries\UsbKeyboard/UsbKeyboard.h:143: error: 'byte' has not been declared

hardware\libraries\UsbKeyboard/UsbKeyboard.h: In constructor 'UsbKeyboardDevice::UsbKeyboardDevice()':

hardware\libraries\UsbKeyboard/UsbKeyboard.h:127: error: 'sei' was not declared in this scope

hardware\libraries\UsbKeyboard/UsbKeyboard.h:131: error: 'memset' was not declared in this scope

hardware\libraries\UsbKeyboard/UsbKeyboard.h: In member function 'void UsbKeyboardDevice::sendKeyStroke(int, int)':

hardware\libraries\UsbKeyboard/UsbKeyboard.h:151: error: 'memset' was not declared in this scope

Any suggestions would be much appreciated!
« Last Edit: September 29, 2008, 04:25:09 pm by mattburr » Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any suggestions would be much appreciated!
My first suggestion would be to try with IDE 0011 rather than 0012 if at all possible. The issue is caused by a change from the 0011 environment in the 0012 environment.

My second suggestion if you need to use 0012 is to try to apply this patch to UsbKeyboard.h (but be warned it was hacked up late one night as I was trying to meet a deadline--and the final result doesn't work as reliably as previous attempts but at present I am unsure if that is hardware or software related):
Code:
--- UsbKeyboard.h~      2008-09-24 22:45:15.000000000 +1200
+++ UsbKeyboard.h      2008-09-24 23:46:34.000000000 +1200
@@ -10,6 +10,15 @@
 
 #include "usbdrv.h"
 
+#include <avr/interrupt.h>
+
+#include <string.h>
+
+// #include "WConstants.h"
+typedef uint8_t byte; // avoid int() issue
+
+#include <util/delay.h>
+
 #define BUFFER_SIZE 4 // Minimum of 2: 1 for modifiers + 1 for keystroke
 
 
@@ -124,7 +133,8 @@
 
     // Control pull-up resistor
     usbDeviceDisconnect();
-    delay(500);
+    //delay(500);
+    _delay_ms(500);
     usbDeviceConnect();
 
     usbInit();

(If you don't know how to interpret the patch formatting I can try resupplying it in a different form.)

Please let me know if this helps you or not.

--Phil.

P.S. As always, I'm keen to learn what people are using the code for. :-)
Logged

Pages: [1] 2 3 ... 5   Go Up
Jump to: