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
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