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 <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 that the company provide and the Setup picture is attached in the picture form.
If someone amend my code or tell where i am doing some error, i shall be very thankful to you.
{gallery}My Gallery Title |
---|
Pyhton Code |
My setup prototype |
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
REPLACE THIS TEXT WITH YOUR IMAGE IMAGE TITLE: THEN IMAGE DESCRIPTION |
Top Comments