<mosaic.cnfolio.com>

Project journal


22/03/12

Welcome to my journal!

This logbook will be maintained on-line to share my ideas with fellow students. Every three days will be updated in the procedure section to record my
process and report any problems I faced and the techniques used to solve them. In addition schematics, pictures and diagrams will be used and explained for better
understanding of the procedure. In addition I will also state my goals for the next three days. Now allow me to make a quick overview of what the product should do.

The idea is to develop a product which a user could easily create a shopping list by scanning barcodes using a barcode reader and send the shopping list
on a mobile device using SMS service. This will achieved using a prototype called Arduino combined with another two shields, WiFly to send the processed data over WiFi connection
and a USB-host-shield to accept USB inputs (barcode reader device). More information about the shields will be provided along with the diagram.

Please see the diagram below.

text


Explanations will be added after

Test equipment, establish wireless connection and retrieve data from a website

By 12 March I received all my components I will use in this project. The equipment was bought using ebay.co.uk and coolcomponents.co.uk websites. My expectations was to receive the component before 2nd of March but a delay was caused by a seller on Ebay. At the end after a complain I received my item. For that reason I changed my plan accordingly and I decided to work more hours each day to catch up.

Procedure


Step 1 (Testing the products)

After receiving all items it was time to test the products. The first step it was to download and install the drivers and Arduino 0023 version IDE on my PC. Arduino Uno board, WiFiy and USB-host-shield where connected together using board to board connectors. The first problem I faced was that the two shields didn't power up when I connected the USB cable on my PC. After I slightly moved the connectors with my hand on pins 3.3v and ground the circuit closed and the PCB boards powered up. Obviously the problem was the bad contact between the two shields and the Arduino board providing the current. To verify that I used a multimeter to test the continuity and as I expected it failed. To fixed that I visited the Lab and I asked a stuff member what is the best solution. The guy there was very helpful and told me that we have to solder the connectors with the PCB board to make a stable contact.

See below the pictures:

PICS TO BE ADDED

Step 2 (Establish a wireless connection)

To establish a wireless connection with my home router I used the Wify auto connect example provided in Arduino IDE:

WiFly_AutoConnect_Terminal
#include "WiFly.h"
#include "Credentials.h"

void setup() {

  Serial.begin(9600);
  Serial.println("\n\r\n\rWiFly Shield Terminal Routine");
  
  WiFly.begin();
  
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }
  
  Serial.println("Associated!");
}

void loop() {
  // Terminal routine

  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  while(SpiSerial.available() > 0) {
    Serial.print(SpiSerial.read(), BYTE);
  }
  
  if(Serial.available()) { // Outgoing data
    SpiSerial.print(Serial.read(), BYTE);
  }
}


Credentials.h
#ifndef __CREDENTIALS_H__
#define __CREDENTIALS_H__

// Wifi parameters
char passphrase[] = "passphrase"; // replaced with my details
char ssid[] = "ssid"; // replaced with my details

#endif


At the beginning the code didn't work after I uploaded on the Arduino microcontroller. I send the commands manually (see the commands bellow) on to the Wifly shield using the TeraTerm terminal to test after I initialize a connection between Arduino and WiFly. To enter the command line I used $$$ and then I typed the following arguments:

set wlan auth 3 //Mixed WPA1 & WPA2-PSK

set wlan phrase ***** //set the password for my AP

join ****   // SSID for my AP


By doing that I was able to get an IP address using the AP DHCP. After a research on the forums I solved the autoconnect issue by downloading and importing the alpha 2 library.

Step 3 (Fetch data from a webpage on the WiFly)

This step is to verify the connection between Wifly and Internet. The test was contacted using the Google webpage and a search query was made with the keyword Arduino to retrieve the search results. The code used:

byte server[] = { 66, 249, 89, 104 }; // Google

//Client client(server, 80);

Client client("google.com", 80);

void setup() {

 Serial.println("connecting...");

 if (client.connect()) {
   Serial.println("connected");
   client.println("GET /search?q=arduino HTTP/1.0");
client.println();
  } else {
    Serial.println("connection failed");
  }


Results:

text


25/03/12

Sending an e-mail using WiFly shield

In this section I will describe the procedure to send an e-mail using WiFly shield. This will help afterwords to send the scanned products in an e-mail form to the SMSC Gateway. To achieve that we need an SMTP Server to send the e-mail.

SMTP (Simple Mail Transfer Protocol)

SMTP is used for outgoing e-mails only. It transmits mails using IP networks on the new port 587 but most providers are still allow the traditional port 25.

This is how it works:

text

MUA (Mail User Agent) is the client wishes to send an e-mail. In our case is the WiFly.
WiFly is using TCP port 25 to open a communication with the SMTP server. In our case I install an SMTP server called hMailServer on my PC to act as a mail server.
It is using the yahoo SMTP server to transfer the mails. MSA (Mail Submission Agent) and MTA (Mail Transfer Agent) are located in the SMTP server. MSA delivers the mail to its mail transfer agent MTA.
After, MTA is sending the recipient high level domain (@whatever.com) to a DNS (MX) records server to resolve it. Then the DNS server replies with the IP address to the MTA and sends the e-mail to MDA ( mail delivery agent) which is able to save e-mails in the right mailbox so that the recipient user can read it.

Procedure


Step 1 ( Telnet straight to an SMTP server)

The first step is to telnet from command prompt on port 25 a free SMTP server so that it can deliver my e-mail.
I tried many SMTP servers around the globe without success. The return message was: Could not open connection to the host, on port 25 (see below)

text

Doing a little research I discovered that my ISP is blocking port 25 and the reason is to prevent people from sending spam e-mails from random e-mails.
The solution was to connect to TCP port 587 because according to the RFC 5321 2008 port 587 is using SSL to authenticate users and it is safer for spam e-mails. (see below)

text

The server requires authentication after entering the mail from command. To authenticate I used the command auth login following by username and password. After I authenticated to the yahoo mail server I still had problem (Syntax error in arguments). (see below)
I didn't find the soloution on that problem so I decided to have a go with a different server.

text

The second server was google mail server. I connected on the mail server by issuing the command telnet smtp.gmail.com 587. When I sent the command MAIL FROM: stelios_kyriacou_27@google.com the return message was Must issue a STARTTLS command first. By issuing the STARTTLS command the connection is terminated. The reason is that telnet is not using TLS in the header of the IP packet resulting the connection to lost from the host. The TLS is used to send certificate and encrytion keys to each other. Manually is impossible to add TLS header.

text

Step 2 (hMail Server configuration)
To tackle the above problems I faced I used a software called hMailServer. It is an e-mail server design for Windows systems. It allow to bypass the need of the ISP and safely manage all the incoming and outgoing e-mails.

Settings used on hMailServer:

The first think is to link hMailServer domain to an Internet domain. I used yahoo.co.uk
Specifying SMTP relayer: In this field it should be my ISP's e-mail server but I used smtp.mail.yahoo.com on port 587 with my authentication details.
IP ranges: I allowed only the server IP to send outgoing mails and given priority 15.
All the other settings remained as default.

Step 3 (Test e-mail)

To test the functionality of the server I send a test mail via telnet session.

First connected to the server using the command telnet localhost 25
helo stelios.com
auth login
MAIL FROM: stelios_kyriacou_27@yahoo.co.uk
rcpt to: stelios_kyriacou_27@hotmail.com
data
Subject: This is a test mail

This is a mail body from localhost!
.

text

The server delivered the e-mail successfully (see below)

text


Step 4 ( Configure Arduino to send e-mail)

To configure the Arduino to send an e-mail we first need to to connect to my local server. If it requires to connect to my e-mail server outside my network, instead of my private IP address to the server, I will enter the public IP address and configure the router to forward the request to the server on port 25. See below the code used to connect to the mail server:

byte server[] = { 192, 168, 1, 89 }; //my email server

//Client client(server, 25)

Client client("192.168.1.89", 25); //port 25


The next step is to send the commands to the server. Here is the code I used:

client.println("helo stelios.com");
    client.println("auth login");
    client.println("c3RlbGlvc19reXJpYW*****************");
    client.println("************");
     client.println("MAIL FROM: stelios_kyriacou_27@yahoo.co.uk");
      client.println("rcpt to: marinostheo@yahoo.gr");
    client.println("data");
    client.println("Subject: This is a test mail!");
    client.println("This is a mail body from Arduino!");
   client.println(".");


The Arduino sent the commands the server delivered the e-mail successfully (see below)

text

26/03/12

Step 5 (Sending an e-mail using WiFly shield (pressing a button))

First I setup the hardware using the example provided on the Arduino website. See bellow the diagram:

Hardware:
10K ohm resistor
Push Button

text

Results:

text

Blue wire to Arduino pin 2
Red wire to Arduino VCC
Green wire to Arduino GND

Coding

At the beginning of the program we must first state at which pin the button is connected and then set the state of the button.

const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0;     // set the state of the button 

In void setup:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input 

In void loop:

 buttonState = digitalRead(buttonPin);    // read the state of the pushbutton value
  
if (buttonState == HIGH)    // check if the pushbutton is pressed

// If the button is pressed it will send the commands to the server

delay(1000);    // prevent multible sends

Please check my video at: http://www.youtube.com/watch?v=TXWfUUVXy1I&feature=youtu.be



02/04/12

Connecting barcode reader to Arduino UNO (Failed)

I tried many different ways to connect the barcode device directly to Arduino shield and using USB-Host-Shield. I used and modify in some cases, different source codes provided online without success. The goal it is to take values from barcode reader and display the digits in serial monitor.

I am using barcode reader bought from ebay:
http://www.ebay.co.uk/itm/280819848262?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649#ht_2288wt_1110 ,

and I am using USB-Host-Shield bought from coolcomponents.com: http://www.coolcomponents.co.uk/catalog/host-shield-p-799.html

Below I will describe every try I have done to achieve my goal.

First try (connect directly the barcode reader to the Arduino PBC)

The barcode cable uses to connect to host devices is RJ-45 to USB. To connect directly to the Arduino I first figure out which wire is which. There were 6 wires in the cable. I used the multimeter to check the connectivity between them. I found out that two of the wires didn't connect at all to the RJ-45. So for that reason I used the red (5v) black(GRD) and the other two yellow and orange as the data and clock. I connected RED to 5V, Black to Ground and the data and clock to 2 and 3 digital pins. (see below)

text

Results:

The barcode reader didn't power up! I also used the following link: http://arduino.cc/playground/ComponentLib/BarcodeScanner and built the circuit on a breadboard. The results were the same. The barcode didn't turn on.

Second try ( connect the barcode using USB female hub)

My second try was to connect the original USB cable of the barcode reader (purple) to a female USB hub. Then run the wires from the USB hub to the Arduino PBC. The USB hub was removed from a working environment.
(See below)

text

Results:

The device power up as normal. I then uploaded some sketches.

http://arduino.cc/playground/uploads/ComponentLib/arduino-barcode-code.txt
http://arduino.cc/playground/Main/PS2Keyboard

It didn't work in any case.
To be sure that I didn't confuse the clock wire with the data i switch them in all cases.

Third try (connect barcode reader to USB-Host-Shield)

(See below the picture)

text

Results:

The purple USB cable is the one coming from barcode reader and is connected straight to the USB shield.

To establish SPI communication between Arduino and USB shield I used the felis_USB_Host_Shield library. This is to reset the Max3421e chip on the USB shield. At he begining I was using a newer library written by a guy named Oleg. After I contacted him on the forums he told me that the sparkfun USB Shield wont't work with his library and he pointed me out the library which might fit to my situation. I used the following source codes to achieve my goal:

http://sree.cc/electronics/barcode-readerusb-using-arduino#respond
I uploaded the code and then in serial monitor I get a message Barcode reader initialized
but after I scan my first product I get the following error: 5Data packet error: 5Set report error: 5 and on the second item I get: 5Setup packet error: ESet report error: E
I couldn't figure out what is the problem.

http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield

The code is not working because Oleg's library is not working with my spakfun PBC.

Also by using the USB shield I discovered more problems.

1. The barcode reader stop scanning after 2-3 items and I need to unplug the USB cable and plug it back again to make it work. I can't find the reason.

2. The barcode reader interfering with the WiFly Shield. This is because the WiFly shield and USB Shield are using the same pins to communicate. I found that I can change from WiFly library the pins that is using to communicate with the Arduino and run jumpers into different pins. But that will be more time consuming.

What I understood?

1. The USB cable it is not compatible with the Arduino because it cannot function as a USB host itself.

2. For the above problems I faced with the USB shield I decided to not use the shield.

3. I found many tutorials on how to configure a PS/2 barcode scanner. This will be more easier but it will require time and more money to be investigated.

Decision

I will think more and discus the problems with my supervisor and thereafter will come to a decision .

10/04/12

Connecting barcode reader to Arduino UNO (successful)

After a long research I managed to connect the barcode scanner to the Arduino. The problem was the barcode reader I was using. For that reason I bought a new one from Ebay: http://www.ebay.co.uk/itm/280771509153?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649#ht_2014wt_905

This scanner is using PS/2 connector. The one end of the cable is RJ-45 and the other end has a PS/2 male and PS/2 female. (see below)

text

text

My first try was to run the VCC, GRD, CLK, DATA wires from the female connector to the Arduino pins. I followed the diagram below to figure out which pin is which.

text


It did power up but when I was uploading the code, it didn't work. For that reason I decided to make an experiment to see if the hardware has problem or the code I am using. I wrote a simple code to read the value of clock on digital pin 3. I initialized the clock pin to 0 and then I run the program on serial monitor. To see if that is working I scanned a product to forced the clock to go low. The result was that the clock was remaining high (1) even if I was scanning a product. So the problem was the hardware.

My second attempt was to connect the male PS/2 to the female and then run wires to the corresponding pins. See below the connection:

text

Black: GND
Red: VCC
Orange: CLK to pin 3
Brown: DATA to pin 2

Then I uploaded the following code to test:

/*
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;                                                            
}


This time it worked. I managed to get the barcode numbers on the serial monitor. The problem was that the female connector is accepting inputs and the male is sending.

Code explanation:


13/04/12

Connecting LCD with Arduino

The first think was to connect the LCD to the Arduino. I followed the diagram bellow provided in the arduino website, under learning.

Circuit
RS pin to digital pin 12
E pin to digital pin 11
D4 pin to digital pin 5
D5 pin to digital pin 4
D6 pin to digital pin 3
D7 pin to digital pin 2
Vcc pin to potentiometer (left pin) and to VCC (Arduino)
Vo pin to potentiometer (centre pin)
R/W and GND pins to potentiometer (right pin) and to GND (Arduino)

text

The screen used is a Hitachi 16x2 4-bit provided by the University. The 4-bit model requires 7 pins from Arduino.
The potentiometer will be used to control the screen brightness.

My first step after the wiring was to upload a little piece of code to test the LCD. This code should print "hello, word!" and at the second row will have a timer. (See below the code)

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}


Result:

text


Display the barcode number on the LCD screen

Now that I know LCD is working it is time to print the barcode number to the screen. The following code lines have been added to the program:

 #include <LiquidCrystal.h> // The LCD library has been added

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);     //  initialize the library with the numbers of the interface pins
 
In void setup:
lcd.begin(16, 2);   // set up the LCD's number of columns and rows

In void loop:
lcd.print( buffer[i] );    // instead of printing the buffer to the serial interface I set it to print it to the LCD

Below is the result:

text

This is a video on YouTube demonstrating my results: http://www.youtube.com/watch?v=OO8h2M83srs&context=C458861aADvjVQa1PpcFMkdA71dtsLcTws0VVZzyCPw_7HSv3dIlo=

Coming Next:

Built the database

Sending the products in text message format

24/04/12
The code taken from http://arduino.cc/playground/uploads/ComponentLib/arduino-barcode-code.txt was simplified using the PS2Keyboard.h library.

The code below can take the value of the scanned product and convert it to a number using the PS2Keyboard.h library. After the algorithm is performed to much the product barcode number to a friendly
product name. Also a counter has been used to count how many products have been scanned. Then the name is printed on the LCD. Furthermore if a barcode number dose not exist in the array, an error message is printed. In case the user scan more products than MAX_SCANNED_PRODUCTS an error message is returned.

#include <LiquidCrystal.h>   
#include <PS2Keyboard.h>

const int DataPin = 6;
const int IRQpin =  7;


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
PS2Keyboard barCodeScanner;

const int NUMBER_OF_PRODUCTS = 10;
const int MAX_SCANNED_PRODUCTS = 15;

String ERROR_MSG = "Invalid barcode/Too many products scanned";
String productNames[NUMBER_OF_PRODUCTS] = {"Product_1","Product_2","Product_3","Product_4","Product_5","Product_6","Product_7","Product_8","Product_9","Product_10"};
String productBarCodes[NUMBER_OF_PRODUCTS] ={"5030930103002","5000226001961","8711600633896","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf"};
String scannedProducts[MAX_SCANNED_PRODUCTS] = {"xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx"};

int numScannedProducts = 0;
String newProductBarCode = "";
String newProductName = "";
bool shoppingListSent = false;

int productIndex(String scannedBarcode) {
  for (int i=0; i<NUMBER_OF_PRODUCTS; i++) {
     if (scannedBarcode == productBarCodes[i]) {
       return i;
     }
  }
  return -1;
}

void addNewProduct(String newProductName){
  scannedProducts[numScannedProducts++] = newProductName;
}

void setup() {
  delay(1000);
  lcd.begin(16, 2);
  delay(1000);
  barCodeScanner.begin(DataPin, IRQpin);
}
  void loop() {
     if (barCodeScanner.available() /*&& (buttonState != HIGH)*/ && (!shoppingListSent) && (numScannedProducts < MAX_SCANNED_PRODUCTS)){
    
    // read the next key
    char c = barCodeScanner.read();
    
    // check for some of the special keys
    if (c == PS2_ENTER) {
      newProductName = productNames[productIndex(newProductBarCode)];
      lcd.clear();
      addNewProduct(newProductName);
      lcd.print("Pr.#" + String(numScannedProducts) + ": " + newProductName);
      newProductBarCode = "";
    } else {
      newProductBarCode.concat(c);
    }
  
    }
  }


Coming Next:

Sending the products in text message format

02/05/12

Now it is time to send the scanned products to a text message. The first step I took, was to embed the code written to send an e-mail to the above program.
After, I altered the code to send the scanned products if the button is pressed.

At the beginning I was using 12, 11, 5, 4, 3, 2 pins for the LCD, but after I uploaded the code that was using the WiFly shield a problem occurred. I was getting F's on the
screen. After some research I found out that WiFly shield is using 10-13 pins to communicate with Arduino and that was interfiening with the LCD. For that reason I changed
12 and 11 pins to 8 and 9.

Next minor problem was that I run out of digital pins so for the button I used the Analogue pin 0 and I leant how to program it.

I used my supervisor's SMSC Getaway server to deliver the SMS text message.

Below is the code I used

#include "WiFly.h"
#include <LiquidCrystal.h>   
#include <PS2Keyboard.h>

int button = A0;

const byte server[] = { 192, 168, 1, 89 }; //email server

//Client client(server, 25);

Client client("192.168.1.89", 25);

const int DataPin = 6;
const int IRQpin =  3;

const char passphrase[] = "********";
const char ssid[] = "mowww";


LiquidCrystal lcd(9, 8, 5, 4, 7, 2);
PS2Keyboard barCodeScanner;

const int NUMBER_OF_PRODUCTS = 8;
const int MAX_SCANNED_PRODUCTS = 15;

const String ERROR_MSG = "Invalid barcode";
const String productNames[NUMBER_OF_PRODUCTS] = {"Bacardi Breezer","Cooked Ham","Honey","Deodorant Spray","Milk","Coffee","Water","Eggs"};
const String productBarCodes[NUMBER_OF_PRODUCTS] = {"5010677018296","5050179821543","5011273040360","8711600633896","5020201473866","5011546415482","5010358147024","5024550316003"};
String scannedProducts[MAX_SCANNED_PRODUCTS] = {"xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx"};

int numScannedProducts = 0;
String newProductBarCode = "";
String newProductName = "";
bool shoppingListSent = false;

int productIndex(String scannedBarcode) {
  for (int i=0; i<NUMBER_OF_PRODUCTS; i++) {
     if (scannedBarcode == productBarCodes[i]) {
       return i;
     }
  }
  return -1;
}

void addNewProduct(String newProductName){
  scannedProducts[numScannedProducts++] = newProductName;
}

void setup() {
    
  lcd.begin(16, 2);
  delay(1000);

  Serial.begin(9600);
  
  Serial.println("\n\r\n\rWiFly Shield Terminal Routine");
  
  WiFly.begin();
  
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }
  
  Serial.println("Associated!");
  
  if (client.connect()) {
    Serial.println("connected");
  } else {
    Serial.println("connection failed");
  }
  delay(1000);
  barCodeScanner.begin(DataPin, IRQpin);
  delay(1000);
}

void loop() {

  int buttonValue = analogRead(A0);

  if( (!shoppingListSent) && (buttonValue < 1000) && (numScannedProducts < MAX_SCANNED_PRODUCTS)){
    if (barCodeScanner.available()) {
      char c = barCodeScanner.read();
      
      if (c == PS2_ENTER) {
        lcd.clear();
        if (productIndex(newProductBarCode) == -1) {
          lcd.print(ERROR_MSG);
        } else {
          newProductName = productNames[productIndex(newProductBarCode)];
          addNewProduct(newProductName);
          lcd.print("Pr.#" + String(numScannedProducts) + ": " + newProductName);  
        }
        newProductBarCode = "";
      } else {
        newProductBarCode.concat(c);
      }
    }
  } else {
    lcd.clear();
    if (!shoppingListSent){
      
      lcd.print("Sending shopping list...");
       
      if (buttonValue > 400)    // check if the pushbutton is pressed(true)
      {     
        client.println("helo Stelios");
        client.println("auth login");
        client.println("******password***********");
        client.println("********password**************");
        client.println("MAIL FROM: stelios_kyriacou_27@yahoo.co.uk");
        client.println("rcpt to: sms@cnfolio.com");
        client.println("data");
        client.println("Subject: MyPhoneNumber");   
        for (int i = 0; i<numScannedProducts; i++) {
          client.println(scannedProducts[i]);
        }
        client.println(".");
        delay(1000);    // prevent multiple sends
       shoppingListSent = true;
      } 
      }
    lcd.clear();
    lcd.print("Finished!");
  }
}




Please take a look at my video on YouTube: http://www.youtube.com/watch?v=5Z1sz7ByO9A





Optimizing the product

To optimize the product I will make use of the EEPROM to store more products or try to connect the product to an external database.

Currently the product is working within my home network. I tried to connect it with the university network, eduroam, but is using SSL certificate to authenticate
the users using username and password. I shall make it work by the next week.





The circuit

Draft

text


In the final report this digram will be designed in the AutoCad software.


Designing the product

09/05/12

The last few days I was working in the lab to design and develop a practical box for my product.
My main target was to produce a product that will be portable as well as lightweight. 4 AA batteries have been used to feed the components and the battery holder has been placed beneath the black box.
Below there are some pictures of the finished product:


text

text

Coming Next

Develop the products catalogue along with user instructions.

01/06/2012

This is the link for the final product advertisement: http://www.youtube.com/watch?v=PdR83a0diac&feature=youtu.be
Attachment Timestamp Size
IMG_0371.JPG 2012-05-08 21:37 284.09 KB
IMG_0372.JPG 2012-05-08 21:36 282.33 KB
circuit.png 2012-05-02 18:33 1.2 MB
IMG_0329.JPG 2012-04-12 19:39 344.18 KB
button_diagram.jpg 2012-04-12 19:29 84.92 KB
IMG_0343.JPG 2012-04-12 19:13 267.01 KB
IMG_0330.JPG 2012-04-12 18:49 333.05 KB
LCD_diagram.jpg 2012-04-10 14:33 78.45 KB
connection.jpg 2012-04-10 14:20 229.05 KB
ps2.jpg 2012-04-10 13:50 54.11 KB
IMG_0342.JPG 2012-04-10 13:22 239.98 KB
IMG_0341.JPG 2012-04-10 13:19 265.38 KB
IMG_0332.JPG 2012-04-02 08:54 232.17 KB
IMG_0331.JPG 2012-04-02 08:17 233.52 KB
IMG_0333.JPG 2012-04-02 08:04 258.25 KB
send_email_localhost_bingo1.png 2012-03-25 17:17 42.26 KB
email_from_arduino.jpg 2012-03-25 17:13 46.75 KB
hotmail_e-mail.jpg 2012-03-25 16:35 47.8 KB
send_email_localhost_bingo.png 2012-03-25 16:33 45.78 KB
fail_telnet_google.jpg 2012-03-25 15:17 50.82 KB
fail_syntax_unkonwn error.jpg 2012-03-25 15:11 69.27 KB
telnetbingo.jpg 2012-03-25 14:52 23.7 KB
failtelnet1.jpg 2012-03-25 14:36 40.34 KB
e-mail.jpg 2012-03-25 13:37 23.93 KB
google connect.png 2012-03-22 10:27 119.12 KB
Design.jpg 2012-03-22 08:15 39.77 KB