lecteur code à barre

douchette de lecture du code à barre, sortie en PS/2 :

Content

la prise DIN est raccordée à un Arduino mini pro qui se charge de stocker le code barre lu par la douchette. Un 2° Arduino interroge le mini pro par I2C pour récupérer puis envoyer le code via OSC.

#include <PS2Keyboard.h>
#include <Wire.h>
const int DataPin = 2;
const int IRQpin =  3;

PS2Keyboard keyboard;
long time = 0;
#define maxBufferSize 30
char stringBuffer[maxBufferSize+1];
char sizeOfStringBuffer = 0;
uint8_t stringToI2C[maxBufferSize+1];
byte sizeOfString = 0;
byte actualize = 0;

void setup() {
  keyboard.begin(DataPin, IRQpin);
  Wire.begin(4);                // join i2c bus 
  Wire.onRequest(requestEvent); // register event
  delay(2000);
}

void loop() {
    if (keyboard.available()) {
    // read the next key
    char c = keyboard.read();

    // check for some of the special keys
    if (c == PS2_ENTER) {
      //Serial.println("Enter");
    } else if (c == PS2_TAB) {
      //Serial.println("[Tab]");
    } else if (c == PS2_ESC) {
      //Serial.println("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      //Serial.println("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      //Serial.println("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      //Serial.println("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      //Serial.println("[Right]");
    } else if (c == PS2_UPARROW) {
      //Serial.println("[Up]");
    } else if (c == PS2_DOWNARROW) {
      //Serial.println("[Down]");
    } else if (c == PS2_DELETE) {
      //Serial.println("[Del]");  
    } else {

      // otherwise, just store all normal characters
      stringToI2C[0] = 0; //while reading from douchette, I2C returns size of string  = 0
      sizeOfStringBuffer ++;
      if(sizeOfStringBuffer >= maxBufferSize)
      {
        sizeOfStringBuffer = maxBufferSize - 1;
      }

      stringBuffer[sizeOfStringBuffer] = (char)c;
      stringBuffer[0] = sizeOfStringBuffer;
      time = millis();
      actualize = 1;
    }
  }

//put the buffer in the string to send once it's ready...
if(millis() - time > 30 && actualize == 1) {
//Serial.println(stringBuffer);
 for (byte i = 0; i < maxBufferSize; i++) {
  stringToI2C[i] = (char)stringBuffer[i]; 
  }

 for (byte i = 0; i < maxBufferSize; i++) {
  stringBuffer[i] = 0;
  }

  sizeOfStringBuffer = 0;
  actualize = 0;
  time = millis();
 }
}// end loop

void requestEvent()
{
  Wire.write(stringToI2C,maxBufferSize); // respond with message of 255 bytes
                       // as expected by master
  stringToI2C[0] = 0; //ne transmettra par OSC qu'une seule fois un nouveau code lu
    //Serial.println("I2C");                   
    //stringToI2C[0] = 0;
    //sizeOfStringBuffer = -1;
  }

GM861

3.3V

gm861 (PDF, 4.59 MB)

Baudrate = 9600

Through the serial port, send the serial command to enable or disable the setting code function. If need enable setting code function:

  1. Send serial command: _SET_CODE_ON
  2. Then send save serial command to save: 7E 00 09 01 00 00 00 AB CD If need disable setting code function:
  3. Send serial command: _SET_CODE_OFF
  4. Then send save serial command to save: 7E 00 09 01 00 00 00 AB CD

GM65

5 Volt

une lib pour GM65, devrait fonctionner avec le GM861 :

https://zjgrow.com/grow-gm73-small-round-easy-installation-usb-uart-1d-2d-qr-code-barcode-scanner-reader-p2276621.html

https://github.com/xuegangxiao0117/GM65_scanner_for_Arduino/tree/master/GM65_scanner

https://how2electronics.com/barcode-qr-code-reader-using-arduino-qr-scanner-module/

https://docs.neqto.com/docs/en/reference-scripts/uart/gm65