I am doing a project trying to read some data from a device sending some motor data out via RS-232. I have verified from my USB-serial keyspan adapter and my terminal software on my PC, that the data is being sent out right at the DB9. I am using the MAX3232 module with an arduino mega, and have the Serial1 tx and rx lines going to the MAX. I have tried switching the tx and rx lines because some of the reviews on amazon said they were switched. I can't get any data to display on the serial monitor, and wrote some simple code to just mirror what was received from the MAX module. I swapped the module out just in case it was a defective one, and still no change.
Does anyone have any clue what could be going on here? This just makes zero sense to me as to why it isn't working. Also, module connected to 5v and ground on the mega as well. Thank you in advance for any feedback
void setup() {
Serial.begin(9600); // Serial Monitor
Serial1.begin(9600); // RS-232 input via MAX3232
Serial.println("Ready to receive data...");
}
void loop() {
if (Serial1.available()) {
Serial.write(Serial1.read()); // Directly write received data
}
}
I also tried this code, but same result, nothing
void setup() {
Serial.begin(9600); // Serial Monitor
Serial1.begin(9600); // RS-232 interface via MAX3232
}
void loop() {
while (Serial1.available()) {
char c = Serial1.read();
Serial.print(c); // Print received character
if (c == '\n') { // Ensure proper new line formatting
Serial.println();
}
}
}
RS-232 requires a data ground connection. You made no mention of a ground connection between the MAX3232 and your Arduino. In addition, with no signal, the RS-232 TX will be positive to ground, and the TTL side of the MAX3232 for the transmit data will be just the opposite, it will be zero volts, or near there on the TTL side. Check with your meter.
Are you really sure about that? rs232 is horribly ambiguous about things like "is this the tx pin, or does it connect to the tx pin of the other device?"
and the MAX module ground is connected to the Arduino Ground as well?
You're absolutely right, but I know that the DB9 to the system is connected right because once I plug in my usb-serial keyspan adapter and connect with my PC terminal, it works no problem.
Yes, the MAX module VCC goes to arduino +5v, and ground to ground. I have not checked if the pin 5 of the DB9 (ground) actually gets connected to the ground of the MAX module, but I would assume it has to be, right? That's part of the rs-232 standard.
Not sure I need to draw it out, it’s pretty simple. Note, I have also switched the rx and tx as I mentioned, but it didn’t change anything. Right now I have MAX rx to arduino tx and Max tx to arduino rx.
If you know of anyone nearby who has one of these, it'll sort your problem for you in minutes. There's nothing like being able to see at a glance which signals are active.
Fortunately, since you are using a hardware serial port on a Mega, you can wire pins 2 and 3 of the MAX module together and do a loopback test to make sure the wiring to the arduino is correct.
I still have one of those I built when I was going to tech school in the early 1980's. Very handy, back then you bought wire and cable ends and put the cable together yourself, trying to buy anything compatible with whatever equipment you had was nearly impossible.
Responding to both of your posts: I didn't think of it being switched within the DB9. Can you explain a bit more about doing that loop back test? I understand the concept, but not sure I understand how I would wire it.
Loopback test is fairly simple. The wiring between the Mega and MAX does not change, you just need to connect pins 2 & 3 on the RS-232 side. Using the serial terminal, have a sketch that reads from Serial and writes to Serial1, then reads from Serial1 and write to Serial. Whatever you send from the serial terminal should appear back in the serial terminal.
That's really neat, I'd love to get one of those. I think I saw one on amazon earlier, I'll have to go back and look. Could I tap in somewhere with my scope to check?