GM67 Serial Command Host Mode

Hello,
I have questions about programming and sending serial command to barcode scanner GM67.
The scanner already working fine with sending barcode data to the serial monitor.
But when i try the Host Mode and send serial command, it didnt work.
I try to type the instruction like "07 C6 04 08 00 8A 04 FE 99" to the serial port but nothing happen.
Here's the datasheet : https://www.mikroshop.ch/pdf/GM67_Barcode.pdf
Here's the code :

#include <Arduino.h>
#define led 25

String kode;
void setup() {
  Serial.begin(9600);
  Serial1.setTX(16);
  Serial1.setRX(17);  
  Serial1.begin(9600);
  pinMode(led, OUTPUT);      
  
}


void loop() {  
  while (Serial1.available() > 0) {            
    kode = Serial1.readString();
    Serial.println(kode);    
  }  
  while (Serial.available() > 0){
    Serial1.write(Serial.read());
  }  
}

usually those commands are not sent in ASCII but as hexadecimal bytes

const byte command[] = {0x07, 0xC6, 0x04, 0x08, 0x00, 0x8A, 0x04, 0xFE, 0x99};
const size_t commandSize = sizeof command;
...
void setup() {
  Serial1.setTX(16);
  Serial1.setRX(17);  
  Serial1.begin(9600);
  // send the configuration 
  Serial1.write(command, commandSize);
  ...
}

void loop() {...}

if you want to get the command from the Serial monitor then you need to transform the ASCII into bytes and send those bytes

Thanks for the reply, i've tried using the ASCII and send a command to turn off the lighting / collimatiion, the GM67 module blue light turning off and then on again but the command didnt do the thing that it should. I factory reset the GM67, set to TTL 232 interface, and change to Host Mode.
Am i missing something to use the serial port instruction ?
Here's the code :

#include <Arduino.h>

const byte Command[] = {0x08, 0xC6, 0x04, 0x08, 0x00, 0xF2, 0x03, 0x02, 0xFE, 0x2F};
const size_t commandSize = sizeof Command;
String kode;
void setup() {
  Serial.begin(9600);
  Serial1.setTX(16);
  Serial1.setRX(17);  
  Serial1.begin(9600);      
  delay(8000);
  Serial1.write(Command, commandSize); 
  Serial.println("Sending");
  
}
void loop(){
  while (Serial1.available() > 0) {            
    kode = Serial1.readString();
    Serial.println(kode);    
  }  
  while (Serial.available() > 0){
    Serial1.write(Serial.read());
  }  
}

is the module by default at 9600 bauds ? does it need some sort of software or hardware reset before you can send commands ?

The module default after factory reset is : Baud rate:9600, Data bit:8, Verification: No. And i even set them again to those default manually.
My serial monitor setting is :

[env:pico]
;platform = raspberrypi
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
upload_protocol = mbed
monitor_speed = 9600
monitor_echo = yes
;monitor_eol = LF
platform_packages =
    earlephilhower/toolchain-rp2040-earlephilhower@^5.100300.230216

From the datasheet, it doesnt tell that i need a software / hardware reset, just switch to Host Mode and make sure the communication parameter are the same. It's already the same between the module and mainfreame, i think

In Appendix 6 of the user manual they state

When the scanner is not working, it is in sleep mode.Under the sleep mode, need to wake up first, then send the effective command. (Wake up command:0x00,50ms,then send the effective command)

To start decoding and stop decoding the serial port command needs to be valid in host mode. Please switch to the host mode first.

You could set up the module at 115200 bauds so that things go faster since you have a hardware based UART by scanning
image
and
image

then go to the host mode
image

the explanation of the host mode is cryptic... I guess that's auto-translated... but let's assume it's need

4.4 Host Mode
Through the instruction to trigger the reading engine, and it can end the reading by instruction, read successfully or the reading time exceeds the single reading time,the reading will be finished

That should configure the module

then I would try something like this

void configure() {
  const byte wakeUp = 0x00;
  const byte collimationAlwaysOff[] = {0x08, 0xC6, 0x04, 0x08, 0x00, 0xF2, 0x03, 0x02, 0xFE, 0x2F};
  const byte ledOn[] = {0x05, 0xE7, 0x04, 0x00, 0x01, 0xFF, 0x0F};
  const byte ledOff[] = {0x05, 0xE8, 0x04, 0x00, 0x01, 0xFF, 0x0E};

  Serial1.write(wakeUp); delay(50);
  Serial1.write(collimationAlwaysOff, sizeof collimationAlwaysOff);

  Serial1.write(wakeUp); delay(50);
  Serial1.write(ledOn, sizeof ledOn);

  delay(2000);

  Serial1.write(wakeUp); delay(50);
  Serial1.write(ledOff, sizeof ledOff);
}


void setup() {
  Serial.begin(115200); // <== set the Serial monitor to 115200
  Serial1.setTX(16);
  Serial1.setRX(17);
  Serial1.begin(115200); // <== make sure you scanned the 115200 baud rate barcode for configuring the module
  delay(1000);
  configure();
  Serial.println("GM67 configured");
}


void loop() {
  int c = Serial1.read();
  if (c != -1) Serial.write(c);
}

(run it with the Serial monitor at 115200 bauds)

if that works you should see the led on for 2 seconds during the configuration

then if you present a barcode, it should spit it out in the Serial monitor

1 Like

Wow, that's work, and also listen to the instructions now, i really appreciate your help Sir, Thank you

cool :slight_smile:

seems that reading the manual was just what was needed :innocent: :crazy_face:

Hahahah yeah :rofl:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.