Unable to use values received at rx tx

Still not working, I tried using the software serial same as before with changing the connection. Nothing on the serial monitor. I tried reseting the arduino too.

I also tried the connections you recommend (i.e. on 7,8 pins). Output: Nothing!
Then I removed the serial monitor from the equation, powering arduino from external power supply 7.4v. Removed all serial statements, except those of softwareserial. And connected an led to be turned on or off according to the data received at the rx pin. It's simply not working.

Have you checked the Wiring Rx>TX, Tx>Rx as noted in reply#4?
Note that there is nothing magic about pins 7,8, indeed I only mentioned them because they are very un-magic.

Nick_Pyner:
Have you checked the Wiring Rx>TX, Tx>Rx as noted in reply#4?

Yes I did.
Here I think pin 2,3 can take interrupt on uno, so they might be ideal for the communication

What does a Serial.event() do? And how is it called from the loop?

Sounds like your RS232 to TTL converter is not working. You posted no details, so we can only guess.

Did you connect the grounds?

Actually in the first post I told that whatever I send from plc, shows up in my serial monitor, but it's after I reset the arduino, an then the setup statements appear. So I guess no problem with Rs232 to ttl converter.

Visual_Kol:
Here I think pin 2,3 can take interrupt on uno, so they might be ideal for the communication

No, and that is why I said Pins 7,8. Pins 2,3 will work OK for comms but there is no need to start bad habits you may regret later.

Guys, something much bizarre has happened today. of course i did not get the output as i wanted but just have a look.
I've attached a copy of the test codes I was conducting today. Please find it attached. I again tested with the Software Serial monitor, it seems to be unable to read any data. So it failed again.
But while I was experimenting with simple serial monitor code, I accidentally deleted the code for printing the received Character. So i further experimented with it. And finally uploaded this code.

void setup()
{
    Serial.begin();
    Serial.println("Serial Setup Complete");
}
void loop()
{
    
}

So, as you see I haven't read the data arriving in the serial buffer or printed it.
Now I send number '2' from the plc. I didn't get anything as expected. But when i reset the arduino It was as follows.

Serial Setup Complete
2Serial Setup Complete
2Serial Setup Complete
2Serial Setup Complete

So it means that the conception that the conflict between Serial monitor and tx rx working at the same time might be the reason to get this effect. But why is this value getting printed? that too before even setup begins the serial communication. and again how to store this value in a variable so that it can be used further.

Serial_Communication_Testing.ino (9.74 KB)

How do you have the PLC wired to the Arduino?

It looks like you are still using the serial monitor RX and TX (pins 0 and 1 on an Uno) connections for both, which is a very bad idea.

jremington:
How do you have the PLC wired to the Arduino?

AB Micrologix 1400 PLC has a DB9 port which supports RS232 protocol.
So the Connections are PLC <---> RS232 Cable <---> RS232 to TTL converter <---> Arduino (0,1)(Rx,Tx)

jremington:
It looks like you are still using the serial monitor RX and TX (0 and 1 on an Uno) connections for both, which is not allowed.

Yes but it's because my SoftwareSerial doesn't work!
Same as earlier, it doesn't take anything into the buffer. But for some reason hardware rx tx does (after reset). That's why I was trying to use rx tx and serial monitor parallelly.

Yes but it's because my SoftwareSerial doesn't work!

You are doing something wrong, but have not provided enough information for us to figure out what it is.

Software serial WORKS, at least at 9600 Baud. Continuing as you are will get you nowhere.

Post a very clear, hand drawn wiring diagram, showing all connections, with pins and parts carefully labeled.

The schematic is pretty simple. I've attached it, along with the code. And my apologise for not posting this earlier.

Please can you have a look at this
Do you think I should try using this DF1 library, while knowing that there is no standard DF1 library for arduino?

re reply#11, there is no such thing as a software serial monitor, the serial monitor is on hardware serial - no exceptions, and, if you have any peripheral connected to 0,1, you won't be able to upload..

Visual_Kol:
AB Micrologix 1400 PLC has a DB9 port which supports RS232 protocol.
So the Connections are PLC <---> RS232 Cable <---> RS232 to TTL converter <---> Arduino (0,1)(Rx,Tx)Yes but it's because my SoftwareSerial doesn't work!

You are connecting the peripheral to the hardware serial pins, 0,1 which, with Software Serial, will never work. If you insist on using Software serial, put it on pins 7,8 and use software serial there, then it might work. Indeed anything will do - except pins 0,1.

Your hand drawing does not agree with the pic in the link. You just have to make up your mind which serial method you want and code accordingly, and stop fartarsing about with both.

If AB say hardware, you should understand that is OK, and I assume the serial monitor is not part of the game. Just remember to disconnect the MAX232 when uploading the programme.

If you want to use software serial, it will be OK at 9600.

Get rid of the useless delays in the program shown in the .jpg appended to reply #15.

Then bidirectional character transmission should work, but if not, try swapping the wires connected to pins 2 & 3.

However, if you don't use the expected protocol, you will not be able to communicate properly with the box, and it may not respond AT ALL.

Nick_Pyner:
re reply#11, there is no such thing as a software serial monitor.

Sorry to confuse you, but when I was saying about using Rx Tx and Serial Monitor, I was trying to say that my SoftwareSerial method doesn't work, so I have gone back to Hardware Serial, removing SoftwareSerial from the picture.

Nick_Pyner:
Your hand drawing does not agree with the pic in the link.

Actually I was asking you, whether I should go with method that they have used in that link, so my drawing is not built according to that.

jremington:
Get rid of the useless delays in the program shown in the .jpg appended to reply #15.

The delay(50) is because PLC is sending data at every 50 milliseconds. And I send just ONE Character from PLC so ARDUINO should perfectly match with that.
The delay(1000) is because I was getting print statements in loop to quick to understand. So for now it is definitely useless. And I will get rid of them.

jremington:
Then bidirectional character transmission should work, but if not, try swapping the wires connected to pins 2 & 3.

I did try swapping the pins. I think I'm frustrating you guys by complicating my replies. I'll try to keep it simple onwards.
And I will further be uploading the code after disconnecting the RS232 - TTL converter from Arduino.

Maybe configuring the serial port (stop/start/parity bits) is necessary if these don’t match the standard used on the Arduino. See, for example, How to configure Start/Parity/Stop bits for Serial Communication - Programming Questions - Arduino Forum

Visual_Kol:
I have gone back to Hardware Serial, removing SoftwareSerial from the picture.

Good idea.
I can't help but feel that your problems may be at the other end but, since the makers have Arduino code, you should be able to use that verbatim, and the real problem is understanding how to use it. Further, this software serial stuff is just a result of misunderstanding.

The delay(50) is because PLC is sending data at every 50 milliseconds. And I send just ONE Character from PLC so ARDUINO should perfectly match with that.

No, you do not need a delay.

The Arduino is always ready to receive a character, and Serial.available will tell you whether one has arrived.

jremington:
No, you do not need a delay.

Actually I was following the Nick_Pyner's suggestions from #2 & #4.

Nick_Pyner:
you should be able to use that verbatim, and the real problem is understanding how to use it.

I don't understand this, can you please elaborate on that one?

6v6gt:
Maybe configuring the serial port (stop/start/parity bits) is necessary

On plc or arduino? And if on arduino, how to do that?

Actually I was following the Nick_Pyner's suggestions from #2 & #4.

You misunderstood Nick's point. You do not need a delay.

Maybe configuring the serial port (stop/start/parity bits) is necessary

On the Arduino. Consult the Arduino reference guide entry on Serial.begin() for instructions.

This:

#define DF1baud 9600
#define DF1format SERIAL_8N1

tells you the Baud rate and exact serial port configuration.

I don't understand this, can you please elaborate on that one?

The word "verbatim" means follow the instructions exactly as written.