EmbeddedRelated.com
Forums
Imagine Conference

PHD ULTRA syringe Pump integrate with Arduino

Started by Zainiii 8 months ago15 replieslatest reply 6 months ago172 views

I have a PHD ULTRA syringe pump from Harvard Apparatus. I want to establish communication between an Arduino and the syringe pump. The company provided me with a Python code, but Arduino does not support Python. Therefore, I converted this code to C++ to make it compatible with the Arduino. I am using an RS-232 to TTL converter between the Arduino and the syringe pump.

However, when I attempted to use this code to establish communication, I encountered issues. Could someone please help me amend this code if there are any errors? I have attached a diagram of my setup and will also attach the Python code provided by the company.

Note: The syringe pump successfully responds and turns ON and OFF when using the pump terminal software provided by the company.

The C++ Code is:

#include
// Define the pins for RX and TX
#define RX_PIN 2
#define TX_PIN 3
SoftwareSerial pumpSerial(RX_PIN, TX_PIN);

void setup() {
// Initialize hardware serial for debugging
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect }
// Initialize software serial for pump communication
pumpSerial.begin(9600);
Serial.println("Arduino ready to communicate with syringe pump.");
}

void loop() {
// Command to send
String command = "run\r\n";
// Send the command
Serial.print("Sending command: ");
Serial.print(command);
pumpSerial.print(command);
// Wait for 1 second
delay(1000);
// Read and print the response
String response = "";
while (pumpSerial.available() > 0) {
char inChar = (char)pumpSerial.read();
response += inChar;
}

// Print the response if not empty
if (response != "") {
Serial.print("Response received: ");
Serial.println(response);
}
else {
Serial.println("No response received.");
}
// Wait before sending the next command (adjust as needed)
delay(5000); }

The python code that the company provide is attach in the post
Python serial snippet.txt
The picture of the setup is attached as well:

Can someone amend this code so that Arduino can integrate with the Syringe pump.
Your hgelp will be highly apreciated, Thanks inadvance


syringe protocol_94962.png


[ - ]
Reply by tcfkatAugust 1, 2024

Hello!

First, check your lowest level of communication, the hardware and its wiring. Is your converter board powered and sends correct RS232 levels to the pump? Did you confuse transmit and receive lines on either TTL or RS232 side? Use an oscilloscope.

Then, check your serial parameters. In the Python sample, odd parity and rather unusual 7 data bits and 2 stop bits are used. Where do you set these communication parameters in your sketch?

[ - ]
Reply by ZainiiiAugust 9, 2024

Dear Sir sorry for late reply.
There was some problem in my Arduino code, i made it correct and now my code is 

#define pumpSerial Serial1

void setup() {

  Serial.begin(9600);

  pumpSerial.begin (9600, SERIAL_7O2);

  Serial.println("Arduino ready to communicate with syringe pump.");

  pumpSerial.print("run\r\n");

  delay(1000);

}

void loop() {

 static char Line[30];

  if (pumpSerial.available() > 0) {

    pumpSerial.readString().toCharArray(Line, 29);

    Serial.print(Line);

  }

  if (Serial.available() > 0) {

    Serial.readString().toCharArray(Line, 29);

    pumpSerial.print(Line);

  }

  // Wait before sending the next command (adjust as needed)

  delay(5000);

}

But it satill not working with arduino. I test the syringe pump working using the pump terminal software and its working fine



[ - ]
Reply by aleciaemileSeptember 16, 2024

@tcfkat is right!

[ - ]
Reply by matthewbarrAugust 1, 2024

Hello Zainiii, I agree with tcfkat and was going to make similar suggestions. In particular, checking the RS232 serial lines with a scope is a very good idea. As tcfkat mentioned, I don't see in your C++ code where the serial character format (data/parity/stop bits, typically 8/none/1 but 7/odd/2 in Python code) is configured.

If you have access to a USB serial adapter you can connect it to the TX and RX pins (and GND of course) on your RS232 TO TTL converter. From there you should be able use a terminal emulator (TeraTerm, PuTTy, Minicom, Terminal by br@y) to set baud rate and character format. Then you can send commands from a keyboard and see responses.

That will confirm that communication is good through your RS232 converter and you can then focus on debugging your Arduino program. Make sure it is sending the right characters at the right baud rate to the right pin on the converter.

A USB serial adapter coupled with a good terminal emulator is absolutely one of the most useful debug tools in the embedded world. As a sanity check you can loop TX back to RX on the USB serial adapter to make sure you see what you type in the terminal emulator.

[ - ]
Reply by tcfkatAugust 5, 2024

Hello Matthew,


very good advices!

Sadly, these newbies in the forum rarely leave any feedback ...


Best regards,

Eric

[ - ]
Reply by matthewbarrAugust 5, 2024

Ditto Eric! Yes indeed, this happens pretty frequently and I can imagine several reasons for it.

Based on the original post any number of things could be wrong outside of the C++ code. We have no idea what the poster has and has not checked.

They mentioned using "pump terminal software" provided by the manufacturer, but we don't know how that connects to the pump. It could cabled directly to the serial port from a desktop PC, or it could be a USB connection. In either case, that doesn't rule out a problem related to the RS-232 adapter such as not having eg. +/-5V to drive/receive RS-232 levels.

Best,

Matt

[ - ]
Reply by ZainiiiAugust 9, 2024

Dear Sir
Your questions are very genuine.
Previously when i used the Cable to connect Laptop with syringe pump, using cable having one side RS 232 DB9 port and other side is USB Type A, the software didn't detect the syringe pump its not detecting, then i putt a null modem Infront of cable DB9 side and then connect with the pump, now the pump terminal software turn ON and OFF the pump using this cable, but previously this procedure was not working without null modem usage 
Now the problem lies totally in code , i used the same baud rate in syringe pump and in Arduino code, but its still not working.
the code is attached below and the company said, we don't support the Arduino.

#define pumpSerial Serial1

void setup() {

  Serial.begin(9600);

  pumpSerial.begin (9600, SERIAL_7O2);

  Serial.println("Arduino ready to communicate with syringe pump.");

  pumpSerial.print("run\r\n");

  delay(1000);

}

void loop() {

 static char Line[30];

  if (pumpSerial.available() > 0) {

    pumpSerial.readString().toCharArray(Line, 29);

    Serial.print(Line);

  }

  if (Serial.available() > 0) {

    Serial.readString().toCharArray(Line, 29);

    pumpSerial.print(Line);

  }

  // Wait before sending the next command (adjust as needed)

  delay(5000);

}

[ - ]
Reply by ZainiiiAugust 9, 2024

I have attached my reply in the precious comment. I set the same baud rate on both Arduino and syringe pump.
make changes in the code, but its still not working, but now its working fine with pump terminal software that the company provides me

[ - ]
Reply by matthewbarrAugust 10, 2024

Hi Zainiii, you mentioned that the pump terminal software works with a USB-to-RS-232 conversion cable plus null modem adapter, driven from a USB port on your laptop.

My understanding is that the Arduino sends what you call TTL level signals to an RS-232 adapter. I assume these are single-ended 3.3V LVTTL levels, TX out, RX in and GND.

I can think of a number of things that might be wrong outside of the Arduino software, and would check these things first:

  • Do you see LVTTL level serial data from the Arduino TX out pin to the adapter?
  • Do you see RS-232 level serial data from the adapter TX out pin to the pump?
  • Have you tried using the null modem adapter with the RS-232 adapter?

That first question is key. If you don't see the LVTTL TX output from the Arduino wiggling, you need to make sure you've got the device configured correctly, UART enabled with TX, RX and control lines mapped to the right I/O pins on the Arduino device.

Next steps would depend on the answers to those two questions. The RS-232 adapter needs to drive RS-232 signal levels, at least +/- 5V. If the adapter doesn't have on-board DC-DC RS-232 voltage generation, you'll need to supply the appropriate power supply voltages.

In addition to TX and RX data, RS-232 interfaces carry traditional modem control lines. Even though there is no modem involved, serial port handlers sometimes want to see an active level on a modem control input (CTS, DCD) in order to know there is an external device attached. Your USB conversion cable and provided pump terminal software may be handling this automatically. If so, you can provide this by pulling the appropriate modem control input on your RS-232 adapter up or down as required.

Good luck!

[ - ]
Reply by tcfkatAugust 15, 2024

Hello Matthew,

to quote: "Next steps would depend on the answers to those two questions. The RS-232 adapter needs to drive RS-232 signal levels, at least +/- 5V. If the adapter doesn't have on-board DC-DC RS-232 voltage generation, you'll need to supply the appropriate power supply voltages."

In either way, the TTL to RS232 adapter needs to be powered. Just connecting RX/TX as in the "schematic" above will not work ... as long as no real circuit diagram was shown ...

[ - ]
Reply by sima_79August 16, 2024

Hello,
Besides what Matthew suggests. There is also the possibility to use a rs232 sniffer software. e.g. hdd serial port monitor or similiar, when using the pump terminal software and check how that software is communicating.
/Martin


[ - ]
Reply by fighneAugust 2, 2024

the problem apprears that you are not send the text string "Sending command: " followed by the command you want the unit to complete. Do you have the manual for this equipment? 

[ - ]
Reply by mikethewireAugust 2, 2024

Is it not

"pumpSerial.print(command);"  ?

[ - ]
Reply by ZainiiiAugust 9, 2024

Dear Sir
Sorry for late reply.
My code was not correct at that time, now i have amended the code, can you look for that and if you find some problem can you rectify it. i believe the code is fine but it still not working.

[ - ]
Reply by ZainiiiAugust 9, 2024

can you check the amended code that i attached in the previous comment reply, if you suggest me some changes, it would be highly appreciated Sir,
The manual link of the pump is attached in the comment Sir.
https://www.harvardapparatus.com/media/manuals/Pro...

Imagine Conference