Wake up/sleep a barcode scanner using UART command

Hello,
I'm an engineering student and i have problems putting a barcode scanner to sleep/wake up. I use a 3,3V arduino MKR WAN 1310, and i need to put a barcode scanner to sleep/wake up. Here is my code so far. The scanning part works fine, but the Serial1.write() does not work at all.

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial);
  delay(1000);  // Initialisation
}

void loop() {
  if (Serial.available()) {
    String command = Serial.readStringUntil('\n');
    command.trim();
    
    if (command.equalsIgnoreCase("veille")) {
      Serial.println("Mise en veille du scanner...");
      Serial1.write((0xA5);  // Envoie de l'octet 0xA5 pour mettre en veille
      delay(100);           // Attendre un peu pour permettre au scanner d'entrer en veille
    } else if (command.equalsIgnoreCase("reveille")) {
      Serial.println("Réveil du scanner...");
      Serial1.write(0x00);  // Envoie de l'octet 0x00 pour réveiller le scanner
      delay(100);           // Attendre un peu pour permettre au scanner de se réveiller
    } else {
      Serial.println("Commande non reconnue");
    }
  }

  lecture();
}

void lecture() {
  if (Serial1.available()) {
    String receivedData = Serial1.readStringUntil('\n');
    Serial.print("Données reçues : ");
    Serial.println(receivedData);
  }

and here is a picture of the documentation, and a link. https://www.waveshare.com/w/upload/d/dd/Barcode_Scanner_Module_Setting_Manual_EN.pdf
I think i have difficulties understanding how to use the Serial1.write() function, what is the adress? what is bit 7-0??.


Thank you so much for your help ! thank you

Have a look at the write examples on the manual.

I think this would be command for A5:
0x7E, 0x00, 0x08, 0x01, 0x00, 0xD9, 0xA5, 0x3E, 0x69

Thank you this byte sequence worked perfectly! I need to spend time on the doc to understand exactly how to create a byte sequence but i am very thankful!

Wasn't complicated.
0x7E, 0x00, header
0x08, write (07 for read)
0x01, number of bytes
0x00, 0xD9, address
0xA5, byte to write
0x3E, 0x69 checksum (calculated without header)

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