SoftSerial has no output but the port is ok

I can’t get soft serial to output from a port but the port is working.

I check the port by sending

digitalWrite(SoftTXPort, HIGH); // show that the port is ok
delayMicroseconds(10);
digitalWrite(SoftTXPort, LOW);

They are seen on a CRO but the SoftSerial.println(" is not being sent from the port -


#include <SoftwareSerial.h>

int SoftTXPort=6;
int SoftRxPort=7;

int SoftTXPIN=9;
int SoftRxPIN=10;

SoftwareSerial SoftSerial(SoftRxPIN, SoftTXPIN); // RX, TX

int BeepHz; // this existing variable will be recycled for the test

void setup()
{

// SoftSerial.begin(115200);
SoftSerial.begin(1200); // low rate is easier to see on the cro

// pinMode(9, OUTPUT);
// pinMode(10, INPUT); // Soft Serial Rx

BeepHz=800; // this existing variable will be recycled for the test

while (BeepHz==BeepHz){ // recycled BeepHz for this temp test

digitalWrite(SoftTXPort, HIGH); // show that the port is ok
delayMicroseconds(10);
digitalWrite(SoftTXPort, LOW);
delayMicroseconds(10);
digitalWrite(SoftTXPort, HIGH);
delayMicroseconds(10);
digitalWrite(SoftTXPort, LOW);
delayMicroseconds(10);
digitalWrite(SoftTXPort, HIGH);
delayMicroseconds(10);
digitalWrite(SoftTXPort, LOW);

delayMicroseconds(100);

if (SoftSerial.available()) {SoftSerial.println("5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A");
}
if (SoftSerial.available()) {
SoftSerialRead=SoftSerial.read();
}
delay(100);

if (SoftSerial.available()) {SoftSerial.println("AT+CGSN");
}
if (SoftSerial.available()) {
SoftSerialRead=SoftSerial.read();
}
if (SoftSerial.available()) {SoftSerial.println("AT+CGSN");
}
if (SoftSerial.available()) {
SoftSerialRead=SoftSerial.read();
}

} // while

what microcontroller are you using? e.g. UNO, Nano, ESP32, RP2040, etc
maybe worth trying AltSoftSerial

1 Like

Thanks for your reply.

It is a genuine Arduino Nano.

Your SoftSerial is on pins 9 & 10, and your "Port" is on pins 6 & 7.
What the "Port" has to do with "Serial" ?
What is point to your "checking the port" which uses a complete different pins than Serial?

The code that you posted does not compile.

I've used modified and shortened code to do a test.
I used an Arduino Uno R3.

What are you expecting the following lines to do:

if (SoftSerial.available()) 
{SoftSerial.println("5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A");

Are you expecting it to automatically send out that "5A5A5A5A....." message?

It is waiting for input on the SoftSerial input pin.
Where does that come from?

For my test, I added Serial.begin and connected pin1 to pin 10, so that I could type a message in the Serial Monitor that would start the sending of the "5A5A5A5A....." message.

Code used.
#include <SoftwareSerial.h>

int SoftTXPort = 6;
int SoftRxPort = 7;

int SoftTXPIN = 9;
int SoftRxPIN = 10;

SoftwareSerial SoftSerial(SoftRxPIN, SoftTXPIN); // RX, TX

int BeepHz; // this existing variable will be recycled for the test

void setup()
{
  Serial.begin(1200);
  SoftSerial.begin(1200); // low rate is easier to see on the cro

  pinMode(6, OUTPUT);
  pinMode(7, INPUT);

  BeepHz = 800; // this existing variable will be recycled for the test

  while (BeepHz == BeepHz) { // recycled BeepHz for this temp test

    digitalWrite(SoftTXPort, HIGH); // show that the port is ok
    delayMicroseconds(10);
    digitalWrite(SoftTXPort, LOW);
    delayMicroseconds(10);
    digitalWrite(SoftTXPort, HIGH);
    delayMicroseconds(10);
    digitalWrite(SoftTXPort, LOW);
    delayMicroseconds(10);
    digitalWrite(SoftTXPort, HIGH);
    delayMicroseconds(10);
    digitalWrite(SoftTXPort, LOW);

    delayMicroseconds(100);

    if (SoftSerial.available()) {
      SoftSerial.println("5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A");
    }
  }
}

void loop(){}

Here is an oscilloscope trace showing what happens when I sent 'Hello' from the Serial Monitor:

  • Channel 1 - yellow trace - pin 6, SoftTXPort
  • Channel 2 - red trace - pin 7, SoftRxPort
  • Channel 3 - blue trace - pin 9, SoftTXIN
  • Channel 4 - green trace - pin 10, SoftRxPIN


SoftSerial begins to send your message as soon as it has received the first character of my message.

If I don't send a message from the Serial Monitor, the code just sends out the groups of three pulses on pin 6, SoftTXPort, shown here on a faster time base:

This does not mean « if the port is working », it means « if there is an incoming byte pending »


Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

1 Like

Thanks for all your help.

I used …PIN variables for code that needs to be passed a pin number, pinmode(…PIN

and …PORT variables for digitalwrite(..PORT .

The short burst was to see if the port hardware was ok. It wasn't removed when I was trying to check the serial code.

I expected to see a string of alternating characters and a couple of AT codes.

I have no help because I installed offline with help from sterretje.

The help looks for online help and doesn't fallback to (outdated) local help. Not a criticism, just an excuse.

Thanks for the excellent example and CRO traces!

Sorry, I used the “Code” button but not the “/Code” one.

Thanks for the help on code formatting.

Thanks for your excellent help John.

I have found my stupid error.

SoftwareSerial SoftSerial(Rx,Tx); uses port numbers, I passed pin numbers.

Now at any time SoftSerial.println(“Sloppy Code”); works.

My computer is no good

I will have to sell it

Because it won't do what I want

Only what I tell it.

Not sure what you mean by that…

I used (10,9) thinking it used pin numbers but it configured to ports 10,9.

When I used (7,6) it became ports 7,6 (on pins 10 and 9) which is what I wanted.

OK - I guess we dont have the same meaning for PORTs and PINs.

At the hardware level, a port is a group of up to eight input/output lines inside the ATmega328P microcontroller. The Nano has three such groups: PORTB, PORTC, and PORTD. Ports are simply a hardware way for the microcontroller to organize its I/O pin. Each bit of the port corresponds to one physical connection on the chip, and the microcontroller can read or write all eight lines of a port in parallel.

So when you say

It does not make any sense. There is nothing called port 9 or 10.

At the Arduino API level, a pin is the number you use in code to refer to one of the Nano’s connectors, such as 2 or 13. The Arduino core defines a table that maps each pin number to the correct port and bit inside the chip.

This means when you call digitalWrite(13, HIGH), the core checks the table to find which port and bit belong to pin 13, and then sets that hardware line.

The user only works with PIN numbers if you use the API, while the underlying code ensures the right hardware port is addressed.

So unless you start playing with PORT registers you would only use the logical pin definition (the labels you usually see printed on the Arduino next to each pin).

Please describe the difference between ports and pins.

Thanks for that detailed explanation.

Obviously my experience with PC serial and parallel ports doesn't apply to Arduino devices. I was thinking in terms of a single pin being a serial port handling digital information, or a pin being an analog port.

I must think in terms of Port x, pin n.

Do you generally “forget” about Ports A, B and just think in terms of pins D2 to D13 as they are labelled on a Nano because digitalRead() uses just pin numbers?

Yes, if you use only the Arduino API, you would not refer to PORTs at all - just pin numbers (the numbers 0, 1, 2, ... or labels like A0, A1, A2...)

Thanks for your help