Read micro USB and add listener

Posted on
  • Good day

    Is micro USB same as USB described in docs ?

    Ask because i cant add listener to read data incoming via micro usb

    function onInit() {
      // fire event when receive data via general usb port
      USB.on('data', function (data) {
        digitalWrite(LED3,1);
        print("<USB> "+data);
      });
    }
    

    Then connect to PC and send data using special tools to COM port, for example:

    1+1
    

    and receive only

    2
    >
    

    As we see, listener did not fire ...

  • Hi. Yes, what you're doing is right - However because the 'console' (the interactive command-line) is on USB, the callback is disabled.

    Try moving the console out of the way with Serial1.setConsole(), and it should work. You'll then have to reset the board before you can program it again though (unless you program it via Serial1).

    However you're doing the print, which will then appear on Serial1 (pins A9/A10). If you wanted to echo the data back down USB then you could do: USB.write("<USB> "+data+"\r\n").

    Hope that helps!

  • Gordon, great, thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Read micro USB and add listener

Posted by Avatar for Unknown @Unknown

Actions