Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: Teensy LC + USB + VB.NET

  1. #1

    Teensy LC + USB + VB.NET

    I bought a Teensy LC.

    I am looking to have the Teensy LC appear in Windows 10 Device Manager as a USB device.

    From all I have read, the simplest is to have the Teensy LC be a USB HID device.

    I would like to write a very simple VB.NET program which would send some bytes to the Teensy LC and have the Teensy LC echo back those bytes + 1.
    In other words, if the byte sent is 0x10, the Teensy sends back 0x11.

    I am lost as to which example program Teensy LC program would be the best one to look at to accomplish this.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,027
    To get started, I'd recommend you use Arduino to program something like this onto your Teensy LC.

    Code:
    void setup() {
    }
    
    void loop() {
      if (Serial.available()) {
        char c = Serial.read();
        Serial.write(c + 1);
      }
    }
    Select Teensy in Tools > Boards, then select your device in Tools > Port. After uploading this code, open the Arduino Serial Monitor. Type some text in the top line and click the "Send" button.

    I highly recommend getting this working in the serial monitor first, so you know the Teensy side is good before adding the complexity of more code on the PC side in another programming language.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,210
    Here two tutorials from the user WIKI, showing how to communicate with a Win10 application via Serial and via HID. They might be helpful after you established connection as recommended by Paul.



    The PC side is written in C# but since C# and VB.net are compiled into the same intermediate language, translating between them is easy. Here a online C# <-> VB.net converter which should give you a head start with the C# examples from the tutorials.

    Serial vs HID:
    Back in the days of Win7, users had to install a serial driver to communicate to attached hardware. HID communication ran out of the box. Thus, if you didn't want your users having to install drivers, HID was easier to use. Since Win10 there is no serial driver installation needed anymore. From the users point of view both methods 'just run'.
    However, serial communication is 'built in' the dotNet languages, using HID requires some third party library (if you don't want to do all the ugly low level SetupDI API calls yourself). I had good experience with this one: https://www.nuget.org/packages/hidlibrary/. All in all, using Win10, I don't see any advantage of HID communication v.s. Serial and I always end up using Serial.
    Last edited by luni; 10-25-2020 at 08:45 AM.

  4. #4
    Quote Originally Posted by PaulStoffregen View Post
    To get started, I'd recommend you use Arduino to program something like this onto your Teensy LC.

    Code:
    void setup() {
    }
    
    void loop() {
      if (Serial.available()) {
        char c = Serial.read();
        Serial.write(c + 1);
      }
    }
    Select Teensy in Tools > Boards, then select your device in Tools > Port. After uploading this code, open the Arduino Serial Monitor. Type some text in the top line and click the "Send" button.

    I highly recommend getting this working in the serial monitor first, so you know the Teensy side is good before adding the complexity of more code on the PC side in another programming language.
    Hi, Paul,

    Do I need to do a Serial.begin(115200) in setup ( ) ?


    .

  5. #5
    Quote Originally Posted by luni View Post
    Here two tutorials from the user WIKI, showing how to communicate with a Win10 application via Serial and via HID. They might be helpful after you established connection as recommended by Paul.



    The PC side is written in C# but since C# and VB.net are compiled into the same intermediate language, translating between them is easy. Here a online C# <-> VB.net converter which should give you a head start with the C# examples from the tutorials.

    Serial vs HID:
    Back in the days of Win7, users had to install a serial driver to communicate to attached hardware. HID communication ran out of the box. Thus, if you didn't want your users having to install drivers, HID was easier to use. Since Win10 there is no serial driver installation needed anymore. From the users point of view both methods 'just run'.
    However, serial communication is 'built in' the dotNet languages, using HID requires some third party library (if you don't want to do all the ugly low level SetupDI API calls yourself). I had good experience with this one: https://www.nuget.org/packages/hidlibrary/. All in all, using Win10, I don't see any advantage of HID communication v.s. Serial and I always end up using Serial.
    The reason I am interested in HID is because when I was working with the Arduino Uno, if I build a project using the Uno, I had to install the IDE so that the drivers were installed.
    At least that is what I recall. I may be wrong about that.

    Are you saying that if I wrote code for a Teensy LC and I gave it to someone with a Windows 10 PC, I don't need to install any drivers?

    .

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,898
    Quote Originally Posted by ieee488 View Post

    Do I need to do a Serial.begin(115200) in setup ( ) ?
    Hove a look into the src code and you will see it Serial.begin(...) does nothing.
    it is not needed, but you can keep it for compatibility.
    BTW, speed is always USB max speed
    Different for HW Serial (Serial1,etc)

  7. #7
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,210
    Are you saying that if I wrote code for a Teensy LC and I gave it to someone with a Windows 10 PC, I don't need to install any drivers?
    Yes, everything works without manually installing drivers. When you plug it in the first time you'll see a message from Windows that it sets up a new device, that's it. No need to install anything but your application.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,027
    The "driver" install is only needed on Windows 8.1 and earlier.

    Windows 10, Linux and Macintosh have all needed drivers built in.

  9. #9
    Quote Originally Posted by WMXZ View Post
    Hove a look into the src code and you will see it Serial.begin(...) does nothing.
    it is not needed, but you can keep it for compatibility.
    BTW, speed is always USB max speed
    Different for HW Serial (Serial1,etc)
    If I wanted to use Serial2 on the Teensy LC, I would buy this --> https://www.amazon.com/ADAFRUIT-Indu.../dp/B00DJUHGHI ?

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,685
    Quote Originally Posted by ieee488 View Post
    If I wanted to use Serial2 on the Teensy LC, I would buy this --> https://www.amazon.com/ADAFRUIT-Indu.../dp/B00DJUHGHI ?
    Yes, something like that can work as long as it connects at 3.3V (that says it does). Also if you have spare Teensy LC or other - that can be used to connect UART Serial from another Teensy and ECHO to USB to a second Serial Monitor program. That is what I tend to do here and use TyCommander for Multiple Teensy Serial Monitor support.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,027
    If you do need to use Windows XP, Vista, 7 or 8, we have a small stand-alone driver installer on the download page.

    https://www.pjrc.com/teensy/td_download.html

    Look for "Windows Serial Installer" on the right hand side near the top of that page. It gives you the same driver install as running the Teensyduino installer, but without the need for Arduino and with only a very small program to download & run.

    On all versions of Windows, the actual driver is USBSER.SYS which is part of Windows. But before Windows 10, Microsoft refused to make their own driver load automatically. The "driver" installation is just a small text file (an .INF file) which tells Windows to load USBSER.SYS when it see Teensy (or other boards) running in USB Serial mode.

    In not using their own driver sounds lame, know that's a general theme with the quality of USB support in old versions of Windows. All versions before Windows 10 have several unpleasant USB bugs. Microsoft made huge quality improvements in USB support on Windows 10, bringing it up to about on par with Macintosh and Linux. Best to avoid Windows 8, 7, XP if possible. But if you do make a device using USB serial and need to let someone still on any of those old systems use it, hopefully that stand-alone installer makes it as painless as possible.

  12. #12
    Quote Originally Posted by PaulStoffregen View Post
    To get started, I'd recommend you use Arduino to program something like this onto your Teensy LC.

    Code:
    void setup() {
    }
    
    void loop() {
      if (Serial.available()) {
        char c = Serial.read();
        Serial.write(c + 1);
      }
    }
    Select Teensy in Tools > Boards, then select your device in Tools > Port. After uploading this code, open the Arduino Serial Monitor. Type some text in the top line and click the "Send" button.

    I highly recommend getting this working in the serial monitor first, so you know the Teensy side is good before adding the complexity of more code on the PC side in another programming language.
    When I used the Arduino IDE to upload the program, I see the message
    Teensy did not respond to a USB-based request to enter program mode.
    Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
    in the IDE.

    Why am I getting that message even though the program uploaded correctly since when I type a in Serial Monitor, I get b?
    The IDE version is 1.8.12

    .

  13. #13
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,685
    Quote Originally Posted by ieee488 View Post
    When I used the Arduino IDE to upload the program, I see the message
    Teensy did not respond to a USB-based request to enter program mode.
    Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
    in the IDE.

    Why am I getting that message even though the program uploaded correctly since when I type a in Serial Monitor, I get b?
    The IDE version is 1.8.12

    .
    Does the Teensy show in the PORTS list under Teensy and that T_LC selected?

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,027
    When your upload completes, Teensy reboots. The USB controller is built inside the chip, so it gets rebooted too. From your PC's point of view, it is as if the USB cable has unplugged. Even though the cable is still physically plugged in, as far as the electronics in your PC are concerned it's momentarily disconnected and then reconnected.

    Quote Originally Posted by ieee488 View Post
    Why am I getting that message even though the program uploaded correctly
    Usually the reason is an unusually long delay inside Windows, where it has detected that Teensy is connected, but for reasons unknown sometimes Windows will wait several seconds before it creates driver instances for the freshly connected USB device. Windows 7 used to do this quite frequently. It's much less common on Windows 10, but still happens sometimes. I have no idea why.

    The teensy_reboot program waits for 5 seconds. Normally that's plenty of time for Windows, Mac or Linux to detect a USB device. Except when Windows does that strange delay. After 5 seconds, teensy_reboot gives up waiting and prints that message. In Teensyduino 1.54, we're lengthening the delay to 6.2 seconds, since just last week someone reported a log file (in Teensy Loader, click Help > Verbose Info) which showed *exactly* 5 seconds from Teensy disconnecting to the time it was detected reconnecting.

    I have looked into this problem many times, mostly back in the days of Windows 7 when it was so much more common. The delay is absolutely on the Windows side. Teensy answers every control transfer very quickly. Then for reasons I can't understand, Windows will sometimes just wait several seconds.

    It's terribly frustrating, but I've never been able to discover why Windows sometimes does this, much less how we can detect when it's happening or possibly do anything about it.

    The guy who reported this last week made a variety of changes to his machine and the problem mysteriously vanished, of course without yielding any useful info. I personally find Microsoft Windows very frustrating, because that seems to be the result with almost all troubleshooting... problem goes away but nothing is learned about why it happened or what we can do about it in the future for everyone else!

  15. #15

    Great information.

    It is working so I am glad.

    Now that I know that Windows 10 has driver for the Teensy, there is no need for me to delve too much into HID.

    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •