Go Down

Topic: Connecting Arduino Uno to a USB HID (Read 2870 times) previous topic - next topic

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: [Select]
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 ?

Nick Gammon


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?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

kf2qd

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.


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?



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.


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!

Scott Baker

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.


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!

KeithRB

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.

Go Up