Sending ASCII strings to RS232 device Revisited

Hi,

I'm having the same/similar type of issues that @jockwr was having back in 2017. I didn't find the resolution in the now closed thread so I'm reposting the topic with my conditions as well as the link to the jockwr's post. Also I’m using a similar format because I thought they framed the problem quite well. I've tried everything jockwr stated they did and everything suggested to them in the thread. (I do not have the same thermal condition that jockwr experienced with their transceiver)

It seems like I'm missing some small detail here or some bit of knowledge.
(This is my first Arduino project in more than 10 years so im a bit rusty too)
I've included my sketch at the end.

Sending ASCII strings to RS232 device - Using Arduino / Programming Questions - Arduino Forum

I have a Syringe Pump, it responds to text/string commands.

The device can communicate using it's RS232 DB9 cable
baud: 9600
Bits: 8
Parity: None
Stop bits: 1
Flow Control: None

I'm using the following hardware:
An Uno with a TinySine RS232/RS485 Shield (SP3232E chip from Max Linear)

Prior to trying to use the Arduino to communicate with the Pump I did a check with HyperTerminal in two ways. (Using the RS232 com port native to the laptop and with a USB to RS232 serial converter.)

I've configured HyperTerminal to the following Parameters and ASCII settings enabled:

Baud: 9600
DataBits: 8
Pairity: None
StopBits: 1
FlowControl: None
✓ Send line ends with line feeds.
✓ Echo typed characters locally.
✓ Append line feeds to incoming line ends.
✓ Wrap lines that exceed terminal width.

When I use HyperTerminal to send the command "/1" (to make a communications check for example). The pump does respond with "/0' " (Which is the desired response)

Furthermore, any properly formatted command that I issue via HyperTerminal works and can control the pump. (With the native com port or the USB to serial converter)

Before I try and send any commands from the Arduino to the pump, I wanted to make sure I have Arduino doing this correctly by sending commands from Arduino to HyperTerminal. For this I just used the DB9 cable from the native com port to the TinySine shield and am sending ASCII stings through the serial monitor and the HyperTerminal communication window. It was a success! We can send strings back and forth all day long now.

The next phase was to have Arduino send a command to the pump and get a response on the serial monitor window. (This didn’t work ..just silence)
Next I tried sending a command in which a response on the serial monitor didn’t matter because we would see a physical reaction of the pump. I used “/1W4R” (which is the initialization command when you replace the syringe). This also did nothing.

Additionally, I visually monitored the TX and RX LEDs on the Arduino board. I can see that the commands are transmitting but nothing on the receiving end.

The Conections are as follows:

  1. PC com6 USB port to USB port on arduino (via USB cable)
  2. Arduino SoftwareSerial to RS232 shield (Pins 2 & 3)
  3. RS232 shield to Pump RS232 com port (via DB9 cable)
    Note: This is the same setup used for communicating from Arduino to HyperTerminal with the exception of condition 3 (the other end of the DB9 cable is plugged into the native 232 com port on the laptop instead of on the Pump)

Any help will be greatly appreciated.

And here is the sketch I was using for both communication with HyperTerminal and with the Pump:

// ---------------------------------------------------------------------------------------------------------------
// Interfacing Arduino(TinySine RS232/RS485 Shield) and Kloehn Syringe Pump.
// ---------------------------------------------------------------------------------------------------------------

#include <SoftwareSerial.h>

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

// SETUP------------------------------------------------------------------------------------------------------
void setup() // Runs once.
{
  Serial.begin(9600); // Open serial communications with IDE Serial Monitor at 9000 baud (Through pin0 and pin1 or UBS port)
  Pump.begin(9600);   // Opens comm port through pins 2 & 3 (RS232 Shield) 9600 baud
  while (!Serial) {}  // Wait for serial port to connect (Needed for native USB port only)
  delay(50);
  Serial.println("Arduino is online!"); // Test: (Text displayed in Serial Monitor)
  delay(1000);
  Serial.println("Checking pump status...");
  Pump.println("/1");  // Test: Is Pump communicating with the Arduino? ( /0' )
  while (Pump.available()){              
  Serial.println(Pump.readString());
} 
 
}
//END SETUP-----------------------------------------------------------------------


// LOOP-------------------------------------------------------------------------------
void loop()  // run over and over
{
while (Pump.available()){              
  Serial.println(Pump.readString());   // Read message from Pump and print line to IDE Serial Monitor.
}
while (Serial.available()){             
  Pump.println(Serial.readString());   // Read message from IDE Serial Monitor and print line to Pump.
}

} 
// END OF LOOP---------------------------------------------------------------------

It may be necessary to swap the TX and RX connections between the arduino and the pump.

can you connect the tx/rx pins on your rs-232 interface and see if any output is echoed back?

not sure if this is possible with SoftwareSerial. it might be easier if you could use the SoftwareSerial port for status and the Hardware Serial port (pins 0&1) for trasnmission

are you suggesting a null-model adaptor or cable

Basically yes, although all you need is pins 2, 3, and 5 (TX/RX and GND), the other wires are used for hardware flow control.

I tried swapping pins 2 and 3 in my sketch but only interesting thing to happen was that the RX LED on the shield flashed when I tried sending a command to the pump.

On reading your reply I was initially thinking of sourcing a different DB9 cable with a crossover but then if that was in fact the issue, I would think that when I connected Arduino with HyperTerminal using the same cable, I should have experienced a communication problem at that time.

Also here is an excerpt from the pump manual:

pump serial connection

I removed the end of the DB9 cable from then pump and placed a jumper wire across pins 2 and 3 of the plug and got the following results on sending a command:
Both TX and RX LEDs flashed on the shield but I didn't get my "message" echoed back to me the serial monitor like I'd expected.

That will not work, that only makes the connection between the arduino and the shield wrong.

Loopback test will not work with SoftwareSerial, drawback of the library is that it cannot send and receive simultaneously.

The shield schematic shows pin 2 as TX and pin 3 as RX, so the opposite of the PC serial port.

Please correct me if I'm wrong here, from the reading I've done the TX and RX of the USB port on the Uno board is directly connected to RX and TX pins 0 and 1 and if I were to try to use the hardware serial communicate through the shield to the pump, that I would not be able to also monitor/send commands to the system with the IDE Serial Monitor because they're in conflict.

  • Additionally, is the only way to use the IDE Serial Monitor through the USB port connector on the Uno board?

  • Or would I need to use a Mega board or two of the TinySine shields to make my SoftwareSerial connection to HyperTerminal

  • Or better yet is there a practical solution that I can implement with the hardware I currently have?
    (I think what I'm really asking in this last point is what other way would you use the Software Serial for displaying the status and does this assume that all commands are pre-contained within the sketch and be called to be sent to the pump by turning a pin high or low instead of inputting them on demand from the serial monitor or hyperterminal?)

In the following test I was running the same sketch that I previously posted. Initially, I had the Arduino connected to the PC via the USB cable and the Pump connected to the shield via the DB9 cable.

Procedure:
I removed the DB9 cable from the RS232 shield and place the following jumpers:

  • Cable pin 5 to Shield pin 5
  • Cable pin 3 to Shield pin 2
  • Cable pin 2 to Shield pin 3

Results: No change.

  • Not getting a response from Pump when sending a "/1" command (com check)
  • Not getting a reaction from Pump when sending a "/1W4R" command (initialization)
  • Tx LED on shield blinks on sending command
  • Rx LED remains off

Doubt it will work, but try this code, just in case the pump has a problem with carriage return.

#include <SoftwareSerial.h>

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

// SETUP------------------------------------------------------------------------------------------------------
void setup(){
  Serial.begin(9600);
  Pump.begin(9600);
  while (!Serial) {}  // Wait for serial port to connect (Needed for native USB port only)
  delay(50);
  Serial.println("Arduino is online!");
  delay(1000);
  Serial.println("Checking pump status...");
  Pump.print("/1\n");
}

void loop(){
  while (Pump.available()) {
    Serial.write(Pump.read());
  }
  while (Serial.available()) {
    Pump.write(Serial.read());
  }
}

have you a USB-RS232 dongle you could use with a PC to test the communications of the pump and the Arduino?

I tried your code with the jumpers in (swapping DB9 pins 2 and 3) and without the jumpers. Unfortunately, it didn't solve the problem. Still getting the Tx LED blinking on sending a command and not getting anything back on the Rx LED.

Can't think of anything else here. Jumpers not making good contact would be a remote possibility.

I do. I was initially testing the pump with HyperTerminal via the native com ports on my laptop as well as USB to RS232 Converter (Dongle) before adding Arduino into the mix.
I was able to connect to the pump and send commands via com1, com2 or com8 (Prolific USB to Serial Comm Port)

Are you thinking that there is a way to use HyperTerminal to relay the message like a proxy?
IDE SerialMonitor -> Arduino ->RS232 Shield -> Laptop com1 HyperTerminal -> Out laptop com2 or USB to serial Dongle ->Pump ?

Though I enjoy the idea of just getting this to communicate with the pump in anyway in the name of progress, the final implementation won't be using a laptop to send commands. It will be to preprogram a set of string commands into the Arduino and call them as needed via tactile switches or other external devices connected to digital pins.

Well for the sake of honesty (and humor) I wasn't thinking that there would be such a quick and steady response from the community today, and I don't have all my tinkering supplies at hand, so I improvised my jumpers with twist-ties stripped on the ends and folded over and slipped in the female socket ends.
Kind of quick and dirty but they definitely have good contact in there with the ends folded over.

The DE-9 TX pin should be a negative voltage when it's not sending anything.

If you send a long string of data, "UUUUUUUUUUUUUUUUUUUU", that will make the DE-9 TX pin go positive (when it's sending zeroes).

Modify your sketch loop that so that you can get in there with a voltmeter and see what's going on.
(Send U's, delay(1000); repeat.)

Some RS232 devices will require other signals (notably DTR) to recognize a connection (yes, even with "flow control" turned off.) Such signals are likely to be provided by a PC rs232 port, but NOT by the TTL/RS232 adapter connected to an Arduino.

The usual solution is to hack the DE9 connector at the device to "loop back" the DTR signal to the DSR signal with a jumper between pins 6 and 4. (although from your diagram, it looks like the pump doesn't have an actual DE9 port, so... maybe not?)

at least you know the pump RS232 communication is working
I would recommend you move to an Arduino with hardware Serial ports, e.g. Mega
for example of Mega to RS232 shield connection see serial-communication-rs232
with hardware ports you can do a loopback test by shorting pins 2 and 3 on the 9 pin D type connector - characters transmitted are echoed back to the receiver - at least proves your basic hardware/software is operational

when no data is being transferred pins 2 and 3 should be around -9 to -12 volts

I modified the original diagram from the pump manual to depict the current jumper configuration for testing given the suggestions.

pump serial connection with jumpers

Testing the above setup yields no new developments unfortunately.
(I've tried this both with and without the crossover.)