Renaming Serial, Serial1, Serial2, Serial3 in Mega

Hi Techies,
This post is about renaming Serial,Serial1 to my custom name for easy & understandable program.
I am using all the 4 Serial in Mega which is connected to 4 different peripheral. I wanna debug my code. Virtronics arduino Simulator is what i am using for debug. The below codes are working well with Arduino IDE but throws error with that software.

#define rfid Serial  // Method 1
#define dbg Serial
HardwareSerial &rfid = Serial;  // Method 2
HardwareSerial &dbg = Serial;

void setup()

Both of the above methods are working with Arduino IDE. But when i am testing my code with virtronics arduino simulator this shows up some error. But arduino library codes(SoftSerial Programs) are working fine with that softwares. So i want to change the "Serial" to "dbg" as it is done in softserial library. How can i change? I dont know anything about libraries? please help.

So my point is simple "dbg", "rfid" should directly come from library. The colour of function changes when we call the library functions in arduino ide right, I expect something like this! How can i do that? Please help. I dont know C++ much... This is my first post ever. Hope someone will helps me...

Also posted at

Yup, hoping for some help!!!!!!!!!!!!

I don't know enough to comment on method 2 but I don't see any reason why method 1 should cause an error. The preprocessor will just replace every instance of dbg or rfid with Serial. Please post the full content of the errors you got from virtronics arduino simulator from each method. Please use code tags for the error output.

As was mentioned on Stack Exchange, don’t get hung up on the coloration thing. Every library has a file named keywords.txt with a list of keywords. The Arduino IDE just reads all the keywords.txt files for all the libraries and colors those keywords. There’s no intelligent behavior behind it, the IDE doesn’t say “hey look, roboticist defined dbg as Serial so now I need to color dbg”. If you really wanted rfid and dbg to be colored you could put them in a keywords.txt file but this is purely an aesthetic change, there will be no functional difference.

Thanks for the reply. I have attached the error message i have got.

One more clarification is that Softserial program is running well without any error. Is there any way similar to how softserial is accessing the Serial library, so that we can try here.

Please post text as text. You're much less likely to get help if people have to download and open an image just to see a 10 word error message. If you do post an image please attach and embed it following these instructions:

that will make it easy for people to view the image and thus you will have a greater chance of getting a solution for your problem.

That error is regarding the code:

HardwareSerial gsm = Serial;

that's different from either method you listed above. That sort of behavior is not conducive to us helping you. If you want to ask about that method then you should test it to be sure it actually works and explain that is another method you want to know about. If you want us to help you with method 1 and 2 in your question you need to post the virtronics arduino simulator error output for method 1 and for method 2.

Thanks for your help for suggesting a better idea for me to post image. I will do so from next time.

Now coming to my question. The error which came there was for the method 2. Error responded by that software was so poor. I am sorry about that. The error came for the below quoted text.

HardwareSerial &gsm = Serial; // Method 2
HardwareSerial &dbg = Serial1;

A Simple question again. Can i rename Serial, Serial1, Serial2, Serial3 in arduino hardware serial libraries to my custom words. Is there anything to be noted to make it work, because i did once by changing the word "Serial1" to "dbg" which didnt allow my program to get compile. Then i had to replace with old wordings again. So where am i wrong? What should be done to replace with custom words?

Serial,Serial1,Serial2,Serial3 are confusing a bit while i program. I see them wrong and makes tough to debug.

I wouldn't recommend messing with the library source code for this purpose. I think method 1 will work fine. Someone else will have to comment on method 2. Generally you should avoid using #define unless absolutely necessary. What virtronics arduino simulator error message do you get from method 1?

  1. Method 1 also get the same reply as we get for method2. only if i put

Serial.begin, Serial.available

its working. Others are getting error. There is a option to skip error. but even if i skip errors and run the simulation the

virtual serial monitor is not opening

and i am unable to give serial inputs to simulator. Thats the problem. So i think the only way is to change in library. Any suggestions?

  1. Are there any better simulator for arduino? i tried Visual Micro. but there is no option of line tracing like virtronics. And i know about VSM Arduino from proteus but its too much costly to buy. Any sugesstions?


  1. Method 1 also get the same reply as we get for method2.

Are you trying to tell me that if you run this code in the simulator:

#define rfid Serial  // Method 1
#define dbg Serial

void setup()

You get this exact error message:

Sketch error - Unknown declaration HardwareSerial gsm = Serial;
 Line 6:0006 HardwareSerial gsm = Serial;

I have trouble believing that because it makes absolutely no sense.

Hi roboticist, we just found this thread and confirmed the issue with the Simulator. We do run a full test script before releasing the Simulator but unfortunately this test was not part of the test suite. It is now so this sketch will always run from now on.

Please download the free version from this webpage. We have 56k registered users of Simulator for Arduino now, so hopefully others will also find this fix useful. Thanks