Teensy with USB Serial Build

Status
Not open for further replies.
I recently bought a Teensy 2.0 and have been programming it to send commands in place of a game controller. (Look Mom, no hands!) As a next step, I'd like to send live commands from my computer to the Teensy. I need to be able to hook the Teensy to the computer while the existing USB port is in use. From what advice I've found, I need a USB serial convertor, right?

I'm mostly concerned with what pieces of hardware I need to get and how to properly hook it all up to the Teensy. I'm not very knowledgeable about these kinds of things (far more a software person), so any help is appreciated.
 
The Teensy behaves as a proper USB serial device and doesn't need an adapter or converter. See this: https://www.pjrc.com/teensy/td_serial.html

Your computer should just see it connected as a comm port or device. Now, I'll add the foot-in-mouth caveat that I've never played with a Teensy 2, only Teensy 3 and above, but I do believe that link above covers Teensy 2's too.
 
Your computer should just see it connected as a comm port or device.

I'm not sure you understood my request...? The existing USB port on the Teensy 2.0 would be in use. I'm trying to connect via a second device's USB port. So there should be 2 USB cords connected to the Teensy in total at the same time.

If that's what you're trying to explain, please go into more detail because I really don't understand what parts I need and how to hook them up. The link provided does not appear to explain this.

Please and thank you.

Edit: I found an image of what I'm trying to do with an Uno R3. How would I do this with a Teensy 2.0?

arduino_serial_connection.jpg
 
Last edited:
Yep. I misunderstood your question. Thanks for clarifying. Curious, what is the Teensy connected to via USB? Is it a situation where you could use a USB hub?
 
As I said, I am using the Teensy 2.0 to emulate a game controller. It's to be used with a game console. But I want to hook it to a computer (a separate device) at the same time to send live commands now.

I don't know if a USB hub would work? You're asking the wrong person that question lol. It looks like it'd be a bulky solution if it did.

Edit: Well, I guess bulky doesn't matter in this case, now that I think of it. Would a Teensy be able to pull this off with a USB hub device?
 
Last edited:
Ah, I understand now. You’re using the USB port as the game controller connection. That wasn’t immediately clear to me because there’s several other ways it could have been physically connected. Many things I make connect via non-USB: SPI, I2C, CAN, serial, etc.

Here are some ideas:
  1. A USB-to-serial converter that connects to the computer. I'd suggest using one with a common chip (FTDI-based, for example) for easy driver installation. There are ones with wires coming out so you can easily attach them to the Teensy. On the Teensy side, you'd use Serial1, Serial2, or whichever serial for communication. On the computer side, you'd need software that knows how to talk to that port. Would you be writing your own or using something scripting-based or something? I'm assuming you have this part handled.
  2. Using another Teensy or Arduino-based system to talk over its USB serial and then hook up the hardware RX/TX lines to the game-controller-Teensy's RX/TX lines. This is functionally the same as having a small USB-to-serial adapter. Another Teensy is pretty small. You'd have the same requirements on the computer side as the previous approach.

Would the computer side need human interaction? Were you thinking of that or something that sends commands to the game-controller-Teensy with some pre-programmed script (which would be perfect with another Teensy)?
 
Ah, I understand now. You’re using the USB port as the game controller connection. That wasn’t immediately clear to me

After 3 times of me saying so, you get it! lol It happens though. This just has been confusing from my end hahaha

A USB-to-serial converter that connects to the computer. I'd suggest using one with a common chip (FTDI-based, for example) for easy driver installation. There are ones with wires coming out so you can easily attach them to the Teensy. On the Teensy side, you'd use Serial1, Serial2, or whichever serial for communication.

Okay, thank you! So that would be like this option and this one?

I found this, which seems to indicate I need to use Serial1 for Teensy 2.0, but in looking at the pin layout here, I don't understand where it is. Can you please help me understand where I would need to connect the wires to on the Teensy 2.0?
 
After 3 times of me saying so, you get it! lol It happens though. This just has been confusing from my end hahaha

All you said was that the "USB port is in use" and not "connected to the game". Don't forget you're asking questions of overly-detailed (well, I can only speak for myself here) engineers. I didn't make that connection because it wasn't stated, even though it was obvious to you. (Doesn't mean others didn't get it; it's possible I'm the only one who didn't see it right away.)

Okay, thank you! So that would be like this option and this one?

Yes. Adafruit carries them too. Then you can get wires with female or male ends that plug onto the pins straight away.

I found this, which seems to indicate I need to use Serial1 for Teensy 2.0, but in looking at the pin layout here, I don't understand where it is. Can you please help me understand where I would need to connect the wires to on the Teensy 2.0?

Use the "Arduino Software" version. Look for the RX and TX lines (different depending on whether it's a Teensy 2 or Teensy++ 2). Hook up RX to the TX of the adapter and the TX to the RX of the adapter. I believe you'll need to use `Serial1`. Don't forget to call `Serial1.begin` with an appropriate baud rate, eg. 115200, before accessing it:
Code:
Serial1.begin(115200);
while (!Serial1 && millis() < 4000) {
  // Wait for Serial1 initialization
}

I have to run, but I can expand more later if you have more questions. Specifically, ensure you're using the right voltage (5V vs. 3.3V); I can't remember offhand if the Teensy 2 pins are 5V tolerant (likely they are) or if they're actually 5V pins. I'll clarify more later...
 
All you said was that the "USB port is in use" and not "connected to the game". Don't forget you're asking questions of overly-detailed (well, I can only speak for myself here) engineers. I didn't make that connection because it wasn't stated, even though it was obvious to you. (Doesn't mean others didn't get it; it's possible I'm the only one who didn't see it right away.)

Sorry, I'm basically a total noob here and was laughing relief that it was a misunderstanding thing. My mind has been swirling for about a week in trying to understand this by myself since what I'm trying to work with was in another actual language and not using Teensy. And our discussion left me thinking I was way off in what I was asking or what little I thought I understood, but it was just a silly communication barrier in the way.

I did not realize I would be dealing with very high level people in engineering. This is very new to me and I will work to keep what you said in mind. Thank you for your help and continuing to help, and the lesson here.

Hook up RX to the TX of the adapter and the TX to the RX of the adapter.

This page : pjrc.com/teensy/td_uart.html

Shows T_2 Serial1 Rx pin 7 and Tx pin 8

Oh there it is! Combine this and now I think I know what I need to do. Thank you! It feels like it's making sense now. I see how it's 2 wires in the Arduino photo too, so it's the same thing hahahaha! I'm so excited!

Edit:

Specifically, ensure you're using the right voltage (5V vs. 3.3V); I can't remember offhand if the Teensy 2 pins are 5V tolerant (likely they are) or if they're actually 5V pins. I'll clarify more later...
Okay, thank you for this bit.
 
Last edited:
As @shawn noted - Assuring same voltage is important … and with Rx/Tx of course the GND must be common too.
 
Not sure what aspects of controlling a game you're trying to accomplish, but here's at least one project where someone did this sort of thing.

https://www.pjrc.com/automating-zelda-breath-of-the-wild/

https://medium.com/@bertrandom/automating-zelda-3b37127e24c8

https://github.com/bertrandom/snowball-thrower


To have a PC control the Teensy, while it's working to control the game, you'll need a 2nd Teensy to talk to your PC and a connection between them. Serial is the easiest. If you onlt need to send data in 1 direction, you can just connect 2 wires: TX on the sending to RX on the recieving side, and of course GND to GND.

If your messages between the 2 are very simple, you can just use Serial1.write() on the sending Teensy and Serial1.available() and Serial1.read() on the receiving Teensy. If you need to send larger or more complex messages, you could write code to send many bytes and code on the receiver to parse those messages, but there are libraries which do this for you. Bill Porter's EasyTransfer lib is one of the most popular.
 
Well, I thought I ordered everything. The wires that come with the serial adapter won't connect to a solderless breadboard. I'm not very good at wire stripping with something like scissors and I really wanted this to be a straightforward project and not something hacky because I will put it to good use. So now to figure that wire part out. Maybe I should look into a wire kit or something.

According to https://www.pjrc.com/teensy/ the Teensy 2 pins are 5 volt.

Thanks, much appreciated!

Not sure what aspects of controlling a game you're trying to accomplish, but here's at least one project where someone did this sort of thing.

https://www.pjrc.com/automating-zelda-breath-of-the-wild/

https://medium.com/@bertrandom/automating-zelda-3b37127e24c8

https://github.com/bertrandom/snowball-thrower


To have a PC control the Teensy, while it's working to control the game, you'll need a 2nd Teensy to talk to your PC and a connection between them. Serial is the easiest. If you onlt need to send data in 1 direction, you can just connect 2 wires: TX on the sending to RX on the recieving side, and of course GND to GND.

If your messages between the 2 are very simple, you can just use Serial1.write() on the sending Teensy and Serial1.available() and Serial1.read() on the receiving Teensy. If you need to send larger or more complex messages, you could write code to send many bytes and code on the receiver to parse those messages, but there are libraries which do this for you. Bill Porter's EasyTransfer lib is one of the most popular.

Yes, this is essentially the idea I originally did and am now going further to add control direct from the computer. The hardware side is what I've been struggling with.

Good to know that I probably only need ground and the one way then with the wires. Thank you. Now to just figure out wires to order.
 
Last edited:
I am not familiar with the Teensy 2. But if it has a second serial port available then it can be connected to an FTDI rs232 to USB device and communicate with a different serial on the PC. if you use serial events for input of data then remember to point at the correct serial for incoming data. I have done this with a Teensy 3.2 and it functions very well.
 
Status
Not open for further replies.
Back
Top