Jump to content
sip03ds

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

Recommended Posts

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 
4) Set pin 3 as RX 

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);
}

6) 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) 

7) I hook the null modem cable to DB-9 connector of the shield and then on the PC. 
8) 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

Share this post


Link to post
Share on other sites

Hi, 

 

Thank you for the reply, well I followed the instructions and I manage to make it work (partially). 

 

The code that I am using right now is: 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  mySerial.begin(9600);
  while (!mySerial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  Serial.println("begin initial Serial USB!\n");
  mySerial.println("begin initial Serial DB-9!\n");
}

void loop() // run over and over
{
  mySerial.println ("hello USB!");
  Serial.println ("hello Linksprite");
  delay(1000);
}

The change is on the following line:

SoftwareSerial mySerial(3,2); 

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

 

The problem appears when I change the baud rate:

  // Open serial communications and wait for port to open:
  Serial.begin(1200);
  while (!Serial) {
  }
  
  mySerial.begin(1200);
  while (!mySerial) {
  }

When I set the baud rate to 1200 and I reopen putty on 1200 baud, then messages are not displayed. 

 

Any ideas? 

Share this post


Link to post
Share on other sites

Hi, 

 

I managed to fix the problem. 

 

I attached a normal cable vs a null modem cable and it works as expected !!! 

 

Now, adding an Ethernet shield v2 in order to relay a message from UDP port I used the following code: 

#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

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip, gateway, subnet);
  Udp.begin(localPort);
  
  Serial.begin(1200);
  mySerial.begin(1200);
  
  // Different Baud Rate
  //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.write(packetBuffer);
    mySerial.write(packetBuffer);
    
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

Everything works great !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×