Arduino UNO & Linksprite Shield RS232 v2 - send message to RS232

Hi,

I 'm quite new with electronics, so pardon me if mistaken.

I have the following components:

  • Arduino UNO
  • Linksprite RS232 Shield v2

My goal is to dispatch from a static message (static at the moment - I plan to add an Ethernet shield later and relay a message from UDP port) from arduino to DB-9 port.

For my coding/testing environment I am using a PC with a USB and RS232 port (COM1) and a null modem cable.

The steps that I followed in order to accomplish it are:

  1. Soldered the pins on RS232 shield v2 (20151022_154938.jpg)

  2. Hooked up the RS232 shield on the arduino

  3. Set pin 2 as TX (20151022_154927.jpg)

  4. Set pin 3 as RX (20151022_154927.jpg)

  5. Opened IDE and uploaded the following code:

#include <SPI.h>         
#include <Ethernet2.h>
#include <EthernetUdp2.h>      
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(3,2); 
 
void setup()
{
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    mySerial.begin(9600);
    Serial.println("begin initial Serial USB!\n");
    mySerial.println("begin initial Serial DB-9!\n");
}
 
void loop() 
{
  mySerial.println ("static message DB9");
  Serial.println ("static message USB");
  delay(1000);
}
  1. The code runs and on serial monitor I get the message “static message USB”. The TX led on the RS232 shield is blinking every second (as it should)

  2. I hook the null modem cable to DB-9 connector of the shield and then on the PC.

  3. I open putty on COM1 (9600 baud , 8N1), BUT MY PROBLEM IS THAT I DO NOT GET ANY MESSAGES (static message DB9).

Any ideas?

Thank you all in advance

Hi,

I managed to make it work by performing the following change:

SoftwareSerial mySerial(2, 3);

Right now I am able to view messages sent both on USB & DB-9 port using putty.

The next step is to make it work with Ethernet shield v2 and relay a message to DB-9 from UDP port.

The code that I am using right now is:

#include <SPI.h>         
#include <Ethernet2.h>
#include <EthernetUdp2.h>      
#include <SoftwareSerial.h>

#define UDP_TX_PACKET_MAX_SIZE 1024

SoftwareSerial mySerial(2, 3);

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x10, 0x01, 0xED
};
IPAddress ip(10, 15, 120, 47);
IPAddress gateway(10, 15, 120, 1);
IPAddress subnet(255, 255, 255, 0);

unsigned int localPort = 8888;     

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip, gateway, subnet);
  Udp.begin(localPort);

  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {  
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {

    IPAddress remote = Udp.remoteIP();
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println(packetBuffer);
    mySerial.println(packetBuffer);

    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();

    for (int i = 0; i < UDP_TX_PACKET_MAX_SIZE; i++) { 
      packetBuffer[i] = 0;
    }

  }
  delay(10);
}

I am facing the following 2 problems:

  • In case I change the baud rate to 1200 instead of 9600 for both serial ports, I do get the message on COM, but I do not get the message on DB-9
  • In case the baud rate is 9600 and the messages are in Greek they are not correctly displayed on DB-9 - even though I change the encoding on putty and they are correctly displayed on IDE’s Serial Monitor

I would really appreciate any help.

Thank you in advance.

Hi,

I managed to fix both problems !!!

  1. I hook the null modem cable to DB-9 connector of the shield and then on the PC.

I attached a normal cable to DB-9 connector and everything works as expected.

I tested both 1200 baud rate and Greek encoding and it works flawlessly.