🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    QR-Code Reader - Trigger read from serial port and read code value

    PRODUCTS
    2
    5
    983
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      qrcoder
      last edited by

      Re: ATOMIC QR-CODE READER - Documentation - Trigger in Host Mode

      Seems obvious that it should be possible to trigger the reading of a QR code from the serial port and read the code value after that. I have tried but failed. Reading the value works fine fut so far only the button trigger mode works reliably.

      Has someone made this work that could share what settings are necessary and how the trigger is sent through the serial port?

      Best regards

      1 Reply Last reply Reply Quote 0
      • C
        Cognitive5525
        last edited by

        Have you read this document?

        1 Reply Last reply Reply Quote 0
        • Q
          qrcoder
          last edited by

          Yes, I have seen that document, but it is not clear to me what sequence of commands is necessary to trigger the reading of a QR code from the serial port.
          Is the sequence something like:

          1. Send wake-up and wait 50ms ( 0x0)
          2. Send host command (0x 07 C6 04 08 00 8A 08 FE 9)
            what now?
          3. start decoding (0x 04 E4 04 00 FF 14) wait x ms
          4. stop decoding (0x 04 E5 04 00 FF 13)
          5. read from serial port

          or is the sequence something else?

          Grateful for your help!

          1 Reply Last reply Reply Quote 0
          • C
            Cognitive5525
            last edited by

            From this Arduino example the answer is yes.

            Note I think there is a typo in line 49.

            Serial2.write(start_scan_cmd, sizeof(stop_scan_cmd));

            should probably be

            Serial2.write(stop_scan_cmd, sizeof(stop_scan_cmd));

            1 Reply Last reply Reply Quote 0
            • Q
              qrcoder
              last edited by

              I think I still am doing something wrong. In the example below it seems that the M5 isn't reacting to the commands. Do I have to scan a QR code from the manual first to get it into the proper state?

              Example 1:

              import serial
              import time
              
              wakeup_cmd = bytes([0x00])
              host_mode_cmd = bytes([0x07, 0xC6, 0x04, 0x08, 0x00, 0x8A, 0x08, 0xFE, 0x95])
              start_scan_cmd = bytes([0x04, 0xE4, 0x04, 0x00, 0xFF, 0x14])
              stop_scan_cmd = bytes([0x04, 0xE5, 0x04, 0x00, 0xFF, 0x13])
              
              print('Open serial port')
              ser = serial.Serial('COM4', 9600, timeout=1)  # Adjust the port name and baud rate as needed
              
              try:
                  print('Wake up!')
                  ser.write(wakeup_cmd)
                  time.sleep(0.05)
                  
                  print('Host mode')
                  ser.write(host_mode_cmd) 
                  time.sleep(0.5)
                  
                  print('Start scan')
                  ser.write(start_scan_cmd)
                  time.sleep(3)
              
                  print('Stop scan')
                  ser.write(stop_scan_cmd)
                  time.sleep(1)
              
                  print('Bytes waiting at serial port: ' + str(ser.in_waiting))
                  response = ser.read(ser.in_waiting)
                  print("Received:", response.decode())
              
              except Exception as e:
                  print("Error communicating with serial device: ", e)
              
              finally:
                  print("Close serial port")
                  ser.close()
              

              The output:

              Open serial port
              Wake up!
              Host mode
              Start scan
              Stop scan
              Bytes waiting at serial port: 0
              Received:
              Close serial port

              Doing something simpler doesn't work either:

              Example 2:

              software_version_cmd = bytes([0x04, 0xA3, 0x04, 0x00, 0xFF, 0x55])
              
              print('Open serial port')
              ser = serial.Serial('COM4', 9600, timeout=1)  # Adjust the port name and baud rate as needed
              
              try:
                  print('Wake up!')
                  ser.write(wakeup_cmd)
                  time.sleep(0.05)
                  
                  print('Check software version')
                  ser.write(software_version_cmd)
                  time.sleep(1)
              
                  print('Bytes waiting at serial port: ' + str(ser.in_waiting))
                  response = ser.read(ser.in_waiting)
                  print("Received:", response.decode())
              
              except Exception as e:
                  print("Error communicating with serial device: ", e)
              
              finally:
                  print("Close serial port")
                  ser.close()
              

              The output:

              Open serial port
              Wake up!
              Check software version
              Bytes waiting at serial port: 0
              Received:
              Close serial port

              1 Reply Last reply Reply Quote 0
              • First post
                Last post