0
votes

I'm working on a project where I have to communicate to a machine using RS232. I've been using an RS232 to USB adapter to work on getting the machine to work, by communicating on a serial terminal (Termite). So now the machine is completely function and I can work on it from my computer.

However, the next step is to automate some of the processes that this machine does. So I want to control it using an Arduino Uno.

enter image description here

So I have these pin outs of the RS232 from the manual of the machine, however this is practically all there is when connecting using RS232. So the next thing I've done is the following:

RXD -> TX (PIN 2 on RS232, to PIN 3 on Arduino)

TXD -> RX (PIN 3 on RS232, to PIN 2 on Arduino)

ground to ground (PIN 5 to ground)

One issue I'm running into is that to upload to the Arduino, I cannot be connected to the dedicated RX and TX pins (pins 0 and 1), so I've done the following. Super basic.

void setup()
{
  byte rx = 2;  //rx pin number
  byte tx = 3;  //tx pin number
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
  Serial.begin(9600, SERIAL_8N1); //9600 baudrate, 8 data bit, no parity, 1 stop bit
}

void loop() 
{
  Serial.write("/1P200R\n");  //writes/1P200R (this is a built in command on the machine that works when connected to the machine using USB. The \n is the character return (CR)
  delay(1000);
}

When I do this, I can see the ouput of /1P200R every second on the serial monitor, but my machine does nothing.

Does anyone have any suggestions on how I can get some communication with my machine through the Arduino? Should I be using pin 0 and 1, the dedicated RX and TX? I've tried this but nothing changed with the output.

1
RS232 uses negative voltages and more then +/-5 V. you need a RS232 to TTL Serial adapter - Juraj

1 Answers

0
votes
void setup()
{
  byte rx = 2;  //rx pin number
  byte tx = 3;  //tx pin number
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
  Serial.begin(9600, SERIAL_8N1); //9600 baudrate, 8 data bit, no parity, 1 stop bit
}

Serial is the hardware serial of the Arduino's microcontroller connected to pins 0 and 1. Naming variables rx and tx and making the respective pins 2 and 3 input and output does not help you at all.

If you want to use other digital I/O pins of the Arduino for serial communication you have to emulate that in software using SoftwareSerial

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
}