Pages: [1]   Go Down
Author Topic: Connecting Arduino Uno to a USB HID  (Read 2413 times)
0 Members and 1 Guest are viewing this topic.
GA
Offline Offline
Newbie
*
Karma: 1
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

After a couple of days of research I've ran out of hope to find an answer on my own. I need to connect HID peripheral as an input to my Arduino Uno microcontroller. The peripheral is a barcode scanner that has a USB connector, but has the following interfaces:
  • Keyboard wedge
  • USB
  • RS232

Thinking it's going to be a cake I set the scanner for RS232 interface at 9600 baud, 8-bit data, no parity, and 1 stop bit. I then connect it to Arduino's USB port and run the following code on Uno:
Code:
void setup() {
    /* Setup serial communication at 9600 baud */
    Serial.begin(9600);
}

void loop()
{
    if (Serial.available() > 0)
    {
        /* Do something */
    }
}

Alas, Arduino goes all the way through the setup(), but never makes it inside the loop()'s if-statement when the scanner transmits data.

What am I missing here? Is my setup even possible? If not could I adapt it to something like this:
http://arduino.cc/playground/ComponentLib/BarcodeScanner ?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thinking it's going to be a cake I set the scanner for RS232 interface at 9600 baud, 8-bit data, no parity, and 1 stop bit. I then connect it to Arduino's USB port and run the following code on Uno:

If you set it to RS232 shouldn't you be connecting it to the serial interface (pins 0 and 1) via a suitable level converter?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Link to the scanner please?
Logged

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1024
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look up Arduino USB Shield.

There are 2 types of USB Devices. Masters and Slaves. Masters and Slaves have different connectors. A slave device cannot function as a master - HINT Arduino Uno is a Slave type device. To connect a USB device to your Arduino youneed a USB shield that will allow the Arduino to function as a master.
Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

USB host shield 2.0 manual and library.

Buying it: US supplier and European supplier.

Logged

GA
Offline Offline
Newbie
*
Karma: 1
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your replies.

The link to the scanner is here. Sorry but even their manual does not have any hardware specs.

USB Shield would be an ideal solution, but I am already using another shield with my Arduino Uno. So I am thinking about taking Nick's suggested way of connecting the scanner to TX/RX pins. I don't want to mess the scanner up though, so should I get a USB-to-PS2 adapter and then connect it in the same way as suggested in my link above?
Logged

GA
Offline Offline
Newbie
*
Karma: 1
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thinking it's going to be a cake I set the scanner for RS232 interface at 9600 baud, 8-bit data, no parity, and 1 stop bit. I then connect it to Arduino's USB port and run the following code on Uno:

If you set it to RS232 shouldn't you be connecting it to the serial interface (pins 0 and 1) via a suitable level converter?

The reason I thought that connecting it through USB port would work is because USB port is treated as a serial input by Arduino (ATmega16u2 is converting the data?) Or at least that's how Arduino Uno is able to communicate with its IDE. So I tried applying the same principle to connect my scanner.
Logged

GA
Offline Offline
Newbie
*
Karma: 1
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look up Arduino USB Shield.

There are 2 types of USB Devices. Masters and Slaves. Masters and Slaves have different connectors. A slave device cannot function as a master - HINT Arduino Uno is a Slave type device. To connect a USB device to your Arduino youneed a USB shield that will allow the Arduino to function as a master.
Didn't know that. Thanks!
Logged

Canby, OR
Offline Offline
Full Member
***
Karma: 1
Posts: 158
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The USB port is treated as serial, IF you connect a device (USB master) that understands how to convert serial to USB signals. If your scanner is outputting RS232 you want to hook it up raw to pins 0 and 1 with appropriate voltage converters.
Logged

Worcester, Ma.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Look up Arduino USB Shield.

There are 2 types of USB Devices. Masters and Slaves. Masters and Slaves have different connectors. A slave device cannot function as a master - HINT Arduino Uno is a Slave type device. To connect a USB device to your Arduino you need a USB shield that will allow the Arduino to function as a master.

Interesting!

I can't say "I didn't know that", but I can say "Duh! Thanks for the reminder!!"

Question:
The Arduino is configured as a "slave" device - and that's understandable.  Is it possible to - programmatically - reconfigure the device to act as a master while running the sketch?  Our would that require a re-flash of the converter firmware, rendering it useless as a normal Arduino "slave" device without another re-flash.

Thanks!
Logged

Offline Offline
Edison Member
*
Karma: 32
Posts: 1389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you check out the USB host library linked to above, to see how much work it is.

Assuming you can find the right cable, I don't know if it is possible to try to dynamically switch from host to device.
Logged

Pages: [1]   Go Up
Jump to: