I know that I will be hated for making this topic. I know that there is a lot of tutorials about this but none of them is helping me.
I want to read data from RS232, I know that I cannot hook up directly RS to Arduino, so I bought some converter(RS232 - UART TTL) based on MAX3232. I have tried a lot of codes on the forum but none of them seems to work for me. For now I have:
#include <SoftwareSerial.h>
int incomingByte = 0; // for incoming serial data
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
mySerial.begin(9600);
}
void loop() {
// send data only when you receive data:
if (mySerial.available() > 0) {
// read the incoming byte:
incomingByte = mySerial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
What I am trying to do is at least print received data from RS232(it is old laptop with RS232 connection and program called "Terminal v1.93b by Br@y++").
Nothing is working... Is there something wrong with code? Shouldn't it work?
You don't really have a mySerial connected to the Arduino, do you? Why such a dumb name for the instance? Why not name it to match what is really connected?
int incomingByte = 0; // for incoming serial data
Why the hell are you using Byte in the name of something that is NOT a byte?
J-M-L:
Well at least there was a meaningful variable name there
To the OP: how are you sure of the speed of the rs232 ? 9600 bauds for sure? Which pin is connected to what?
I am sure, because as I wrote I am using program to send/receive data on RS port. I can set up all connection details including speed.
Of course Rx and Tx from converter are connected to port 10/11. I was trying to switch them around but no success.
I have also tried some example code directly from Arduino Studio but also no success.
PaulS:
SoftwareSerial mySerial(10, 11); // RX, TX
You don't really have a mySerial connected to the Arduino, do you? Why such a dumb name for the instance? Why not name it to match what is really connected?
It is a example code, which was used in some Arduino tuts. So if you call person who wrote it a "dumb" then don't waste your time in this topic.
I asked for help nicely, you don't have to act like a buffon...
sarouje:
Tell us, how you connected the RS232 converter to Arduino.
Do you have common GND with converter and arduino?
Variable naming is very important. Even if you are copying from some other place, it's your responsibility to code it correct.
So I have RS232 comming out from PC to a converter socket(DB9). Converter(it is based on MAX3232 chip) have 4 pins: VCC(I have connected 5V from arduino), GND(GND from arduino), Rx and Tx. Rx i tried to connect to 10 and Tx to 11. I had no success with reading any data, so I swapped them around - also no success.
I am sorry for in naming variables good, but first I wanted code to work
#include <SoftwareSerial.h>
SoftwareSerial RS232Out(10, 11); // RX, TX
int i = 0;
void setup() {
Serial.begin(9600);
RS232Out.begin(9600);
}
void loop()
{
char buffer[4];
if(i>30000) {
Serial.println("Sending 02");
sprintf(buffer, "%02X ", 0x02);
RS232Out.write(buffer);
i=0;
}
if (RS232Out.available()) {
int inByte = RS232Out.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
RS232Out.write(inByte);
Serial.write(inByte);
}
i++;
}
I connect my laptop RS232 output to the converter and I don't receive any messages on COM1.
BUT! I have also some converter from RS232 to USB and I connect this to my laptop(it's installing on COM4) and everything works fine. I can send and receive messages both ways.
BUT! I have also some converter from RS232 to USB and I connect this to my laptop(it's installing on COM4) and everything works fine. I can send and receive messages both ways.
Well the converter is from 3.3V to 5V but it works perfectly fine.
Maybe I will explain it one more time.
When I am using RS232 port on my laptop and connect a cable there and the other end to the converter(which is connected to arduino), it is not working(no messages are coming through).
When I use USB to RS232 converter(one end is USB and I connect it to the laptop and second end is DB9 end and I connect it to the converter) instead normal RS232 port everything is working, all signals are coming through.
RS232 on laptop is working fine, because I was testing it with another computer.