Arduino Mega Serial Ports

Hello,

I am using a TFMini Plus. I have used the manufacturers sample code with an Arduino Uno with no issues. However, when I try and use it with a Mega I get an error when trying to compile the code.

conflicting declaration 'SoftwareSerial Serial1'

As stated in the code. I believe it is because the Mega has multiple serial ports unlike the Uno.

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and directly use Serial1 serial port*/

Example Code:

Information:
[https://github.com/TFmini/TFminiPlus-Arduino/blob/master/Example-ReadData/The%20Examples%20of%20TFmini%20Plus%20on%20Arduino(Ⅰ).pdf](https://github.com/TFmini/TFminiPlus-Arduino/blob/master/Example-ReadData/The Examples of TFmini Plus on Arduino(Ⅰ).pdf)

What do I have to change to make the sketch compile?

Thanks

#include <SoftwareSerial.h>  //header file of software serial port
SoftwareSerial Serial1(2,3); //define software serial port name as Serial1 and define pin2 as RX and pin3 as TX
/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and directly use Serial1 serial port*/

It is probably sufficient to just comment out those two lines of code, the comment about “interpret above two pieces of code…” sounds like a bad translation.

Study the Mega's MultiSerial example in the IDE, to understand how to use the hardware serial ports.
Leo..

David_2018 is right, and I believe you should be very suss about anything to do with benewake, the guy is clearly an idiot. At a guess,

conflicting declaration 'SoftwareSerial Serial1'

is caused by serial1 being hardware serial pins 18,19 on a Mega, and you are trying to call that on pins 2,3 instead. Nobody else would be that stupid, but it's all there on GitHub. Indeed calling software serial on any pin on a Mega tells you all you need to know.

Serial1 is Serial1, so if you simply connect your serial device to pins 18,19 (hardware serial1) and delete all reference to software serial as suggested, you will probably be OK - even @ 115200. Indeed, fat chance you would have at running that baud rate with software serial....

As suggested I connect the device to the TX1 pin 18 and the RX1 pin 19. Removed any reference to the software serial library. The code now compiles and uploads to the Mega board. However the serial data does not print to the serial monitor on the computer.

I used a different code/library I found online from someone else and it works perfectly.

I will use this moving forward.

Cheers

kwalking:
However the serial data does not print to the serial monitor on the computer.

I imagine that was because, while the device is fine on serial1, you still need to serial.print it to get it up on the monitor. But you've got a result, so all is well!

Nick_Pyner:
I imagine that was because, while the device is fine on serial1, you still need to serial.print it to get it up on the monitor.

That's why I suggested studying the Mega's MultiSerial example in the IDE.
It's clearly explained there how to move data from one serial port to the other.
Leo..