Hi I’m currently trying to use Arduino to perform serial communication with my Korad Power Supply. I have the code below and all I got was just:
10:28:42.744 -> Sent command: VSET1:5.00 10:28:43.730 -> No response from power supply.
My Arduino was connected to Korad Power Supply with a RS232 TTL Module.enter image description here
I was wondering what could be wrong.
Here is my code:
[enter image description here](https://i.sstatic.net/82wbsvLT.jpg)
<code>#include <SoftwareSerial.h>
#define RX_PIN 10 // RX pin for SoftwareSerial
#define TX_PIN 11 // TX pin for SoftwareSerial
#define TEST_COMMAND "VSET1:5.00" // Test command without line endings
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Create a SoftwareSerial object
void setup() {
Serial.begin(9600); // Initialize hardware serial for debugging
mySerial.begin(9600); // Initialize SoftwareSerial
delay(1000); // Brief delay to ensure everything is ready
// Send a test command
sendTestCommand();
}
void loop() {
// Send the test command periodically
sendTestCommand();
delay(5000); // Wait 5 seconds before sending again
}
void sendTestCommand() {
// Send the command without adding any line endings
mySerial.print(TEST_COMMAND);
Serial.println("Sent command: " + String(TEST_COMMAND));
// Read and display any response
unsigned long startTime = millis();
bool responseReceived = false;
while (millis() - startTime < 1000) { // Wait up to 1 second for response
if (mySerial.available() > 0) {
String response = mySerial.readStringUntil('r');
Serial.println("Power Supply Response: " + response);
responseReceived = true;
}
}
if (!responseReceived) {
Serial.println("No response from power supply.");
}
}
</code>
<code>#include <SoftwareSerial.h>
#define RX_PIN 10 // RX pin for SoftwareSerial
#define TX_PIN 11 // TX pin for SoftwareSerial
#define TEST_COMMAND "VSET1:5.00" // Test command without line endings
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Create a SoftwareSerial object
void setup() {
Serial.begin(9600); // Initialize hardware serial for debugging
mySerial.begin(9600); // Initialize SoftwareSerial
delay(1000); // Brief delay to ensure everything is ready
// Send a test command
sendTestCommand();
}
void loop() {
// Send the test command periodically
sendTestCommand();
delay(5000); // Wait 5 seconds before sending again
}
void sendTestCommand() {
// Send the command without adding any line endings
mySerial.print(TEST_COMMAND);
Serial.println("Sent command: " + String(TEST_COMMAND));
// Read and display any response
unsigned long startTime = millis();
bool responseReceived = false;
while (millis() - startTime < 1000) { // Wait up to 1 second for response
if (mySerial.available() > 0) {
String response = mySerial.readStringUntil('r');
Serial.println("Power Supply Response: " + response);
responseReceived = true;
}
}
if (!responseReceived) {
Serial.println("No response from power supply.");
}
}
</code>
#include <SoftwareSerial.h>
#define RX_PIN 10 // RX pin for SoftwareSerial
#define TX_PIN 11 // TX pin for SoftwareSerial
#define TEST_COMMAND "VSET1:5.00" // Test command without line endings
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Create a SoftwareSerial object
void setup() {
Serial.begin(9600); // Initialize hardware serial for debugging
mySerial.begin(9600); // Initialize SoftwareSerial
delay(1000); // Brief delay to ensure everything is ready
// Send a test command
sendTestCommand();
}
void loop() {
// Send the test command periodically
sendTestCommand();
delay(5000); // Wait 5 seconds before sending again
}
void sendTestCommand() {
// Send the command without adding any line endings
mySerial.print(TEST_COMMAND);
Serial.println("Sent command: " + String(TEST_COMMAND));
// Read and display any response
unsigned long startTime = millis();
bool responseReceived = false;
while (millis() - startTime < 1000) { // Wait up to 1 second for response
if (mySerial.available() > 0) {
String response = mySerial.readStringUntil('r');
Serial.println("Power Supply Response: " + response);
responseReceived = true;
}
}
if (!responseReceived) {
Serial.println("No response from power supply.");
}
}
New contributor
Ivy Meshle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.