Hey there,
I’m having some issues with the new Sparkfun barcode reader (https://www.sparkfun.com/products/18088).
I’m using it with an ESP 32 via UART and it kind of works pretty good.
I just would like to define the time, when the sensor is actually looking for barcodes.
The library offers the function .startScan(); and stopScan(); which work fine when using the board in “single scanning mode” but don’t when using the board in “continuous scanning mode”.
I’m using a slightly modified version of the example sketch:
#include "SoftwareSerial.h"
SoftwareSerial softSerial(16, 17);
#include "SparkFun_DE2120_Arduino_Library.h"
DE2120 scanner;
#define BUFFER_LEN 40
char scanBuffer[BUFFER_LEN];
int button = 23;
int button_status = 0;
int button_pressed = 0;
void setup()
{
pinMode(button, INPUT);
Serial.begin(115200);
Serial.println("DE2120 Scanner Example");
if (scanner.begin(softSerial) == false)
{
Serial.println("Scanner did not respond. Please check wiring. Did you scan the POR232 barcode? Freezing...");
while (1)
;
}
Serial.println("Scanner online!");
scanner.enableContinuousRead(2);
}
void loop()
{
button_status = digitalRead(button);
if(button_status == HIGH) button_pressed=1;
if(button_pressed == 1 && button_status == LOW) {
//when button is released
scanner.startScan();
button_pressed=0;
delay(200);
}
if (scanner.readBarcode(scanBuffer, BUFFER_LEN)) {
Serial.print("Code found: ");
for (int i = 0; i < strlen(scanBuffer); i++) Serial.print(scanBuffer[i]);
Serial.println();
scanner.stopScan();
delay(200);
}
}
The scanner doesn’t really stop searching for barcodes when it found one. The lights turn off after it recognizes a barcode, so it seems like the scanner.stopScan();
worked, but when I turn the scanner on again using the button ```
scanner.startScan();
So it seems like the barcode is still in the buffer and fires immediately when the scanner is activated again.
It sometimes even fires a broken / wrong barcode from the buffer when started.
When using the barcode scanner in "single scanning mode" everything works fine, but the scanner turns off after 5 seconds if it doesn't recognize a barcode and it's not possible to change that time. Unfortunately I need to turn it off manually so that doesn't work for me.
Maybe someone uses the same barcode scanner and has an idea how to solve the problem :)
It would be amazing if someone could help me! Thanks a lot!
Leo :)