ESP8266 Arduino SoftwareSerial

General discussion of using Roboclaw motor controllers
Post Reply
cupoftea
Posts: 3
Joined: Thu Jul 13, 2017 6:52 pm
ESP8266 Arduino SoftwareSerial

Post by cupoftea »

At the moment the Roboclaw arduino library wont compile with SoftwareSerial on non __AVR__ processors.
The espSoftwareSerial library is part of esp8266 Arduino and claims compatability with Arduino SoftwareSerial.
I'm inclined to modify the Roboclaw library ifdefs to allow it to compile but thought I'd better ask first if it's been tried before or is likely to be unuseable in real life.

cheers H
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: ESP8266 Arduino SoftwareSerial

Post by Basicmicro Support »

Yes, that should be fine as long as the ESP8266 software serial is compatible with the regular Arduino software serial.

You should only have to comment out these lines: "#ifdef __AVR__" and the associated "#endif"

Everything else should just work.
cupoftea
Posts: 3
Joined: Thu Jul 13, 2017 6:52 pm
Re: ESP8266 Arduino SoftwareSerial

Post by cupoftea »

Took a while but I've made progress.

Got SoftwareSerial to compile by commenting out the #ifdefs as suggested
I had to download the latest espSoftwareSerial from https://github.com/plerup/espsoftwareserial

It compiled but I got nothing from the PacketSerialReadVersion example..... So I switched to HardwareSerial. First on an esp8266 dev board and then an esp32. Got what I suspect may be the same problem.

Turns out the esps have a hardware FIFO Tx buffer and flush() makes it do something funky to its pointer and it sends from the wrong part of the buffer. (I don't know whats it's actually doing but that's what it looks like from here). So I neutered flush (giving back some #ifdef)

Code: Select all

void RoboClaw::flush()
{
#ifdef __AVR__
	if(hserial)
		hserial->flush();
#endif
}
and at this point things appear to be working. I've no idea if this is a good way of dealing with it but I'm keen to be working on my project so for now I'm assuming it's fixed.

I'm going to stay on esp32 HardwareSerial so I won't test SoftwareSerial again but I'm guessing it will work now. (edit: on reflection maybe not..... flush() contained if(hserial) )

for what it's worth the following set's up Serial1 on esp32 pins rx 16 tx 17

Code: Select all

#ifdef ESP32
HardwareSerial Serial1(2);
#endif
Happy Daze
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: ESP8266 Arduino SoftwareSerial

Post by Basicmicro Support »

The functionality of Flush in the Arduino serial libraries has changed atleast once before so Im not surprised you had to modify that.

If its working I dont see any problem.

Post Reply