Connect COM port(s) to FEZ via USB

DB9 serial ports on laptops are becoming extinct.  But you may want to add another COM port to your FEZ so as not to interfere with the Debug interface. You can use CDC virtual COM port, but then you need to Break and Run at the right spot to stop the Debug channel load the CDC VCOM driver.  Fortunately, you can just side-step the issue completely by connecting another COM port and use that for FEZ-to-PC serial communication.  But you say, “hey, I still want to use USB”.  That ok, just get a FT232 board (or make one).  For $14 bucks, this one will work great

Now just read the datasheet of your MCU to figure out what pins your COM port uses.  On the Domino, I have used COM1 and COM2.  COM1 does not have CTS/RTS, so use XON/XOFF (software) handshaking. COM2 does have hardware handshaking, so you can also hookup CTS/RTS to the FT232.  A Fritzing diagram is below for COM2 on the Domino. Note the photo looks like a Panda as I did not have a Domino Fritzing part.  You should be able to change easily per your MCU pin configuration.


1) Get at FT232 breakout board.  You can’t really make them cheaper, so save time and buy one from Sparkfun.  Also get a mini-USB cable if you don’t already have one.

2) Solder the headers on the sides as needed.  Pins facing down so you can also plug board into breadboard if needed.  You can use these pins as just jumper wire connect points also if you don’t need BB.

3) Plug USB cable into board and into computer.  Windows should automatically recognize and install driver and a new COM port. Write down the new COM port (i.e. COM22) as you will need this later when writing your PC client code.

4) When you know your FT232 has installed and works, unplug it and connect your header pins to your FEZ pins using diagram 1 as a guide.

5) Write your code on the FEZ to Send/Receive data.  Here is a sample:

public static void TestCom2()
    SerialPort com1 = new SerialPort("com2", 9600, Parity.None, 8, StopBits.One);
    com1.Handshake = Handshake.RequestToSend;

    string reply = ReadLine(com1);
    Debug.Print("From PC:" + reply);

    string s = "Hello\n";
    byte[] ba = Encoding.UTF8.GetBytes(s);
    com1.Write(ba, 0, ba.Length);

6) Write your code on the PC. Here is sample:

private void button1_Click(object sender, EventArgs e)
    SerialPort sp = new SerialPort(this.textBox1.Text, 9600, Parity.None, 8, StopBits.One);
    sp.Handshake = Handshake.RequestToSend; // XOnXOff;
    sp.Write("Hello from pc.\n");
    string reply = sp.ReadLine();

7) Now just finish your project and “Run what you brung”!

–William Stacey

This entry was posted in .Net Micro Framework, C#, FEZ, Robotics, Serial and tagged , , , , , . Bookmark the permalink.