SoftwareSerial TX problem

Hi!
I'm using Arduino nano with the library "SoftwareSerial.h" and I have a problem with the TX pin.
Problem is:
When I'm using pin no.11 as TX pin, no transmitting happening, only receiving. I discovered that when I comment on some part of code, TX on 11 then working normally.
Part of the code I comment on is no related to pin no. 11 and I'm not using pin no. 11 anywhere in code except in the constructor of SoftwareSerial.
Also discovered when I change the TX pin from pin no. 11 to pin no.12, everything is working fine - without commenting code.
Is it possible that is somehow related to the memory location issue or something like that?
I'm using now :
RAM: [==== ] 37.3% (used 763 bytes from 2048 bytes)
Flash: [=== ] 29.6% (used 9092 bytes from 30720 bytes)

Hi!

Do you realise we can see neither code, nor schematic?

Some code certainly can have a mysterious effect on pins, without the pins being explicitly defined in your sketch. Hardware SPI is an example which, incidentally, can affect exactly the pins you have been discussing.

I'm confused because when I comment on some random part of the code TX line again works.
And I'm not using any other library related to the physical pins of Arduino.

See reply #2

Here is part of the code that is related to that issue.


When i comment those lines, it is working.

Here is part of my answer:

What is the value of RELAY_1 in that code snippet ? 11 by any chance ?

Pictures of code are not ideal. The how to get the most from this forum post has instructions on how to properly post code. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to format code before posting in code tags.

No, it is pin no.5, and that function "send_SMS(number,message_to_send)" not contains digitalWrite or anything related to physical pins ,but contains thihg related to SoftwareSerial - example smsModem.print(message);

void send_SMS(String number, String message)
{
    wdt_reset(); //Reset watchdog timer

    if (setup_over)
    {
        String phone_numb = "AT+CMGS=\"" + number + "\""; //Phone number string format
        //smsModem.println(phone_numb);

        while (true)
        {

            if (smsModem.available() > 0)
            {
                String incomingResponce= smsModem.readString(); // Read  string from modem

                if (incomingResponce.indexOf("MODEM:STARTUP") != -1) // Modem send this message if restarted
                {
                    setup_over = false;
                    break;
                }

                if (incomingResponce.indexOf('>') != -1) // Waiting ">" from modem for sending message
                {
                    smsModem.print(message);    //Print message to modem
                    smsModem.println((char)26); // CTRL+Z (char for send message)
                    incomingResponce = "";
                    Serial.println("Sending message..."); //Debug
                    delay(5000);                          //pause for network to send sms
                    smsModem.println("AT+CMGD=1,4");      //Delete message from memory of modem
                    Serial.println("Message SENT!");      //Debug
                    delay(100);
                    break;
                }
                else if (incomingResponce.indexOf("ERROR") != -1) //Modem send this message if command is wrong
                {
                    break;
                }
            }
        }
    }
}

So, I found the solution! I literally changed the library from SoftwareSerial.h to NeoSWSerial.h and now all works fine! Seems like the SoftwareSerial library is not so good... following lines are ONLY lines that I changed in code:

//#include <SoftwareSerial.h>
#include <NeoSWSerial.h>

NeoSWSerial smsModem(RX_pin,TX_pin); //Rx pin,Tx pin
//SoftwareSerial smsModem(RX_pin,TX_pin); //Rx pin,Tx pin

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.