Before i even tell you the problem that i'm facing this is the hardware which i'm using :
- Arduin Uno
- USB Shield Host 2.0
- I2C 16x2 LCD
- Datalogic Gryphon 4470
So to get in point, I'm currently working on a project which aims to scan QR codes / bar codes through a barcode scanner (Datalogic Gryphon) somehow a fixed type on some kind of test interface.
In the normal case it should be able to scan and display the code on an LCD .
After scanning the barcode i should save what i get on a Text File "As simple As that ". I'm trying to connect the scanner with the arduino using an USB Shield Host 2.0. It should be able to read or to display something on the serial monitor but it doesn't seem to work or even show the messages which are on the code.
I've tryed to change the speed but that didn't work out too . I doubt that the problem is the serial communication between the two of them.
I really can't figure it out.Any help please !! Thanks in advance.
The code that i'm used is perfectly compiled here it is :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
SoftwareSerial mySerial(2,3);//RX,TX
char code[28];
char code_1[28]; // tab of 28 cases
char code_2[28];
char code_3[28];
char code_4[28];
char code_5[28];
byte i; // compteur des tableaux
int etat = 0;
int bouton = 0;
//int SELA = 11;
//int SELB = 12;
//int SELC = 13;
int oldstate =0 ;
void setup() {
Serial.begin(9600);//opens Serial port,sets data rate to 9600 bps
mySerial.begin (9600);//opens serial port,sets data rate to 9600 bps
//initialisation du LCD
lcd.init();
//Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("initialisation ");
lcd.setCursor(1,1);
lcd.print("du system");
// déclaration des entrées / sorties
//pinMode(SELA,OUTPUT);
//pinMode(SELB,OUTPUT);
//pinMode(SELC,OUTPUT);
//pinMode(bouton,INPUT);
//4
mySerial.print("initialisation ");
}
void remplir ()
{
// i=0;
if(Serial.available() )// on a reçu quelque chose dans le serial
{
code[0] = Serial.read();// je récupère le premier char reçu .
i = 1;
while (i<27)
{
while (!Serial.available()); // j'attends l'arrivée du prochain .
code[i]=Serial.read();//je récupère celui qui vient d'arriver .
if (code[i]== '\0') break; // on a réçu une fin de chaine , alors on sort de while()
i++;
}
code[28]='\0'; // dans le cas où le code est > 28 chiffres, on impose une fermeture de chaine .
mySerial.println(code);
}
}
void loop() {
mySerial.println("loup");
etat = digitalRead(bouton);
if( etat==1){
oldstate=1;
mySerial.println("ouvert");
}
else if( (oldstate==1) && (etat==0))
{
oldstate=0 ;
mySerial.println("fermer");
mySerial.println("scan_1");
//digitalWrite (SELA,LOW);
//digitalWrite (SELB,LOW);
//digitalWrite (SELC,LOW);
remplir();
}
}
codetab.ino (2.16 KB)