Go Down

Topic: usb keyboard hardware (Read 864 times) previous topic - next topic

emada

So im trying to emulate a usb keyboard and i was just wondering, is it valid to just cute a USB cable and plug it into a breadboard then into the arduino or do i need resistors and such to make it work? Thanks.

terryking228

Hi,
To be clear, do you want to use Arduino to connect to a USB cable and appear to be a USB keyboard to a desktop computer etc??

If so, there's a lot more to this than connections..  Google "arduino emulate USB keyboard" and you'll start to get an idea of what is involved...

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

emada


Hi,
To be clear, do you want to use Arduino to connect to a USB cable and appear to be a USB keyboard to a desktop computer etc??

If so, there's a lot more to this than connections..  Google "arduino emulate USB keyboard" and you'll start to get an idea of what is involved...




I have done so and i have the software all done, just working on the hardware part now. just wanted to know if i need to use anything other then a usb cable, breadboard, and my arduino for just a little hello world.

Coding Badly


Teensy; no extra hardware necessary...
http://pjrc.com/teensy/td_keyboard.html

emada

Ok i have the right hardware built i think and im using the example that comes with the lib from here:
http://code.google.com/p/vusb-for-arduino/
code:
Code: [Select]
#include "UsbKeyboard.h"

#define BUTTON_PIN 12

// If the timer isr is corrected
// to not take so long change this to 0.
#define BYPASS_TIMER_ISR 1

void setup() {
  pinMode(BUTTON_PIN, INPUT);
  digitalWrite(BUTTON_PIN, HIGH);
 
#if BYPASS_TIMER_ISR
  // disable timer 0 overflow interrupt (used for millis)
  TIMSK0&=!(1<<TOIE0); // ++
#endif
}

#if BYPASS_TIMER_ISR
void delayMs(unsigned int ms) {
   /*
  */
  for (int i = 0; i < ms; i++) {
    delayMicroseconds(1000);
  }
}
#endif

void loop() {
 
  UsbKeyboard.update();

  digitalWrite(13, !digitalRead(13));

  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_SPACE);

    UsbKeyboard.sendKeyStroke(KEY_W);
    UsbKeyboard.sendKeyStroke(KEY_O);
    UsbKeyboard.sendKeyStroke(KEY_R);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_D);
    //UsbKeyboard.sendKeyStroke(KEY_B, MOD_GUI_LEFT);

    UsbKeyboard.sendKeyStroke(KEY_ENTER);
#if BYPASS_TIMER_ISR  // check if timer isr fixed.
    delayMs(20);
#else
    delay(20);
#endif
   
   }

}


My set up is like so
DIO2 - green wire
DIO4 - white
DIO5 - white
GRN - grn
5v - 5v
DIO12 - button

i get this in syslog:
Code: [Select]
Oct  3 21:50:03 emada-laptop kernel: [14576.550470] usb 2-1: new full speed USB device using ohci_hcd and address 38
Oct  3 21:50:03 emada-laptop kernel: [14576.732589] usb 2-1: device descriptor read/64, error -62
Oct  3 21:50:03 emada-laptop kernel: [14577.020127] usb 2-1: device descriptor read/64, error -62
Oct  3 21:50:04 emada-laptop kernel: [14577.312322] usb 2-1: new full speed USB device using ohci_hcd and address 39
Oct  3 21:50:04 emada-laptop kernel: [14577.497535] usb 2-1: device descriptor read/64, error -62
Oct  3 21:50:04 emada-laptop kernel: [14577.782600] usb 2-1: device descriptor read/64, error -62
Oct  3 21:50:04 emada-laptop kernel: [14578.070204] usb 2-1: new full speed USB device using ohci_hcd and address 40
Oct  3 21:50:05 emada-laptop kernel: [14578.492592] usb 2-1: device not accepting address 40, error -62
Oct  3 21:50:05 emada-laptop kernel: [14578.670124] usb 2-1: new full speed USB device using ohci_hcd and address 41
Oct  3 21:50:05 emada-laptop kernel: [14579.092576] usb 2-1: device not accepting address 41, error -62
Oct  3 21:50:05 emada-laptop kernel: [14579.092657] hub 2-0:1.0: unable to enumerate USB device on port 1


attached is also i picture of the set up. anyone have any idea what im doing wrong?

Jaaptina

#5
Oct 30, 2011, 11:59 am Last Edit: Oct 30, 2011, 12:04 pm by Jaaptina Reason: 1
I'm also busy with the Virtual USB keyboard. I have just got mine working. It wasn't easy. First I used a breadboard. That did not work. The pc did not recognise the Arduino as USB-device. USB is very sensative to tiny disruptions. Thats why the breadboard version doesn't work. After I soldered all to the proto-shield it did work and the Arduino is recognised as USB-keyboard. However it is still sensative. See the topic "Virtual USB Keyboard problem" for more info.

I do not understand the bypass timer part in your loop. I is not used in the code at http://www.practicalarduino.com/projects/virtual-usb-keyboard.

JoeO

I don't see how the ground on the breadboard is connected to the ground of the Arduino board.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy