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

Thread: Strange Serial1 issue

  1. #1

    Strange Serial1 issue

    Hi Everyone

    I have an unexplained issue where my Serial1 only seems to work when the Teensy is connected via USB to my computer.

    I'm trying to control a Linux computer as a mouse from a Windows computer via a Teensy 3.2.

    I have a C# application that uses a TTL USB adaptor to talk to the Teensy on Serial1 that is then connected via it's USB to the computer (Linux) I am trying to control.

    When I connect to the Teensy USB output back into my windows computer the mouse moves as per the commands I send it. However when I connect the USB output to the Linux computer it doesn't move. But it does move the mouse as expected in the setup() function so it's not a mouse command issue. I've added an LED output to the serial1 available code block and basically it is not receiving the serial commands when the USB is connected to the Linux computer even though this functionality should be totally diifferent from where the USB is connected right?

    I then ran the same test but with the Teensy USB only connected to a power source and not a computer and the same failure to get the Serial1 LED flashing happened.

    My assumption is that the Serial1 functionality is only working for me when the USB serial is connected and running, even though I am not using the USB serial!

    I'm sending across 200,200,0 as the bytes across the serial1 interface and not changing this whether the USB is connected or not. So I'm not exceeding the 255 byte size limit. I also have an LED on my USB TTL adaptor so I can see my Serial data is going via that and not the Teensy USB in some weird mix up.

    This happens when I'm running in Serial, Keyboard, Mouse, Joystick mode and this is my code:

    int led = 13;
    void setup() {
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);
    delay(1000);
    Mouse.screenSize(1000, 1000);
    Serial1.begin(9600);
    delay(20000);
    Mouse.moveTo(150,150); //This works
    digitalWrite(led, LOW);
    delay(1000);
    }

    void loop() {

    int MouseX;
    int MouseY;
    int MouseClick;

    if (Serial1.available() > 2) {
    //this only works when connected to windows PC, if connected to Linux PC or just power supply I get no LED flashing
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);

    MouseX = Serial1.read();
    MouseY = Serial1.read();
    MouseClick = Serial1.read();

    Mouse.moveTo(MouseX,MouseY);

    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);


    if (MouseClick == 1)
    {
    Mouse.set_buttons(1, 0, 0);
    delay(100);
    Mouse.set_buttons(0, 0, 0);
    }

    }


    }

    It feels very difficult to diagnose as it doesn't make sense unless I've done something wrong in my code, but then I would expect
    it not to work when connected to the PC. So all I'm doing is trying random things to hope it works.

    Does anyone have any suggestions? I appreciate it is hard for anyone else to test unless they have a USB TTL. I believe it is a FTDI one. It says BTE13 009B on it. However I can't see why that would act any different based on whether the Teensy USB was connected.

    I'm going to try a few more random things like trying Serial2 and probably next I'll add the LED flash to the start of the loop just to make sure that is running.

    Thank you

    Andy

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,502
    Ok, I'm running it here with a FTDI cable, no USB connection to the Teensy 3.2.

    After that long 20 second startup, when I type in a terminal emulator, the LED does the double blink on every 3rd keystroke.

    Click image for larger version. 

Name:	DSC_0138_web.jpg 
Views:	9 
Size:	168.6 KB 
ID:	14124

    However, there is a known bug with Linux where absolute mouse moves do not work. Technically it's a Xorg X11 limitation. If you're testing with a Linux system, you'll probably hit that issue.

  3. #3
    Quote Originally Posted by PaulStoffregen View Post
    Ok, I'm running it here with a FTDI cable, no USB connection to the Teensy 3.2.

    After that long 20 second startup, when I type in a terminal emulator, the LED does the double blink on every 3rd keystroke.

    Click image for larger version. 

Name:	DSC_0138_web.jpg 
Views:	9 
Size:	168.6 KB 
ID:	14124

    However, there is a known bug with Linux where absolute mouse moves do not work. Technically it's a Xorg X11 limitation. If you're testing with a Linux system, you'll probably hit that issue.
    Hi Paul

    You are a legend as always. I was aware of the Linux mouse issue but it's not even flashing the LED when I'm not connected to the Linux machine. In fact the mouse movement in the start loop works exactly how I want on Linux so I'm lucky there.

    However your test has given me a clue because it could be something to do with how I'm sending the serial commands. At least you have proven my code works.

    I've only connected the TX to the Teensy RX. That works fine on the PC but I haven't connected anything else. Could that be the problem, am I missing power to the serial chip because USB is unplugged from the computer? It is plugged into a USB power source I should add!

    I assumed because it worked when the USB was in the PC that I didn't need to connect ground or CTS/RTS?

    Looking at your picture, I think I might have figured it out! From what I can tell you are powering the Teensy off the Serial USB so they have a shared ground? That may be the issue, I will report back.

    Kind regards

    Andy

  4. #4
    Hi Paul

    Connecting the ground was the missing link! I didn't need to connect the VCC.

    Thank you and keep up the great work as always.

    Andy

Posting Permissions

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