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);
}
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
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.
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
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
Dear Sir.
When i uploaded the program it gave the error.
String object to a char array, which is not compatible. So i changed the program to.
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