Pages: [1]   Go Down
Author Topic: USB bar code Reader  (Read 967 times)
0 Members and 1 Guest are viewing this topic.
USA
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have Motorola DS6707 bar code scanner that I am trying to interface with the DUE. I am new to this and having issues. I am running the keyboard USB host example, with a keyboard attached I can run the serial monitor and everything works fine. When I attach the bar code scanner (which is supposed to run as a keyboard), I get nuttin. When I plug the scanner into my PC, drivers were installed. Not sure if this is the problem, please help.
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If it is emulating a keyboard, do you have the serial parameters and baud rate set correctly?  You might post some code.
Logged

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

The code I am using is the Keyboard Controller Example. The bar code reader is supposed to emulate a keyboard, but it doesn't. The code does work with a keyboard though.


Code:
[quote]
[color=#7E7E7E]/*[/color]
[color=#7E7E7E] Keyboard Controller Example[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] Shows the output of a USB Keyboard connected to [/color]
[color=#7E7E7E] the Native USB port on an Arduino Due Board.[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] created 8 Oct 2012[/color]
[color=#7E7E7E] by Cristian Maglie[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] http://arduino.cc/en/Tutorial/KeyboardController[/color]
[color=#7E7E7E] [/color]
[color=#7E7E7E] This sample code is part of the public domain.[/color]
[color=#7E7E7E] */[/color]


[color=#7E7E7E]// Require keyboard control library[/color]
#include <[color=#CC6600]KeyboardController[/color].h>

[color=#7E7E7E]// Initialize USB Controller[/color]
[color=#CC6600]USBHost[/color] usb;

[color=#7E7E7E]// Attach keyboard controller to USB[/color]
[color=#CC6600]KeyboardController[/color] keyboard(usb);

[color=#7E7E7E]// This function intercepts key press[/color]
[color=#CC6600]void[/color] [color=#CC6600]keyPressed[/color]() {
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Pressed:  "[/color]);
  printKey();
}

[color=#7E7E7E]// This function intercepts key release[/color]
[color=#CC6600]void[/color] [color=#CC6600]keyReleased[/color]() {
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Released: "[/color]);
  printKey();
}

[color=#CC6600]void[/color] printKey() {
  [color=#7E7E7E]// getOemKey() returns the OEM-code associated with the key[/color]
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]" key:"[/color]);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](keyboard.[color=#CC6600]getOemKey[/color]());

  [color=#7E7E7E]// getModifiers() returns a bits field with the modifiers-keys[/color]
  [color=#CC6600]int[/color] mod = keyboard.[color=#CC6600]getModifiers[/color]();
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]" mod:"[/color]);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](mod);

  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]" => "[/color]);

  [color=#CC6600]if[/color] (mod & LeftCtrl)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"L-Ctrl "[/color]);
  [color=#CC6600]if[/color] (mod & LeftShift)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"L-Shift "[/color]);
  [color=#CC6600]if[/color] (mod & Alt)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Alt "[/color]);
  [color=#CC6600]if[/color] (mod & LeftCmd)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"L-Cmd "[/color]);
  [color=#CC6600]if[/color] (mod & RightCtrl)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"R-Ctrl "[/color]);
  [color=#CC6600]if[/color] (mod & RightShift)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"R-Shift "[/color]);
  [color=#CC6600]if[/color] (mod & AltGr)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"AltGr "[/color]);
  [color=#CC6600]if[/color] (mod & RightCmd)
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"R-Cmd "[/color]);

  [color=#7E7E7E]// getKey() returns the ASCII translation of OEM key[/color]
  [color=#7E7E7E]// combined with modifiers.[/color]
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]write[/color](keyboard.[color=#CC6600]getKey[/color]());
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]();
}

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]([color=#006699]"Program started"[/color]);
  [color=#CC6600]delay[/color](200);
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
  [color=#7E7E7E]// Process USB tasks[/color]
  usb.[color=#CC6600]Task[/color]();
}

[/quote]
Logged

Offline Offline
Jr. Member
**
Karma: 5
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The bar code may not be a simple keyboard device, it might be a composite device. Check by plugging into windows and look to see if it installs as a HID or composite device. There are utilities like usbview and usbdeview which help here, or you can root around in Device Manager.

If it is simple HID device, then there is a chance to get it working, otherwise you will need Arduino code to handle composite devices.
Logged

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

Using USBview, looks like the bar code reader is a HID device. I also noticed the bar code reader is a full speed device, but a keyboard is a low speed device.
« Last Edit: August 12, 2013, 01:30:55 pm by Doogle » Logged

Pages: [1]   Go Up
Jump to: