Using A Second (Software) Serial USB To Debug Your Arduino

So, you’ve got a working second serial connection all set up and going – now how to use it on the Arduino?

It’s actually really easy, using some code called NewSoftSerial (available from this site, at the ‘Download’ subheading). This software is much like your Serial device you use on the Arduino, but it’s in software (so slower), and it works with your new device (so great for a second debug terminal).

Here’s the steps to test it out:

  • Download the NewSoftSerial library, and unzip it into your Arduino folder (place NewSoftSerial in the libraries folder).
  • Run the Arduino editor, and load up the new example sketch ‘NewSoftSerialTest’ (in the NewSoftSerial Examples menu option).
  • Change the pins in this setup line to yours, such as 8 and 9 – the first entry is for the receive pin and the second is for the transmit pin (but even if it’s mixed up, just reverse them in the code if nothing works right):
    NewSoftSerial mySerial(2, 3);
  • Make sure your Realterm program is running, connected to your port, in half duplex, and set the baud to 4800 (as shown in the sketch for the serial terminal). Also, make sure your normal serial terminal is running at 57600 as shown in the sketch (or change these values – just make sure the two terminals match them in there).
  • At this point, compile/upload the sketch. If everything works, you’ll get two messages, one on your regular terminal, and one on Realterm:
    Arduino term: Goodnight moon!
    Realterm: Hello, world?

    That’s it – you’re communicating! To test further, just type away on one, and you’ll get it sent to the other (don’t forget the hit Enter if nothing appears).

In working with this, I found the biggest issues were forgetting: forgetting the baud rate, forgetting to hit the Change button on Realterm, forgetting which pin was which (and reversing them in code till they worked), and so on. However, once running, the terminals are fun to play with. As the code works now in the test sketch, anything you write on one can be sent to the other. A few things to watch out for, though:

  • On the Arduino terminal, there is a checkbox on the bottom for how to end lines. It doesn’t matter too much which you pick, just take note of it when working with the program. After all, if your code expects newlines, and you are sending breaks, you could have a problem.
  • On Realterm, using it is a bit odd. As long as you stay in half duplex, it will move to the next line, but not until a new character comes in, which can look somewhat weird. And if you want to send a break out, you have to combine it with CTRL, so CTRL-Enter will do the job.
  • There are settings on the Realterm front panel that can give you great diagnostics as to what’s going through the terminal: for example, clicking on ‘hex+ascii’ will display the character and the hexadecimal code, ideal if your characters are not all printable. Likewise, clicking on ‘terminal font’ and selecting ‘Terminal_Ctrl+Hex’ will give you extra characters for normally invisible text, helping you debug a connection.

Put together, you should have a working system for communication. Now for debugging, you can skip having one talk to the other; instead, use the second serial device to do debugging, and let the first hardware one go ahead and do its work – and aside from a little extra (and a bit slower) code, your Arduino code won’t even know it’s got a second line hooked up!

Arduino K000007 The Arduino Starter Kit
$49.99 (0 Bids)
End Date: Tuesday Feb-27-2018 18:53:32 PST
Bid now | Add to watch list
Micro USB UNO R3 MEGA328P with CH340 CH340G Board for Arduino
End Date: Thursday Mar-22-2018 17:55:30 PDT
Buy It Now for only: $6.99
Buy It Now | Add to watch list
Arduino ATMega 2560 ATmega16U2 Development Board + USB Cable
End Date: Thursday Mar-22-2018 13:19:59 PDT
Buy It Now for only: $7.99
Buy It Now | Add to watch list

2 thoughts on “Using A Second (Software) Serial USB To Debug Your Arduino

  1. I realise this is an old article but I found it useful. Realtearm and the Arduino library has been updated in recent years.
    I can send from Realterm and it is received in the Arduino Serial window but not the other way around.
    With your settings of half duplex and Realterm as it is today I don’t get the text duplicated in Realterm, just the text I type. I have tried changing the pin settings and anything else I can think of but nothing helps. Any ideas?

  2. I have found a workaround but it’s not ideal. I have COM 5 and COM6. 5 is normally the Arduino USB and 6 is normally the Serial USB attached to my laptop. I have to use the full COM5 port on the Arduino to upload the sketch (although I do know there are other ways like and I do have a USBasp etc). Once I have uploaded the sketch I can change to COM6 and use COM5 in Realterm. With this set up I can send from the Arduino to Realterm. Ideally I want send and receive but I will see if I can work with just send or receive at time.

Leave a Reply

Your email address will not be published. Required fields are marked *