[RESOLVED] SoftwareSerial and Ethernet conflict on Mega?

I’m trying to control Roomba with Arduino Mega 2560 and Ethernet Shield (connected to portable WiFi bridge). On it’s own, Arduino has no issues controlling Roomba. Ethernet shield also works on it’s own with default WebServer sketch.
But they do not work together.
Is there a documented conflict issue between SoftwareSerial and Ethernet libraries on Arduino Mega2560? I couldn’t find much online. Software serial is setup on PIN50 (RX) and PIN51 (TX) at baud of 115200.
Here’s a sketch below just in case…

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

int rxPin = 50;
int txPin = 51;
int ledPin = 13;

SoftwareSerial Roomba(rxPin,txPin);

#define bumpright (sensorbytes[0] & 0x01)
#define bumpleft  (sensorbytes[0] & 0x02)

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);

void setup() {
  pinMode(ledPin, OUTPUT);   // sets the pins as output
  Serial.begin(115200);
  Roomba.begin(115200);  
  digitalWrite(ledPin, HIGH); // say we're alive
  Serial.println ("Sending start command...");
  delay (1000);
   // set up ROI to receive commands  
  Roomba.write(128);  // START
  delay(150);
  Serial.println ("Sending Safe Mode command...");
  delay (1000);
  Roomba.write(131);  // CONTROL
  delay(150);
  digitalWrite(ledPin, LOW);  // say we've finished setup
  Serial.println ("Ready to go!");
  delay (5000);
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  digitalWrite(ledPin, HIGH); // say we're starting loop
  Serial.println ("Go Forward");
  goForward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  Serial.println ("Go Backwards");
  delay (500);
  goBackward();
  delay (500);
  Serial.println ("Halt!");
  halt();
  while(1) { } // Stop program
}

void goForward() {
  Roomba.write(137);   // DRIVE
  Roomba.write((byte)0x00);   // 0x00c8 == 200
  Roomba.write(0xc8);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}
void goBackward() {
  Roomba.write(137);   // DRIVE
  Roomba.write(0xff);   // 0xff38 == -200
  Roomba.write(0x38);
  Roomba.write(0x80);
  Roomba.write((byte)0x00);
}

void halt(){
 byte j = 0x00;
 Roomba.write(137);   
 Roomba.write(j);   
 Roomba.write(j);
 Roomba.write(j);
 Roomba.write(j);
}

When I comment out these two lines below, Roomba starts to work…

 Ethernet.begin(mac, ip);
  server.begin();

Is there any workaround for this or my own choice is to go with WiFi shield?

You need to take a look at the pins that the Ethernet shield uses, on the Mega. Hint: 50, 51, 52, and 53.

Why are you using SoftwareSerial on a device with 4 hardware serial ports?

PaulS: You need to take a look at the pins that the Ethernet shield uses, on the Mega. Hint: 50, 51, 52, and 53.

Why are you using SoftwareSerial on a device with 4 hardware serial ports?

Oh I didn't realize it. I know on Uno it uses others :) Thanks for the tip! Roomba doesn't like standard Serial Ports for some reason (at least on Uno). There have been many reports online about this issue, so people either use some kind of hex buffer or SoftwareSerial. I verified with Port 0 and 1 it doesn't work. Haven't tried other serial ports

Roomba doesn't like standard Serial Ports for some reason (at least on Uno).

Neither does my Hoover, but what that has to do with the problem you are having is not at all clear.

There have been many reports online about this issue, so people either use some kind of hex buffer or SoftwareSerial.

Maybe a couple of tennis shoes and a badminton racket would work. I really have no idea what you are talking about.

SoftwareSerial sets up a serial port that is similar to the hardware serial port, except slower and more resource intensive. It is no less real a serial port, though, that the hardware serial port.

I verified with Port 0 and 1 it doesn't work.

Again, clarity doesn't seem to be your strong suit. What do you mean by Port 0? Port 1?

First of all you already answered my question, thank you! :) As you pointed out SPI on Mega uses digital ports 50,51,52 and 53 that's why I had conflict. I should've realized it, but it wasn't obvious because Ethernet shield doesn't touch those pins. After you posted your comment I realized that it connects to those pins the via ICSP header.

You don't need to answer to anything I write below I'm just trying to explain since you asked...

The serial port output TXD from the iRobot Roomba is too weak to drive the RX serial port input of an Arduino properly. This is because of the USB-Serial converter on the Arduino: it also tries to drive the RX serial port input via a pullup resistor, but the Roomba does not have enough drive to pull the RX down below about 2.5 volts, which is insufficient to be reliably detected as a TTL serial input of 0.

As for my mentioning of Port 0 and 1, in the context of Serial communication in Arduino, I figured it would be obvious that I'm talking about PIN0 (RX) and PIN1 (TX).

Is this sufficiently clear now? :)

bratan: First of all you already answered my question, thank you! :) As you pointed out SPI on Mega uses digital ports 50,51,52 and 53 that's why I had conflict. I should've realized it, but it wasn't obvious because Ethernet shield doesn't touch those pins. After you posted your comment I realized that it connects to those pins the via ICSP header.

You don't need to answer to anything I write below I'm just trying to explain since you asked...

The serial port output TXD from the iRobot Roomba is too weak to drive the RX serial port input of an Arduino properly. This is because of the USB-Serial converter on the Arduino: it also tries to drive the RX serial port input via a pullup resistor, but the Roomba does not have enough drive to pull the RX down below about 2.5 volts, which is insufficient to be reliably detected as a TTL serial input of 0.

As for my mentioning of Port 0 and 1, in the context of Serial communication in Arduino, I figured it would be obvious that I'm talking about PIN0 (RX) and PIN1 (TX).

Is this sufficiently clear now? :)

Not obvious because the Mega has 3 other serial ports, called in ArduinoIDE as "Serial1" (RX1 & TX1 on the silkscreen), "Serial2" (RX2 & TX2), and "Serial3" (RX3 & TX3). While it is true that "Serial" (RX0 and TX0) has circuitry attached, the other three don't have any circuitry attached to them (other than the traces connecting the pins to the header). By referencing "pins" as "ports" I was also confused thinking you had tried "Serial" (to verify that what is reported true on the UNO in other forums is also true on the Mega) and one of the other three serial ports (to see if the lack of parallel circuitry would help). It might be true that the Roomba can't drive those either (I don't know, and I don't have a Roomba (nor the inclination) to try), but I would think a better solution would be to use one of the four hardware serial ports of the Mega, but with some sort of buffer circuitry to 'help' the Roomba serial port work with proper TTL signaling.

But, since you have solved your problem to your own satisfaction, my suggestion is just academic. ;) (I really need to get off my tush and hack into my Neato XV-21... Supposedly one can intercept the laser range finder (pseudo lidar) data stream to do one's own mapping and path-finding.)

Fair enough :) I also came to a conclusion that Serial1,2 should work no problem, just didn't have chance to test it :) is neato hacker friendly?

bratan:
Fair enough :slight_smile: I also came to a conclusion that Serial1,2 should work no problem, just didn’t have chance to test it :slight_smile: is neato hacker friendly?

I think it is, or at least used to be. I haven’t checked on the scene in a while, but if you feel so inclined look for people hacking the XV-11. It was the first one, and the other two models are really the same thing just different housings, attachments, and factory-loaded firmwares. (That reminds me… I should check to see if there is a firmware update…)

Just wanted to post small update. As expected Hardware Serial1 (RX1/TX1) works just fine controlling Roomba 551 from Arduino Mega2560. No need for SoftwareSerial. Hooray!!! :) Thanks again guys!

Just wanted to post small update.

And, thank you for doing that.

Bratan, is it possible that you could upload the code with the working (RX1/TX1) without using softwareserial? :)