Barcode reader for arduino

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
kh8913
 
Posts: 3
Joined: Fri Feb 22, 2013 7:55 am

Barcode reader for arduino

Post by kh8913 »

For a project at university, I'm trying to read barcode (common 1D one) to be processed with an Arduino. I have found a compact barcode reader on adafruit's online store which are titled "Barcode Reader/Scanner Module - CCD Camera - USB Interface -" (ID: 1203) and "Barcode Reader/Scanner Module - CCD Camera - PS/2 Interface -" (ID: 1202) I want to buy one of them as soon as possible. But I need help with one thing.
In terms of connecting them to Arduino, I guess they are both the same as I have to strip the end bits and use the wires inside individually but I'm not sure if the device itself is suitable to be connected to arduino or not. Can it easily communicate with arduino?

And one more thing. For this purpose what Arduino is the best. UNO or MEGA?

I'd be grateful if someone could help me out.

Thanks
Khash

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Barcode reader for arduino

Post by adafruit_support_mike »

kh8913 wrote: Can it easily communicate with arduino?
The device acts like a keyboard, so there's a layer of hardware and data protocols that you'd have to implement on the Arduino. It's possible, but probably not what you'd call easy.

You should be able to plug it straight into a Raspberry Pi though.. no cable trimming necessary. Are there specific features of the Arduino that you need for your project?

User avatar
kh8913
 
Posts: 3
Joined: Fri Feb 22, 2013 7:55 am

Re: Barcode reader for arduino

Post by kh8913 »

[email protected] wrote:The device acts like a keyboard, so there's a layer of hardware and data protocols that you'd have to implement on the Arduino. It's possible, but probably not what you'd call easy.

You should be able to plug it straight into a Raspberry Pi though.. no cable trimming necessary. Are there specific features of the Arduino that you need for your project?
Thanks for your reply. 2 years ago I used ardiuno at my uni for one of my projects. I'm really worried about the coding to make them talk to each other and I thought that if I use Arduino, it's something I'm more familiar with and I can get some help from the technicians and friends here at uni. The main concern of mine is that this is one part (out of four) of my project and I don't have enough time to do a lot of debugging or learn a coding language in 3 months and do a lot of trial and error and I have to say I'm beginner at coding and electronics so what I'm trying to do is find a very simple way.

I was wondering if there's any better way of doing it? Is it less complex to use a normal barcode reader which uses laser?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Barcode reader for arduino

Post by adafruit_support_rick »

Actually, we have a PS/2 adapter cable for attaching the barcode reader to an arduino, so you won't have to cut any cables. And the PJRC PS/2 library should take care of all the details of the PS/2 interface.

So, really, I don't think you would have too difficult a time with putting this together on an Arduino. A Uno will handle this sort of thing easily.

With the PJRC library installed, the barcode scanner will look pretty much exactly like someone entering text via the Arduino Serial Monitor (instead of Serial.read(), you would call something like Scanner.read()). You will read one character at a time. Have a look at the PJRC link for some examples.

Your job as programmer will be figuring out what to do with the code characters as they are entered.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Barcode reader for arduino

Post by adafruit_support_mike »

driverblock wrote:Actually, we have a PS/2 adapter cable for attaching the barcode reader to an arduino, so you won't have to cut any cables. And the PJRC PS/2 library should take care of all the details of the PS/2 interface.
I defer to the man who knows more about it than me. ;-)

User avatar
kh8913
 
Posts: 3
Joined: Fri Feb 22, 2013 7:55 am

Re: Barcode reader for arduino

Post by kh8913 »

driverblock wrote: With the PJRC library installed, the barcode scanner will look pretty much exactly like someone entering text via the Arduino Serial Monitor (instead of Serial.read(), you would call something like Scanner.read()). You will read one character at a time. Have a look at the PJRC link for some examples.

Your job as programmer will be figuring out what to do with the code characters as they are entered.
[email protected] wrote: I defer to the man who knows more about it than me. ;-)
Thanks a lot to both of you. much appreciated. It seems that I might be able to do it then. :) :)

KA1OS
 
Posts: 2
Joined: Mon Apr 05, 2010 9:32 pm

Re: Barcode reader for arduino

Post by KA1OS »

The spec sheet for the MCR12 (available from Adafruit) indicates that the barcode scanner can output RS232 serial. The output voltages listed are +/- 9V which could be passed through an RS232/TTL serial converter chip to Arduino-safe, serial logic levels.

The manufacturer appears to sell a serial connector with a DB9 and power lead for the scanner but Adafruit currently seems to carry only the PS2 and USB leads. One could also convert the PS2 cable version by swapping pin receptacles on the 11-pin Molex motherboard connector, or make a cable from scratch. The connector is listed as Molex (or compatible), 11P with a 1.25 pitch. For a serial interface you would need to access:

Pin 1 (GND)
Pin 2 (+5V) -- to power supply
Pin 3 (TXD)
Pin 4 (RXD)
Pin 9 (RTS)
Pin 10 (CTS)

Using an RS232/TTL serial converter circuit one could skip the PS2 keyboard library and code for a simple serial connection instead. That might save some code space.

Barcodeproject
 
Posts: 3
Joined: Wed Apr 17, 2013 4:51 am

Re: Barcode reader for arduino

Post by Barcodeproject »

Hi

I'm working with the Adafruit barcode scanner and plugged it into my computer with a USB cable, like shown in the specs sheet: http://www.adafruit.com/products/1202#Downloads.

But the scanner doesn't read all the numbers of the barcode. E.g. when the complete barcode is "7 640152 110269", only the numbers "74021109" appear in the empty Wordpad document I opened. Or sometimes "761521109" or "76521109" or "764021109" appears, so it is pretty random.

How can I configure the scanner to scan ALL the numbers?

Your/Any help would be very much appreciated!!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Barcode reader for arduino

Post by adafruit_support_rick »

What kind of barcodes are these? If you look at the manual and quick-config, which are also linked on the product page, you'll see that the scanner can be configured for many different barcode standards, which can have different lengths.

Barcodeproject
 
Posts: 3
Joined: Wed Apr 17, 2013 4:51 am

Re: Barcode reader for arduino

Post by Barcodeproject »

Thanks for your previous reply.
I have another problem now. The barcode scanner seems to scan only once. After that, the red light stays on continuously and the scanner doesn't react to anything anymore, if i push it's button it doesn't do anything either.

This video shows the problem http://www.youtube.com/watch?v=-MCezw8DdOU.
(In the video, the scanner is activated when the ultrasonic sensor detects something withing a distance range.)

I tried reconfiguring the scanner to the default parameters but it doesn't help and turning the power off and on neither helps.

The problem also occurs when it isn't activated by the ultrasonic sensor and i just push the button: i push once, it buzzer goas off so i guess it has scanned successfully. Then when i push a second time, blockage, the red light stays on and pushing the button again does nothing. I need to put the power off and on again in order for it to scan a barcode again. But it will, again, only scan once so the bug will still be there.

What could be the cause of this? And how could it be solved?


Here is the Arduino code:

Code: Select all

#include <PS2Keyboard.h>
#include <ColorLCDShield.h>
#include <stdlib.h>
#include <stdio.h>

#define BACKGROUND  BLACK  // room for growth, adjust the background color according to daylight
#define C_COLOR  RED  // This is the color of the clock face, and digital clock
#define H_COLOR  BLUE  // hour hand color
#define M_COLOR  GREEN  // minute hand color
#define S_COLOR  YELLOW  // second hand color

LCDShield lcd;

const int pingPin = 7;
int pingVcc = 6;
int cm;
int printText;
int blah;

int actScan = 12;

const int DataPin = 10; //pin 5 op scanner
const int IRQpin =  2; //pin 6 op scanner

PS2Keyboard keyboard;

char c;
char barcodeChar[20];
int i;
char *allBarcodes;
int b;
int barcodeNumber;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  pinMode(actScan, OUTPUT);
    
  /* Initialize the LCD, set the contrast, clear the screen */
  lcd.init(PHILIPS);
  lcd.contrast(63); 
  lcd.clear(BACKGROUND);
  int b = 0;
  Serial.print("Item: ");
}

void loop()
{
 digitalWrite(actScan, HIGH);
 measureProximity();
 if (cm <=10){
   if (cm >= 5){
     i = 0;
     digitalWrite(actScan,LOW);
     delay(3000);
     digitalWrite(actScan,HIGH);
     printText = 1;
     decodeBarcode();
     printText = 0;
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
     decodeBarcode();
   }
}
}

long measureProximity (){ 
  long duration, inches;
  //int cm; // establish variables for duration of the ping, and the distance result in inches and centimeters:

  pinMode(pingVcc, OUTPUT);
  digitalWrite(pingVcc, HIGH);
  
  pinMode(pingPin, OUTPUT);   // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  digitalWrite(pingPin, LOW); // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT); // The same pin is used to read the signal from the PING))): a HIGH
  duration = pulseIn(pingPin, HIGH); // a HIGH pulse whose duration is the time (in microseconds) from the sending of the ping to the reception of its echo off of an object.

  inches = microsecondsToInches(duration);   // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
 
  //Serial.print(cm);
  //Serial.println(" cm");
  return cm;
  delay(100);
}

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}


void decodeBarcode () {
      if (keyboard.available()) {
        
        if (printText == 1){
           Serial.print("Item: ");
        }   
           char c = keyboard.read(); // read the next key
    
           if (c == PS2_ENTER) { // check for some of the special keys
            Serial.println();
          } else if (c == PS2_TAB) {
            Serial.print("[Tab]");
          } else if (c == PS2_ESC) {
            Serial.print("[ESC]");
          } else if (c == PS2_PAGEDOWN) {
            Serial.print("[PgDn]");
          } else if (c == PS2_PAGEUP) {
            Serial.print("[PgUp]");
          } else if (c == PS2_LEFTARROW) {
            Serial.print("[Left]");
          } else if (c == PS2_RIGHTARROW) {
            Serial.print("[Right]");
          } else if (c == PS2_UPARROW) {
            Serial.print("[Up]");
          } else if (c == PS2_DOWNARROW) {
            Serial.print("[Down]");
          } else if (c == PS2_DELETE) {
            Serial.print("[Del]");
          } else { 
            Serial.print(c); // otherwise, just print all normal characters
          }
            barcodeChar[i] = c ;
            //allBarcodes = c;
            i += 1;
            //Serial.println(barcodeChar);
            if (i == 13){
            Serial.print("allBarcodes: ");
            //Serial.println(barcodeChar);
            lcd.setStr(barcodeChar, 5, 5, WHITE, BLACK);
            //lcd.setStr(barcodeChar, 5, 5, WHITE, BLACK);
            i = 0;
            //barcodeNumber +=1;
            }
        }
  }
Last edited by adafruit_support_rick on Fri Jun 14, 2013 10:12 am, edited 1 time in total.
Reason: please use [code][/code] tags when posting code

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Barcode reader for arduino

Post by adafruit_support_rick »

Hmmm … that's a tough one. I don't see anything in your sketch or in the PS2 library that could block the scanner.
What happens if you connect it back up to your PC and try to scan into WordPad again? Does it still block when you do that?

You say you reset to factory defaults, which should disable all handshaking, but you might want to make sure. Enter the following configuration commands from the Quick Config guide:
<RTS/CTS Disable>
<ACK/NAK Disable>
<XON/XOFF Disable>

Barcodeproject
 
Posts: 3
Joined: Wed Apr 17, 2013 4:51 am

Re: Barcode reader for arduino

Post by Barcodeproject »

Hi
I reconfigured to usb mode and explicitly configured <RTS/CTS Disable> <ACK/NAK Disable> <XON/XOFF Disable>.
I plugged it in with wordpad open on my pc.
Same result:
- The first time i scan a barcode, the buzzer works and the light goes back off, but nothing appears in wordpad.
- And the second time i push the button, it still blocks so the same situation occurs as in keyboard mode.

Is it possible to reset the device internally in some way? Or what could be the problem?
Thanks for the help

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Barcode reader for arduino

Post by adafruit_support_rick »

I have no clue. Why don't we try replacing it?
Email [email protected] with a link to this thread and ask for a replacement.

magnetto123
 
Posts: 1
Joined: Wed Apr 02, 2014 4:55 am

Bar Code Project for Arduino Help!

Post by magnetto123 »

Hi , since I have seen this topic is related to my university subject this semester I have decided to ask for a little bit of consultation on this forum. I am making a project for people with Lactose/ Gluten Intolerance. In this way I am building a product using :

-Arduino Uno R3 - Atmega328 P
- Bar code Reader ( http://www.adafruit.com/products/1202 )
- Display ( http://www.adafruit.com/products/1480 )
- Battery (http://www.adafruit.com/products/328 )
- Charger (http://www.adafruit.com/products/259 )

In this project I need to select the criteria ( I am lactose intolerant ( BUTTON 1 ) OR I am Gluten Intolerant ( BUTTON 2 ) ). Depending on this, the food scanned by the bar code scanner will return a GREEN LED ( the product is safe for your alimentary issue ) or RED LED ( the product is not good for your Gluten/Lactose Intolerance Problem and in this case will return a recommended product on the Display from above). I want this device to work on battery but I am pretty sure I mistaken the battery voltage when I bought it.

Problem : Do I need a PS/2 connector to the arduino or can I mount the bar code scanner to the Arduino - wire by wire? ?
How much battery voltage and amperes do I need for powering everything in the project??
Is this product possible to build and work smoothly?

If any of the users have helping links and information I am greatful because I am new to Arduino world , I still have to learn a lot.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Barcode reader for arduino

Post by adafruit_support_rick »

Hi.
magnetto123 wrote:Do I need a PS/2 connector to the arduino or can I mount the bar code scanner to the Arduino - wire by wire? ?
You can do that. The adapter is just for convenience.
magnetto123 wrote:-Arduino Uno R3 - Atmega328 P
- Bar code Reader ( http://www.adafruit.com/products/1202 )
- Display ( http://www.adafruit.com/products/1480 )
- Battery (http://www.adafruit.com/products/328 )
- Charger (http://www.adafruit.com/products/259 )
You can't run a Uno from that battery. The Uno needs at least 7V input. You would be better off with a 6xAA battery pack. You can use rechargeable or alkaline AA batteries.
http://www.adafruit.com/products/248

Alternately, you could use a Flora instead of a Uno. That will run from a LiPo battery pack.
http://www.adafruit.com/products/659

You can power the display from the Flora.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”