barcode

Good morning

I need to interface the barcode reader linked below to Arduino.
I am using PS2 to breadboard connector also linked below.

Why there are two connectors in the barcode reader (male and female) ?

The barcode terminals are listed below.
Brown is data
Green is VCC
Black is ground
Yellow is clock

I used the connection diagram and the code posted at the link below.
https://playground.arduino.cc/ComponentLib/BarcodeScanner

When I press on the button at the scanner, the flash light turns ON and OFF but there is no sound
and I didn't get any info at the serial monitor.

Appreciate your early reply.
Thank you

(deleted)

spycatcher2k:
Why are you asking here? We don't do product support for Adafruit!

The tutorial is posted at Arduino website ???

Why there are two connectors in the barcode reader (male and female) ?

It says on the website

its designed to be a 'pass through keyboard wedge' device for point-of-sale terminals

So one to plug your keyboard into one and the other is to plug into your computer.

We can’t help if we don’t know what you have done. What sort of help were you expecting when all you say is you followed some tutorial and it didn’t work?

You have either wired it up wrong or have the software wrong but who knows because you have not told us what you have done and my crystal ball is on the blink at the moment.

Kindly check the connector image to check each colored wire is correctly identified.
These are from the male connector of the barcode scanner.
They are connected as below:

Brown wire (pin 1 in the male connector) is data and it's connected to pin 2 in Arduino (through a 2.2k resistor).

Black wire (pin 3 in the male connector) is connected to ground.

Yellow wire (pin 5 in the male connector) is clock and it's connected to pin 3 in Arduino (through a 2.2k resistor)

Green wire (pin 4 in the male connector) is connected to VCC

The white and the red (pin 2 and 6 respectively) are not connected

Kindly check image 2 that shows the connection to Arduino.

I am using three resistors of 1k, 1k and 220 to get the 2.2kohms resistor.

barcode1.pdf (1.16 MB)

Kindly check the code and the connection to Arduino mega attached.

/*
Barcode Scanner                                                        
	This code reads the input from a ps/2 keyboard or keyboard-like        
	device (e.g. a barcode scanner), translates the scan-codes into        
	numbers (only numbers from 0 to 9 can be used at the moment)           
	It is nowhere near a complete implementation of the ps/2 protocol,     
	but it should give you a starting point.                               
	mys .// Benjamin Maus	( benjamin.maus <at> allesblinkt.com )          
	2007                                                                   
*/

int SCAN_ENTER = 0x5a; int SCAN_BREAK = 0xf0;
int breakActive = 0;
int clockPin = 3; // Clock is only output. 
int dataPin = 2; // The data pin is bi-directional
				// But at the moment we are only interested in receiving   
int ledPin = 13;  // When a SCAN_ENTER scancode is received the LED blink
int clockValue = 0; byte dataValue;
byte scanCodes[10] = {0x45,0x16,0x1e,0x26,0x25,0x2e,0x36,0x3d,0x3e,0x46}; char characters[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
int quantityCodes = 10;
char buffer[64] = {};	// This saves the characters (for now only numbers) 
int bufferPos = 0; 
int bufferLength = 64;


void setup() {
	pinMode(dataPin, INPUT);                                               
	pinMode(clockPin, INPUT);                                              
	pinMode(ledPin, OUTPUT);                                               
	Serial.begin(9600);                                                    
}

void loop() {
	dataValue = dataRead();                                                
	// If there is a break code, skip the next byte                        
	if (dataValue == SCAN_BREAK) {                                         
		breakActive = 1;                                                     
	}                                                                      
	// Translate the scan codes to numbers                                 
	// If there is a match, store it to the buffer                         
	for (int i = 0; i < quantityCodes; i++) {      	                       
		byte temp = scanCodes[i];                                            
		if(temp == dataValue){                                               
			if(!breakActive == 1){                                             
				buffer[bufferPos] = characters[i];                               
				bufferPos++;                                                     
			}                                                                  
		}                                                                    
	}                                                                      
	//Serial.print('*'); // Output an asterix for every byte               
	// Print the buffer if SCAN_ENTER is pressed.                          
	if(dataValue == SCAN_ENTER){                                           
		Serial.print("\nbuffer: ");                                          
		// Read the buffer                                                   
		int i=0;																		                         
		if (buffer[i] != 0) {                                                
			while(buffer[i] != 0) {                                            
				Serial.print( buffer[i] );                                       
				buffer[i] = 0;                                                   
				i++;                                                             
			}                                                                  
		}                                                                    
		Serial.println(" [Enter]");                                          
		bufferPos = 0;                                                       
		// Blink the LED	                                                   
		digitalWrite(ledPin, HIGH);                                          
		delay(300);                                                          
		digitalWrite(ledPin, LOW);                                           
	}                                                                      
	// Reset the SCAN_BREAK state if the byte was a normal one             
	if(dataValue != SCAN_BREAK){                                           
		breakActive = 0;                                                     
	}                                                                      
	dataValue = 0;                                                         
}

int dataRead() {
	byte val = 0;                                                          
	// Skip start state and start bit                                      
	while (digitalRead(clockPin));  // Wait for LOW.                       
	// clock is high when idle                                             
	while (!digitalRead(clockPin)); // Wait for HIGH.                      
	while (digitalRead(clockPin));  // Wait for LOW.                       
	for (int offset = 0; offset < 8; offset++) {                           
		while (digitalRead(clockPin));         // Wait for LOW               
		val |= digitalRead(dataPin) << offset; // Add to byte                
		while (!digitalRead(clockPin));        // Wait for HIGH              
	}                                                                      
// Skipping parity and stop bits down here.                            
	while (digitalRead(clockPin));           // Wait for LOW.              
	while (!digitalRead(clockPin));          // Wait for HIGH.             
	while (digitalRead(clockPin));           // Wait for LOW.              
	while (!digitalRead(clockPin));          // Wait for HIGH.             
	return val;                                                            
}

barcode2.pdf (950 KB)

Now it's working. I was not careful of the distance between the reader and the barcode.

: )

You might have mentioned you cross posted on the Adafruit forum.

https://forums.adafruit.com/viewtopic.php?f=48&t=128103

gdsports:
You might have mentioned you cross posted on the Adafruit forum.

https://forums.adafruit.com/viewtopic.php?f=48&t=128103

Is that a problem ?????

Is that a problem ?????

Yes, can you not see that?

You are asking people for free help. If you get help in both places then you waste the time of people duplicating answers. It is very selfish of you.

Grumpy_Mike:
Yes, can you not see that?

You are asking people for free help. If you get help in both places then you waste the time of people duplicating answers. It is very selfish of you.

It's their product and they should provide technical support for that.
I am posting at Arduino forum because I am using their product also.

Thank you

OK with that attitude you will not make many friends here.

Grumpy_Mike:
OK with that attitude you will not make many friends here.

Dear,

This is about being professional, there is no attitude here.

FutureEngineer:
Dear,

This is about being professional, there is no attitude here.

Professional also includes polite.

I'm seeing an over-inflated and misplaced sense of entitlement here.

If you want to break the rules just because you want an answer quickly, you'd better be prepared to cope with the backlash.
People here owe you nothing.

Remembering this will serve you well when you leave academia and try to get on in the real world.

FutureEngineer:
This is about being professional, there is no attitude here.

Fine I'm willing to be professional. And as a professional I will naturally expect to be paid. How much are you offering?

Steve

FutureEngineer:
This is about being professional, there is no attitude here.

That is where you are wrong, and unless you learn you will never be an engineer in the future. Their is a lot more to professionalism than just being good, and you are not even good yet.

Dear Arduino enthusiasts,

I honestly thought this fourm is supported by Arduino to provide technical support.

Any way thanks for all those share their valuable time and offered some help me in solving my problem.

Kind regards.

I hope I can still come back to the forum and get some help when I am stuck. :-[ :-[ :-[

I managed to modify the code to compare the scanned code with the saved ones.
When I run the code, it only identifies the first barcode correctly and then nothing appear at the serial monitor, it's like the serial monitor freezes.
Despite that the buzzer make the sound of detecting the barcode, any idea why I have this problem ?

int SCAN_ENTER = 0x5a; int SCAN_BREAK = 0xf0;
int breakActive = 0;
int clockPin = 3; 
int dataPin = 2; 
				
int ledPin = 13;  // When a SCAN_ENTER scancode is received the LED blink

int clockValue = 0; 
byte dataValue;
byte scanCodes[10] = {0x45,0x16,0x1e,0x26,0x25,0x2e,0x36,0x3d,0x3e,0x46}; 
char characters[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
int quantityCodes = 10;
char buffer[64] = {};	// This saves the characters (for now only numbers) 
char check[10]={'0','0','0','0','0','0','0','0','0','0'};  
int bufferPos = 0; 
int bufferLength = 64;

char tag1[5] = {'6','2','9','1','0'}; //masafi
char tag2[5] = {'6','2','9','1','1'}; //alain
char tag3[5] = {'6','2','9','7','0'}; //maiDubi
char tag4[5] = {'5','4','4','9','0'}; ////cocacola
char tag5[5] = {'0','1','2','0','0'}; ////7up
char tag7[5] = {'6','2','8','1','0'}; ////Al Rabie
char tag8[5] = {'4','7','9','2','0'}; ////Coconut water

int count=0; 

//

void setup() {
	pinMode(dataPin, INPUT);                                               
	pinMode(clockPin, INPUT);                                              
	pinMode(ledPin, OUTPUT);                                               
	Serial.begin(115200);                                                    
}

void loop() {

	dataValue = dataRead();                                                
	// If there is a break code, skip the next byte                        
	if (dataValue == SCAN_BREAK) {                                         
		breakActive = 1;                                                     
	}                                                                      
	// Translate the scan codes to numbers                                 
	// If there is a match, store it to the buffer                         
	for (int i = 0; i < quantityCodes; i++) {      	                       
		byte temp = scanCodes[i];                                            
		if(temp == dataValue){                                               
			if(!breakActive == 1){                                             
				buffer[bufferPos] = characters[i];                               
				bufferPos++;                                                     
			}                                                                  
		}                                                                    
	}                                                                      
	//Serial.print('*'); // Output an asterix for every byte               
	// Print the buffer if SCAN_ENTER is pressed.                          
	if(dataValue == SCAN_ENTER){                                           
		Serial.print("\nbuffer: ");                                          
		// Read the buffer                                                   
		int i=0;																		                         
		if (buffer[i] != 0) {                                                
			while(buffer[i] != 0) {                                            
				Serial.print( buffer[i]);
                                 check[i]=buffer[i];
				 buffer[i] = 0;
				i++;  
			}  
		}  

                 if (check[0] ==tag1[0]  && check[1] == tag1[1] && check[2] ==tag1[2]  && check[3] ==tag1[3] && check[4] ==tag1[4]  ) 
                    {Serial.println("\tMasafi"); count=count+1; Serial.print("count=");Serial.println(count);} 
                 if (check[0] ==tag2[0]  && check[1] == tag2[1] && check[2] ==tag2[2]  && check[3] ==tag2[3] && check[4] ==tag2[4] ) {Serial.println("\tAlain");}
                 if (check[0] ==tag3[0]  && check[1] == tag3[1] && check[2] ==tag3[2]  && check[3] ==tag3[3] && check[4] ==tag3[4]){Serial.println("\tMai Dubai");} 
                 if (check[0] ==tag4[0]  && check[1] == tag4[1] && check[2] ==tag4[2]  && check[3] ==tag4[3] && check[4] ==tag4[4] ) {Serial.println("\tCocacola");}
                 if (check[0] ==tag5[0]  && check[1] == tag5[1] && check[2] ==tag5[2]  && check[3] ==tag5[3] && check[4] ==tag5[4]){Serial.println("\t7UP");}  
                 if (check[0] ==tag7[0]  && check[1] == tag7[1] && check[2] ==tag7[2]  && check[3] ==tag7[3] && check[4] ==tag7[4]){Serial.println("\tAl Rabie");} 
                 if (check[0] ==tag8[0]  && check[1] == tag8[1] && check[2] ==tag8[2]  && check[3] ==tag8[3] && check[4] ==tag8[4]){Serial.println("\tCocunut Water");} 
                                     
		Serial.println(" [Enter]");  
                Serial.print("Check="); 																                         
                for (int i=0; i <= 10; i++){ Serial.print(check[i]);  delay(10); }             
		bufferPos = 0;                                                       
		// Blink the LED	                                                   
		digitalWrite(ledPin, HIGH);                                          
		delay(300);                                                          
		digitalWrite(ledPin, LOW);                                           
	} 

       

	// Reset the SCAN_BREAK state if the byte was a normal one             
	if(dataValue != SCAN_BREAK){                                           
		breakActive = 0;                                                     
	}                                                                      
	dataValue = 0;                                                         
}

int dataRead() {
	byte val = 0;                                                          
	// Skip start state and start bit                                      
	while (digitalRead(clockPin));  // Wait for LOW.                       
	// clock is high when idle                                             
	while (!digitalRead(clockPin)); // Wait for HIGH.                      
	while (digitalRead(clockPin));  // Wait for LOW.                       
	for (int offset = 0; offset < 8; offset++) {                           
		while (digitalRead(clockPin));         // Wait for LOW               
		val |= digitalRead(dataPin) << offset; // Add to byte                
		while (!digitalRead(clockPin));        // Wait for HIGH              
	}                                                                      
// Skipping parity and stop bits down here.                            
	while (digitalRead(clockPin));           // Wait for LOW.              
	while (!digitalRead(clockPin));          // Wait for HIGH.             
	while (digitalRead(clockPin));           // Wait for LOW.              
	while (!digitalRead(clockPin));          // Wait for HIGH.             
	return val;                                                            
}