(RESOLVED) Serial commands from Uno using DB9 shield to DB25

Hi,

I have an Arduino Uno equipped with a RS232 shield (RS232 Shield For Arduino - RobotShop) that converts the Uno's UART signal to Dsub signal. My setup uses a DB9-to-DB25 cable, with DB9 attached to the shield, DB25 attached to a liquid dispenser.

The commands that I need to send are very simple: "V(variable)" and then "D". The instrument should also send a response back confirming it got the command. I assume I should be sending the ASCII numbers for these characters.

While the shield is functional (I used the tutorial sample code) the instrument is showing no response to the commands. I have tried writing the commands in both hex and binary, sending the binary signals both as one Serial.write and as individual Serial.writes (the latter shown below in code), to no avail. I am new to Arduino and am pretty sure this is a simple fix of how I am sending the commands.

Here is the relevant excerpt of code, currently written in the format of 1 start bit/8 bits/1 stop bit as per the instrument's requirements:

 if (counter < rows) {
    Serial.write(0); // V start bit
    Serial.write(0); // V bit 0
    Serial.write(1); // V bit 1
    Serial.write(0); // V bit 2
    Serial.write(1); // V bit 3
    Serial.write(0); // V bit 4
    Serial.write(1); // V bit 5
    Serial.write(1); // V bit 6
    Serial.write(0); // V bit 7
    Serial.write(1); // V stop bit
    Serial.print(0); // volume start bit
    Serial.write(0); // volume bit 0
    Serial.write(0); // volume bit 1
    Serial.write(0); // volume bit 2
    Serial.write(1); // volume bit 3
    Serial.write(0); // volume bit 4
    Serial.write(1); // volume bit 5
    Serial.write(0); // volume bit 6
    Serial.write(0); // volume bit 7
    Serial.write(1); // volume stop bit;
    Serial.write(0); // LF start bit
    Serial.write(0); // LF bit 0
    Serial.write(0); // LF bit 1
    Serial.write(0); // LF bit 2
    Serial.write(0); // LF bit 3
    Serial.write(1); // LF bit 4
    Serial.write(0); // LF bit 5
    Serial.write(1); // LF bit 6
    Serial.write(0); // LF bit 7
    Serial.write(1); // LF stop bit
    Serial.write(0); // D start bit
    Serial.write(0); // D bit 0
    Serial.write(1); // D bit 1
    Serial.write(0); // D bit 2
    Serial.write(0); // D bit 3
    Serial.write(0); // D bit 4
    Serial.write(1); // D bit 5
    Serial.write(0); // D bit 6
    Serial.write(0); // D bit 7
    Serial.write(1); // D stop bit
    Serial.write(0); // LF start bit
    Serial.write(0); // LF bit 0
    Serial.write(0); // LF bit 1
    Serial.write(0); // LF bit 2
    Serial.write(0); // LF bit 3
    Serial.write(1); // LF bit 4
    Serial.write(0); // LF bit 5
    Serial.write(1); // LF bit 6
    Serial.write(0); // LF bit 7
    Serial.write(1); // LF stop bit
    while(Serial.available() > 0) {
      byte reading = Serial.read();
      Serial.println(char(reading));
    }
  }

I've also attached the excerpt of the user manual that outlines serial control for the instrument.

Advice would be MUCH appreciated- I've been running in circles trying to figure out how to send these commands!

Thanks,

Kate

Multidrop_SerialControl.pdf (273 KB)

have you tried to just bit bang it or does the interface use the RTS DTR signals from rs-232?

ok scratch that... becasue in the pdf, it says RTS and DTR are not used, which means theorhetically you can use this device without the rs-232 shield.

also you are going about this the way hard way :

    Serial.write(0); // V start bit[color=#222222][/color]
    Serial.write(0); // V bit 0[color=#222222][/color]
    Serial.write(1); // V bit 1[color=#222222][/color]
    Serial.write(0); // V bit 2[color=#222222][/color]
    Serial.write(1); // V bit 3[color=#222222][/color]
    Serial.write(0); // V bit 4[color=#222222][/color]
    Serial.write(1); // V bit 5[color=#222222][/color]
    Serial.write(1); // V bit 6[color=#222222][/color]
    Serial.write(0); // V bit 7

is the same as :

Serial.print('87', BIN);

however '87' is just the decimal equivilent to capital V on the ascii table so really all you need to do to send a command is

Serial.print("V\n");

which should have the device return to you the version number according to the datasheet.

\n is new line
\r is carriage return

:slight_smile:

int value;
Serial.print("V");
Serial.print(value);
Serial.print("\n");

the above code woudl send a value to the machine in a format that it is looking for.
i would suspect you are confusing it with your start and stop bits...

Hey,

Thanks so much for your input. I reached the same conclusion about simply using the actual characters "V" "D" etc. with Serial.print() but unfortunately no response whatsoever from the instrument. It reads out just fine in the serial monitor.

Not sure if it's worth replacing the actual DB9-DB25 cable? Running out of ideas for what could be causing the miscommunication!

Thanks again.

In fact, I'm realizing that all I need is to output is a "G"! So simple, yet I must be doing something wrong. Here's my current code:

void setup() {
  Serial.begin(9600);
}

void loop() {
    Serial.print("G");
    Serial.print("\n");

    while(Serial.available() > 0) {
      byte reading = Serial.read();
      Serial.println(char(reading));
    }
    delay(15000);
}

Not sure that the little loop at the end is the right way to receive info from the instrument, but I am far more concerned with transmitting info to the instrument, which isn't effective.

like i was saying previously, since the device doesn't use DTR and RTS, what about just running a piece of regular wire between the RXD of the Device and the TXD of the arduino, then send the command.

if you tune your sketch to the baud rate of the device for the serial terminal you should be able to use an additional wire and plug it from the TXD of the device into the RXD of the serial port you use for the debug output on arduino, thus if you are getting a message back error or otherwise it comes up straight onto the terminal.

however before i did any direct connection i would us a High impedance meter to check the signal level voltage (fair warning :slight_smile: ) if the TXD of the Device is true rs-232 the voltage should go positive and negative 12V a dso would be much better, its kinda my goto tool when hardware hacking.

that multidop machine is really cool... i could have used one of those back in the day ...

void setup() {[color=#222222][/color]
  Serial.begin(9600);[color=#222222][/color]
}[color=#222222][/color]
[color=#222222][/color]
void loop() {[color=#222222][/color]
    Serial.print("G");[color=#222222][/color]
    Serial.print("\n");[color=#222222][/color]
[color=#222222][/color]
    while(Serial.available() > 0) {[color=#222222][/color]
      byte reading = Serial.read();[color=#222222][/color]
      Serial.println(char(reading));[color=#222222][/color]
    }[color=#222222][/color]
    delay(15000);[color=#222222][/color]
}

id change it to

void setup() {
  Serial.begin(9600);
}

void loop() {
  long NonBlockingFlag
  if (NonBlockingFlag >= 20000) {
    Serial.print("G");
    Serial.print("\n");
    NonBlockingFlag = 0;
  }
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
  NonBlockingFlag++;
}

Hey,

I like how you're thinking, especially since getting a replacement cord is a week's wait on delivery.

The baud rate is 9600 both in the sketch and the instrument's requirements so the Tx <--> Rx wires should be good.

Do I need to wire the GND pins together too? Obviously the instrument is powered and grounded via it's own plug.

And, do you think it would be better to wire Tx of the Arduino to Rx of the instrument's serial port, or Tx of the DB9 port on the shield to Rx of the instrument's serial port? I know the shield generally protects the Arduino since it's more equipped for that voltage.

Big fan of the multidrop, definitely a time saver over manually pipetting to a whole plate! Hopefully will be even more of a time saver with the remote control. :slight_smile:

Thanks again!

Kate

yeah, i always forget that stupid ground, causes some pretty weird things to happen :slight_smile:

And, do you think it would be better to wire Tx of the Arduino to Rx of the instrument's serial port, or Tx of the DB9 port on the shield to Rx of the instrument's serial port?

depends on the tools and parts you have at your disposal, if you have a bunch of spare dupont wires, i would use those because they have the pin ends made onto them so carefully (operative word) remove the plastic shield from the dupont wire and pin it into the (assumption) female end on the device, to the female end of the db9 for now.

if this were mine, id verify my hardware.
use a DVOM to get a resistance reading of the cables internal wires
use a loop back wire on the TXD and RXD of the RS-232 shield to establish that the MAX232 (assumption) is functioning correctly
if you have those 2 things then the last thing to verify is that the cable you have makes the proper connections with the device and the only way to verify that is to direct wire a solution. does the rest of the datasheet have a pin out for the DB-25? because it may not be a standard wiring system, alot of Fishers stuff is proprietary so you have to buy it from them .

Breakout boxes for RS-232 are really cheap on Ebay and would really ease you debugging!

Paul

agreed, however depending on what part of the world you are in shipping is commonly a night mare. if this person plans on continuing to hack hardware then i would definately invest in some good tools and wigets, but if its a one time deal alot of times you can get by without them...

RS232 cables can be a nightmare as all the handshaking (RTS/DTR/CTS/DSR) that may or may not be needed or is needed by one side of the connection but not supported on the other side. On top of this the type of equipment your connecting to may need the RX/TX wire crossed or uncrossed.

I would suggest you start by confirming the cable is wired okay. As hardware handshaking is not needed by default (I assume your equipment is default) the minimum connections between the DB9 & DB25 connector need to be either
DB9 pin 2 - DB25 pin 3
DB9 pin 3 - DB25 pin 2
DB9 pin 5 - DB25 pin 7
or
DB9 pin 2 - DB25 pin 2
DB9 pin 3 - DB25 pin 3
DB9 pin 5 - DB25 pin 7

Start with just sending the N command as it should return a software version value. If your not getting a reply then try again with the alternate serial cable connection.
If this still fails then check your Serial shield by looping a wire between DB9 pins 2 & 3 and anything you send should be echoed back to your sketch. If this fails then it could be a dodgy sketch or RS232 shield hardware.

Thanks everyone for the input, much appreciated!

This is really a one-time ordeal, and unfortunately I need the project wrapped up next week so I'm trying very hard to avoid needed anything shipped.

I've just tried exactly what you suggested Riva, by wiring the pins 2 and 3 on the shield and sending commands through the serial monitor in a sketch with this code:

char rx_byte;

void setup() {
 Serial.begin(9600);
}

void loop() {
 if (Serial.available() > 0) {
   rx_byte = Serial.read();
   Serial.print("You sent: ");
   Serial.println(rx_byte);
 }
}

And absolutely no response popping up in the Serial monitor when I send single letters or numbers.

However, I thought that the shield was functional, since I used the sample code provided with the shield and it sent back "OK":

int led = 13;
void setup()
{
  Serial.begin(9600);
  pinMode(led,OUTPUT);
}
void loop()
{
  int temp;
  if(Serial.available())
  {
    temp=Serial.read();
     if(temp=='V'){
      digitalWrite(led,1-digitalRead(led));
    Serial.println("OK");
     }
  }
}

Seems so bizarre that that my feedback test loop was not functional while the provided test code worked. The only difference is that with my feedback test loop, the Tx and Rx (pins 2 and 3) are manually wired on the female serial DB9 port on the shield and the serial monitor is monitoring via the USB to the Arduino, while in the provided test loop the serial monitor is monitoring via the USB to the DB9 port on the shield.

Any ideas what's causing this communication block? :frowning:

All right, try this: solder two LEDs in parallel, the long leg on one to short leg on the other. Add a 1k resistor to one side and a length of wire to the other. Now you have an RS232 tester. One LED or the other will light when you connect one wire to ground and the other to the pin in question, if it is powered. If data is being sent you will see a LED blink. OR even if the pin changes you will see it.

Paul

You don't have the voltage level needed for that it's rs232c that's needs a 6 volt or higher swing you only have a 0 to 5 volt with this RS232 Shield For Arduino

Working voltage: +5V
• Transceiver indicating LED
• DB9 connectors (female), RS232 pins
• Weldable area
• Reset switch

you need a max 232 chip ±30-V Input Levels

lectronic equipment or module in the need to communicate with the world, often using serial communication mode, namely, by a series of binary coding data transmission. Based on SCM electronic equipment serial port is a big part of the use of the standard, it TTL level 1, level of logic is 5V 0V is logic 0 level, We used the PC serial use rs-five is 232C level standard, it is the logic 1 level 3V - - - the 12V, logic 0 level is + 3V ~ + 12 v. Because both level range far, and therefore must be in 232C rs-five and TTL circuit and logical relationship between the level of transformation, can in PC with this kind of electronic equipment serial communication between realization. Generally speaking, realize the transformation of the circuit can use division element, also can use MAX232 such integrated circuit chips.

krooney:
Any ideas what's causing this communication block? :frowning:

There seems to be a switch on the shield that switches between programming mode and RS232 mode. Once you have uploaded the sketch to the Arduino are you switching to the other mode?
You might need to hold the Arduino in reset mode to properly do a loopback test and to do this you put a patch wire between the Reset pin and a GND pin and then use the serial monitor to send/receive the replies.

be80be:
You don't have the voltage level needed for that it's rs232c that's needs a 6 volt or higher swing you only have a 0 to 5 volt with this RS232 Shield For Arduino
you need a max 232 chip ±30-V Input Levels

It looks like the shield has a MAX232 chip and the MAX232 chip can generate the required RS232 voltages from 5V with its charge pump and external capacitors.

The data sheet for that does not state that all that have a real max 232 chip clearly state they are in spec
That shield clearly states it 0 to 5 volt that will not work on anything that is truly rs232c

be80be:
The data sheet for that does not state that all that have a real max 232 chip clearly state they are in spec

That shield clearly states it 0 to 5 volt that will not work on anything that is truly rs232c

Sorry but I'm not understanding your first sentence very well. Are you referring to the datasheet for the MAX3232 chip used on the shield or some other datasheet?

The shield will only be supplied with 3.3V or 5V from an Arduino but the MAX3232 chip on the shield uses capacitors to pump the supply voltage up to the levels required for RS232.

First off I know how a max232 works the problem here is the datasheet for the shield being used doe not state its a max 232 it
said it only does 5 volts

Now and shield with a real max232 will brag about it and state it is fully able serial port.

I bet the posters is not giving the needed voltage levels.

be80be:
First off I know how a max232 works the problem here is the datasheet for the shield being used doe not state its a max 232 it
said it only does 5 volts

Now and shield with a real max232 will brag about it and state it is fully able serial port.

I bet the posters is not giving the needed voltage levels.

One of the picture shows an overhead view with an IC showing the MAX3232 identification. So the it will produce 8+- volts.

Paul