Jump to content


Photo

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

Shield RS232 v2 UNO

  • Please log in to reply
3 replies to this topic

#1 sip03ds

sip03ds

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 23 October 2015 - 11:41 AM

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



#2 youkee

youkee

    Advanced Member

  • Administrators
  • 237 posts

Posted 06 November 2015 - 12:53 AM

Read the SoftwareSerial site:
 

Please check the two COM ports, one is connected to Arduino USB, another one is connected to Linksprite RS232. 

Note: RX and TX pin is right, or you can try to exchange.



#3 sip03ds

sip03ds

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 06 November 2015 - 03:56 PM

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? 



#4 sip03ds

sip03ds

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 09 November 2015 - 11:29 AM

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 !






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users