SoftwareSerial conflict with Serial and,or Wire


I'm using :

  • arduino nano
  • pcf8574 + 2 tiny 128x64 display on the I2C bus
  • sim800L gsm

Let's says it' a kind of "enhanced" phone.

I use:

  • Serial to output debug information.
  • SoftwareSerial for communication with the GSM module with pin D7 and D6
  • I2C bus on pin A4 A5

SIM800L is used as long distance remote control...

As long as I don't initialize the GSM board with SoftwareSerial, remaining logic works fine. When SoftwareSerial is initialized, boards are at least frozen. Sometime LCD over I2C display whatever, just like an old TV of the 70' and no feedback over Serial in the console.

  • If I do not use debug over Serial, the software works, but debug is impossible (blind coding...).
  • If I only use Serial and SoftwareSerial with SIM800L, it works (it's tricky but seems to work, at least I have feed back over serial in the console) .
  • If I removed the SIM80L and just initialize the SoftwareSerial. The problem still occurs.

Libraries used:

  • PCF8574: RobTillaart/PCF8574@0.3.2
  • Displays: olikraus/u8g2@2.28.8
  • SIM800L: actually none

Are there any consideration or limits to use these hardwares or,and API all together ?


Is this a typo? The I2C bus should be on A4 & A5. Or are you using a software I2C library?

1 Like

Yes typo, and adding libraries in the initial post. thanks

Have you set Preferences: Compiler warnings: to 'All'? if you do that, does your sketch compile without any warnings?

Build seems fine. I use platformio which generate a cmake file with these options:
SET(CMAKE_C_FLAGS "-std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p")

What so you have in mind ? a link error ?

A programming error. I can't see your code but the compiler can. Sometimes a compiler warning will point to a programming mistake. If you are not getting any compiler warnings then there could be a mistake too subtle for the compiler to see.

What does the compiler say about Flash and SRAM usage ?
The OLED U8g2 library uses a lot of memory. You could consider U8x8, but I would select an Arduino board with more memory.

Your topic is in the wrong category. You can change that if you scroll up and edit that.


Using a lot of Serial prints while your also trying to read stuff on softeware serial can result in characters being missed in the software serial reads.

@spassignat Installation and Troubleshooting is for Problems with the Arduino itself NOT your project. It says so in the description of the section. Therefore I have moved your post here.

You may want to read this before you proceed:-
how to get the best out of this forum

1 Like

Thank you all for these contributions.

SoftwareSerial desactivate interrupt during write operation (line 436). So it's impossible to receive data while sending some (kind of simplex communication) which may also interfere with hardware serial.

Highly likely you are running out of ram. Each serial interface allocates 128 bytes of buffer, and the displays buffers take a lot of ram.

I use the 8x8 implementation, it uses very few memory compared to more graphical implementations. @david_2018 it seems we faced the same difficulties ... :wink:

So if I understand well, all the issues come from interruption management by libraries and having several buses creates "interference".

I use many serial communication 1 for GSM, 1 memories, 1 for debug and an i2c bus for 4 others, I will probably face a lot of issues going further in the software.

What would be a better solution ? to put everything on the I2C bus ? (If I can find devices with this bus interface)
Connect the GSM to the Mosi/Miso ? but here that's gona be harder as I don't have a CS pin to activate it...

If you don’t have a CS pin hen you don’t have an SPI interface.

Usually I have a lot of solution ideas, but here I feel a little stuck. I don't see which solution could be simple, reliable ...

I tried:

  • to suppress all logs in the console (Serial) but apps still freezes.
  • to connect GSM on Serial but I don't really like having several printing source (arduino and GSM) in the same print stream (Serial).

How would you address this challenge ? Convert I2C or SPI to Serial which may requires more than a simple chip (if such exists), because modem may not synchronously answer? Use hardware serial in addition to other elements ?

Simple diag. to remind the context.

Some suggestions ?

Drop SoftwareSerial and move to a more capable Arduino with a minimum of 2 USART, I2C,and SPI (if you really need that.) You can never have too much SRAM/flash but over purchasing will increase your cost. Seek a balance.

(I do not understand in your diagram why Tx/Rx are unused; that is, why are you not using this for Diags? Like with a USB-serial adapter module.)

An old Arduino and LCD can be a very handy project for your workbench:

1 Like

Yes this sort of thing does exist as a single chip :-

@Grumpy_Mike MAX3107 is an interesting solution. I'm actually searching an equivalent which is not CMS (easier for me at this point).

I'm not sure yet, but isn't it possible to use an I2C expander (PCF8574, MCP23017, ...) to create a "Hub" of Serial buses ? The driver might be as complex as SoftwareSerial either...

BTW thanks a lot for you advice

@mrburnette I'm using the onboard USB connector for firmware upload and diagnostics. Tx/Rx pins are not physically used but they're used by the USB controller (If I read well arduino nano schematic).
My diagram is maybe not clear enough...

No not really. All they do is to provide extra I/O. It would actually be harder to create a serial software version to work with them, and you would still be faced with the problem of only being able to look at one serial stream at a time.

If you want more then one serial port then you have to go for an Arduino that has more than one. The Leonardo and the Micro both have two ports, although one is a virtual port. The Mega has 4 serial ports, and the PR2040 connect can be made to have eight ports.

Not impossible, in the days when you used raw machine code there was no serial printing facility and you had to rely on setting pins high / low or turning an LED on or off.

Nowadays you can use a protocol / logic analyser like sigrok
The software is free and the hardware is not very expensive
8 channel logic analyser

1 Like

Thanks for all that.

I had a look at the Arduino Micro, but I can't really find where is that second Serial port or second UART. Replace the Nano by Micro is my actual plan D (but requires a lot of changes). Interface the GSM with an external UART is plan C. Before all that, I'm exploring a plan B. (you can say I'm a little stubborn, but I bet I'll learn something at the end)

About interrupt, Serials, I2C ... I would like to understand a bit more, how they interfere.

I know when SoftwareSerial reads from the pin, it interrupt the controller which can screw up communication on Serial. Then if I understand well the situation, when something writes on the hardware Serial it also interrupt the sequence which prevent the SoftwareSerial to compute properly the time and then it reads data with delays which is more or less equivalent to read random data. Let's say the TwoWire library works like SoftwareSerial and plays with interrupts.

So if I don't have any communication on Serial, I should be able to continue playing with all those devices.

GSM on SoftSerial: works request / response. Should not push data whenever.
Serial: I commented debug, so, unused.
I2C: works request / response
So I guessed if I just open communication with these devices, talks, and terminate the communication and not retaining references I would just skip the constraints. In fact not really or not all the time.
Here is an example:

	auto *GSM = new ExGsm(RX, TX);
	operators = GSM->getOperatorsList();
	timestamp = GSM->getLocalTimestamp();
	oper      = GSM->getOperator();
	error     = GSM->errors();
	lock      = GSM->getLock();
	delete GSM;

void testScreen() {
	U8X8 *display1 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE, PIN_A5, PIN_A4);
	display1->setCursor(0, 4);
	display1->setCursor(3, 4);
	display1->setCursor(0, 6);
	display1->setCursor(5, 6);
	display1->setCursor(1, 1);
	delete display1;

void loop() {

Guess what. It works a little bit but I attempted to read sms and then everything is totally screwed up. GSM does not respond anymore. screens are up side down, random display, ...

So I don't understand why it's failing. Any ideas ?