and used the cable to connect them. But the receiver does not receive anything. I also tried to switch rx/tx because I am not really sure if my cable is cross over. But this also resulted in no data. If I connect again directly everything works fine.
not recommended to use UNO pins D0 and D1 as they are used to program the device and by the serial monitor
Try this code which uses pinsAltSoftSerial library pin 9 Tx and pin 8 Rx
// AltSoftSerial transmit/Receive Test
//
// from https://github.com/PaulStoffregen/AltSoftSerial/blob/master/examples/ReceiveTest/ReceiveTest.ino
//
// Transmit data with Serial1 and try to receive
// it with AltSoftSerial. You must connect a wire
// from Serial1 TX to AltSoftSerial RX.
#include <AltSoftSerial.h>
AltSoftSerial altser;
const int mybaud = 19200;
// UNO connection to a RS232-TTL
// UNO PIN 8 to RS232 RXD
// UNO pin 9 to RS232 TXD
// Board Serial1 TX AltSoftSerial RX
// ----- ---------- ----------------
// UNO/nano 9 8
// Teensy 3.x 1 20
// Teensy 2.0 8 (D3) 10 (C7)
// Teensy++ 2.0 3 (D3) 4 (D4)
// Arduino Leonardo 1 13
// Arduino Mega 18 48
// Serial1 on AVR @ 16 MHz minimum baud is 245
// Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733
void setup() {
delay(200);
Serial.begin(115200);
while (!Serial)
; // wait for Arduino Serial Monitor
altser.begin(mybaud); // to AltSoftSerial RX
Serial.println("\n\nAltSoftSerial transmit/ Receive Test");
Serial.println("on a UNO connect pins 8 and 9 for a loopback test");
Serial.println("using RS232 module connect pins 2 and 3 for a loopback test");
Serial.println("characters entered on serial monitor keyboard are echoed back via serial to the display");
}
void loop() {
// transmit a test byte on Serial 1
if (Serial.available() > 0) {
altser.write(Serial.read());
}
// attempt to receive it by AltSoftSerial
if (altser.available() > 0) {
Serial.write(altser.read());
}
}
ininially connect UNO pins 8 and 9 together to form a loop back test - characters entered on the serial monitor are echoed back to the display
if that works connect the TTL-RS232 module
// UNO connection to a RS232-TTL
// UNO PIN 8 to RS232 RXD
// UNO pin 9 to RS232 TXD
to check it is working connect pins 2 and 3 together to form a loopback test
if that works connect the UNOs together
Edit: any particular reason to use RS232 - for a couple of metres TTL would probably work
2. The above Module-1 (Fig-3) accepts TTL signal from Arduino-1 and produces RS232 signal at the female DB-9 connector side. Connect TTL side (RXD, TXD, VCC, GND) of Module-1 with Arduino-1 (Fig-3).
This made my day, thanks! Loopback worked. So I tried to connect the two RS232 to ttl module pins also directly without cable. Now it also worked.
But only with crossover! When using straight, it also does not work to change the rx/tx pins. Any ideas why?
I only need 1 - 2 m. I went for rs232 because in my last project I had several microcontroller freezes because of 20 cm cables near higher voltage cables. When changing them to pcb the problem was gone. Can I also be save by using the correct shielded cables?