Barcode scanner

Good morning
I am working on a code to help people track their dially consumption of different food nutrients. The user have two choices between:

  1. Scanning the barcode of the food item
  2. Enter the food code and the quantitiy, for items without a barcode using a keypad

The barcode scanner code was taken from Arduino playground, and it succeesfully scan and identify the food item. However, when I intergrate the codes of 1 and 2, the barcode scanner doesn’t identify the items.

I added the run results for the scanner alone, and after the intigration.

Any help is appreciated.
Thanks

RunResult_Integration.pdf (253 KB)

RunResult_ScannerAlone.pdf (28.9 KB)

We can't help you using screenshots. Post the code.

I am having a problem posting the code.

I got this message"exceed size"

I can send it via email

The code is very long.

Kindly check the attached error message.

ErrorMessage.pdf (125 KB)

How can I post the code ?? Please I need your support.

Thanks

looking at the code in the file RunResult_Integration.pdf in post #1 you appear to be repeating the same sequence of statements on different data multiple times which is probably why your code is very long
could you use a function ?
post you original scanner code?

original barcode scanner code, from Arduino play ground

/*
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 = 20; // Clock is only output. 
int dataPin = 21; // 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(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] );                                       
				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;                                                            
}
/////food database 
int Calories  = 0;  
int Fat_g =0; 
int Carbohydrate_g = 0;
 

int Calories_sum  = 0;  
int Fat_g_sum =0; 
int Carbohydrate_g_sum = 0;


///// Keypad
char m[4]; 
byte y=0;
boolean OK=0;
byte n = 0;
int REF=0; 
char Quantity[2]= {0,0}; 
#include <Keypad.h>  
const byte ROWS = 4; 
const byte COLS = 3; 
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; 
byte colPins[COLS] = {8, 7, 6}; 

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

/////////////////////////////////// Serial LCD
#include <SoftwareSerial.h>
SoftwareSerial mySerial(15,14); /
////////////////////////////////////////////////////////Barcode 

int SCAN_ENTER = 0x5a; 
int SCAN_BREAK = 0xf0;
int breakActive = 0;
int clockPin = 7; 
int dataPin = 6; 				
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



int count=0; 
///////////////////////////////////////////////////////////////
void setup(){
  Serial.begin(115200); 
  mySerial.begin(9600); 
  delay(500); /
  ///////////////////     Barcode
  pinMode(dataPin, INPUT);                                               
  pinMode(clockPin, INPUT);                                              
  pinMode(ledPin, OUTPUT);                                               
	

  
}
  
void loop(){
  //count = count +1;
  Serial.print("countStart");  Serial.print(count);
 

  mySerial.write("Scan barcode or Enter 5555:");
  
  while (n<4)
  { 
    char key = keypad.getKey();
    if (key != NO_KEY)
    {
      m[n]=key; 
      n=n+1;
      mySerial.print(key);
      Serial.print(key);
      if (strcmp(m, "5555") == 0)  {ClearLCD(); mySerial.write("Enter food code: ");delay(2000);     ClearLCD();  n=0; for (int i=0; i<4; i++) {m[i]='\0'; }EnterQunatity(); }
      else {ClearLCD(); mySerial.write("Scan barcode: ");  for (int i=0; i <= 50; i++) {barcode();} mySerial.write("Done "); }
    }
  }       
  
}




int EnterQunatity()
{
double Amount;

  while (n<4)
  { 
    char key = keypad.getKey();
    if (key != NO_KEY)
    {
      m[n]=key; 
      n=n+1;
      mySerial.print(key);
      Serial.print(key);
      if (strcmp(m, "1111") == 0)  { mySerial.write("Peacon");delay(1000); REF=11;ClearLCD();n=0;
                                     for (int i=0; i<4 ; i++) {m[i]=0;} mySerial.write("Enter Quantity: ");delay(1000);
                                     Amount=Get_Number_Keypad(); Peacon(Amount); Total_AND_DisplayLCD();} 
                                  
    }
  }
  
  Serial.print("check="); delay(2000); 
  for (int k=0; k<4; k++) {Serial.print(Amount); delay(1000);}
  
  return Amount; 
}
///////////////////////////////////clear LCD

void ClearLCD()
{
  mySerial.write(254); mySerial.write(128);
  mySerial.write("                "); 
  mySerial.write("                ");
  mySerial.write(254); 
  mySerial.write(128);
}


/////////////////////////////////////

int Get_Number_Keypad()
{
  n=0; 
     while (n < 4)
     
     { char key = keypad.getKey(); 
     if (key != NO_KEY)
     {
       Quantity[n]=key; 
       n=n+1;
       mySerial.print(key);
       Serial.print(key); 
     }
   }
   double Amount = atoi(&Quantity[0]);
   Serial.print("Amount="); Serial.print(Amount);
   int test = Amount + 10; 
   Serial.print("test="); Serial.print(test);
   return Amount; 
 }

/////////////////////////////////////Total and  display

void Total_AND_DisplayLCD (void)

{
   Calories_sum = Calories_sum + Calories;
   Carbohydrate_g_sum = Carbohydrate_g_sum + Carbohydrate_g;
   Fat_g_sum = Fat_g_sum + Fat_g;

   
   Serial.print("\tcarb_sum=");Serial.print(Carbohydrate_g_sum);  
   Serial.print("\tfat_sum=");  Serial.print(Fat_g_sum);  
   Serial.print("\tprotein_sum=");  Serial.print(Protein_g_sum);  
   delay(1000); 
   ClearLCD(); 
   
   mySerial.write("Calories:");mySerial.print(Calories_sum);
   mySerial.write(254); mySerial.write(192); 
   mySerial.write("Carb:");mySerial.print(Carbohydrate_g_sum);mySerial.write("g"); delay(5000); 
   ClearLCD(); 

   
   }





/////////////////////////////////// barcode scanner 
void barcode (void)
{
  Serial.print("countA=");
  Serial.println(count);
  count = count +1; 

////////////////////////////////// dataRead() function 
  byte val = 0;                                                          
                                
	while (digitalRead(clockPin));                                                                  
	while (!digitalRead(clockPin));                      
	while (digitalRead(clockPin));                        
	for (int offset = 0; offset < 8; offset++) {                           
		while (digitalRead(clockPin));                   
		val |= digitalRead(dataPin) << offset;              
		while (!digitalRead(clockPin));                    
	}                                                                      
                           
	while (digitalRead(clockPin));                       
	while (!digitalRead(clockPin));                  
	while (digitalRead(clockPin));                      
	while (!digitalRead(clockPin));                       
	//return val; 

dataValue = val; 
Serial.print("countB=");
Serial.println(count);

  //////////////////////////////
 
        Serial.print(dataValue);                       
	if (dataValue == SCAN_BREAK) {                                         
		breakActive = 1;                                                     
	}                                                                      
	                       
	for (int i = 0; i < quantityCodes; i++) {      	                       
		byte temp = scanCodes[i];                                            
		if(temp == dataValue){                                               
			if(!breakActive == 1){                                             
				buffer[bufferPos] = characters[i];                               
				bufferPos++;                                                     
			}                                                                  
		}                                                                    
	}                                                                      
	   
Serial.println("countC=");
 Serial.println(count);

	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++;  
			}  
		}  
 
 Serial.println("countD=");
 Serial.println(count);
  
////////////////////////////////////////////Masafi 

                 if (check[0] ==tag1[0]  && check[1] == tag1[1] && check[2] ==tag1[2]  && check[3] ==tag1[3] && check[4] ==tag1[4]  ) 
                    {Serial.println("\tMasafi"); 
                     mySerial.write(254); mySerial.write(128);
                     mySerial.write("                "); 
                     mySerial.write("                ");
                     mySerial.write(254); mySerial.write(128);
                     mySerial.write("Masafi");
                     count=count+1; 
                     Serial.print("CNT=");Serial.println(count);
                     mySerial.write("count");mySerial.print(count);}                                        
	} 

       
Serial.print("countE=");
Serial.println(count);

            
	if(dataValue != SCAN_BREAK){                                           
		breakActive = 0;                                                     
	}                                                                      
	dataValue = 0;                                              
  
}
  
///////////////////// food database from barcode 

int Masafi() {
 Calories =5;  
 Fat_g =5; 
 Carbohydrate_g = 5; 
 Protein_g = 5; 
 Sodium_mg = 5; 

return Calories; Fat_g; Carbohydrate_g; Protein_g; Sodium_mg;  }
 

 //////////// 
   
   
   int Peacon(double Amount)
   {
     Serial.print("Amount 3rd time="); Serial.print(Amount); delay(2000);  

     Calories  = 691* (Amount/100);  Serial.print("Amount");Serial.print(Amount/100); delay(3000); Serial.print("Calories=");Serial.print(Calories); delay(3000); 
     Fat_g =72 * (Amount/100);
     Carbohydrate_g = 14 * (Amount/100); 
 
 return Calories; Fat_g; Carbohydrate_g;  }

I removed the redundant parts and I divided the code into two posts.

Please advise.

For what it's worth, if you know how to attach a .pdf, you know how to attach an .ino