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
