Go Down

Topic: Finding trouble displaying barcodes from a scanner using LCD and Arduino Uno (Read 410 times) previous topic - next topic


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 :

Code: [Select]

#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

//Print a message to the LCD.
lcd.print("initialisation ");
lcd.print("du system");

// déclaration des entrées / sorties


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()
  code[28]='\0'; // dans le cas où le code est > 28 chiffres, on impose une fermeture de chaine .

void loop() {

etat = digitalRead(bouton);
if( etat==1){
else if( (oldstate==1) && (etat==0))
oldstate=0 ;

//digitalWrite (SELA,LOW);
//digitalWrite (SELB,LOW);
//digitalWrite (SELC,LOW);



How is everything wired up?

Is RX/TX connected the right way round for your software serial on pin 2/3?

Code: [Select]

char code[28];


code[28]='\0'; // dans le cas où le code est > 28 chiffres, on impose une fermeture de chaine .

You are writing outside of the array. This will overwrite something you do not want to overwrite.


First of all, thanks for replying. About the array that i'm using you're right. There will be always one char which won't be showed but i've figured if i change the length of the array that should be just fine.

To answer your other queston, I tried to change the scanner that I have (Datalogic Gryphon) since it only works with USB and can not with a serial communication, to finally get another one which is " Cognex". The new one works with RS232. That can cause a problem, because the Arduino works with TTL so I used a Converter Module RS232 to TTL Serial MAX3232 just to get the right communication between the scanner and the Arduino.

The scanner works perfectly fine when i plug the RS232-USB into my laptop and  displays whatever code that I scan into a the Putty (Driver for the Cognex) but when I use the Arduino inbetween and the converter module there seem to be a problemand i get nothing on the Arduino's COM.

This the way that i'm wiring them up on the photo below along with the Converter Module.



Yes the module is connected to an external power supply of 12V. The scanner "Cognex" is also connected to power.


In the posted code, nowhere is the software serial port read (mySerial.read()).  I see only prints.
You will save everyone's time if you read and follow the forum guidelines.  https://forum.arduino.cc/index.php/topic,148850.0.html


It worked !! :D  :D

The problem is that I was using tge serial communication on "Serial" while I declared it on "mySerial". So i've changed them and eventually when I scan something it displays it on my COM. Just the way I want it to be.

Thank you all !! Your guidance was really helpful  :)

Go Up