PHD ULTRA syringe Pump with Arduino

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.

#include <SoftwareSerial.h>

// 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 is also attached below

t# Assuming that PySerial is installed:

import serial
import time

# Configure serial connection
ser = serial.Serial(
    port='COM1',
    baudrate=9600,
    parity=serial.PARITY_ODD,
    stopbits=serial.STOPBITS_TWO,
    bytesize=serial.SEVENBITS
)

ser.isOpen()

input = 'run'
out = ''

# Send the input to the device
# Note the carriage return and line feed characters \r\n will depend on the device
ser.write(input + '\r\n')

# Wait 1 sec before reading output
time.sleep(1)
while ser.inWaiting() > 0:
    out += ser.read(1)

# Print the response
if out != '':
    print out

in arduino code you have this not

You did not tell us the type of PC you used with the Python code. What issues did you encounter? If the device works with the PC Python code, it may work with the Arduino code. If it didn't work, the whole project is more difficult because of the chance the pump has a problem. So get the Python code working, first!

Dear Sir.
Can you amend the Arduino code. please

Dear Sir.
This syringe pump only work and operate with the software that the company provides, the commands are very simple, i just write on the software and it start running. That commands are not Python command, they are simple command i get from the user manual.
I didn't test with the python code, because i didn't have raspberry Pi.
I just convert this python code to Arduino to make it compatible with the Arduino

SoftSer does not support this.
use Micro Pro, Leonardo or Mega.
then use:

Serial1.begin(9600, SERIAL_7O2);

Thanks Sir, any other change, that i should do in the Arduino code

i don't know, python script is not complete, or better to say erroneous


This is the complete python code in picture

did you noticed? this script will end and stop in 1 second

better buy "USB-to-TTL converter" or "RS232 to USB converter" and use python on PC without complication with arduino

Yes, i understand it stop after 1 second because of this command
time.sleep(1)

no, this command is wait, not stop. stop is when script ends and return to OS.
so this script without waiting will shut down immediately after start

Actually Sir, i have automated other work using the Arduino. The only thing that is remaining is Syringe pump controlling, If it will automate, then everything will be fine.
If i control it using the software provided by the company, then i cannot automate the whole setup.
One one side: Arduino will work for whole system and the second side, we have to provide the command to the software for running the syringe pump. Then there would not be the an automated system
That is the main problem sir

If i change the Arduino, there is chance of solving the error or not, Like Arduino UNO to Arduino Mega

not Uno, not Nano.

Someone work on this project, but i cannot understand, how he worked.
the link is attached

Understand, i will buy them as well

#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);
}
1 Like

Thank you so much Sir, i buy the Arduino Mega and then try to upload.
After that i will surely let you know

Dear Sir.
When i uploaded the program it gave the error.

  1. String object to a char array, which is not compatible. So i changed the program to.
  2. Then i do changes in the code.
    the code is attached below.
#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) {
    String inputString = pumpSerial.readString();
    inputString.toCharArray(Line, 30);
    Serial.print(Line);
  }

  if (Serial.available() > 0) {
    String inputString = Serial.readString();
    inputString.toCharArray(Line, 30);
    pumpSerial.print(Line);
  }

  // Wait before sending the next command (adjust as needed)
  delay(5000);
}

The program is still not working.
You help is required in this case