I actually have a bronkhost controller in which i want to control and read the data, like control its opening, control the flow rate
So, I sort of new to this stuff. I am using Arduino mega for this and below i have attached my wiring connections and my code to operate. So, if any one can guide me it will be very helpful
Thanks
my code :
#include <SoftwareSerial.h>
const int RX_PIN = 10;
const int TX_PIN = 11;
SoftwareSerial rs232Serial(RX_PIN, TX_PIN);
String setFlowCommand = ":09800101213E80\r\n";
void setup() {
Serial.begin(9600);
while (!Serial) { ; }
rs232Serial.begin(38400);
delay(500);
rs232Serial.print(setFlowCommand);
Serial.println(setFlowCommand);
}
void loop() {
if (rs232Serial.available()) {
String response = rs232Serial.readStringUntil('\n');
response.trim();
Serial.print("Received response: ");
Serial.println(response);
if (response.length() >= 6) {
String statusCode = response.substring(4, 6);
if (statusCode == "00") {
Serial.println("Setpoint update successful (flow rate set to 50%).");
} else {
Serial.print("Error in setting setpoint. Status code: ");
Serial.println(statusCode);
}
} else {
Serial.println("Response too short; unable to verify status.");
}
}
delay(1000);
}
Your diagram shows connections to pins 0 & 1 which is not advisable as they are used for the USB-Serial link. Which pins are really used?
38400 baud on a software serial port on an UNO is probably at the limit of reliable operation. If you are able to reconfigure the serial port baud rate to a lower value - such as 9600 baud - then you will stand a much better chance of success.
Note that the use of the String class may work initially, but it's not really designed for use on a micro with limited memory and projects using the String class on an UNO tend to stop working after a few hours.
Please can you edit your post to place your code between code tags as it makes it more readable.
#include <SoftwareSerial.h>
const int RX_PIN = 10;
const int TX_PIN = 11;
SoftwareSerial rs232Serial(RX_PIN, TX_PIN);
String setFlowCommand = ":09800101213E80\r\n";
void setup() {
Serial.begin(9600);
while (!Serial) { ; }
rs232Serial.begin(38400);
delay(500);
rs232Serial.print(setFlowCommand);
Serial.print("Sent command to set flow rate to 50%: ");
Serial.println(setFlowCommand);
}
void loop() {
if (rs232Serial.available()) {
String response = rs232Serial.readStringUntil('\n');
response.trim();
Serial.print("Received response: ");
Serial.println(response);
if (response.length() >= 6) {
String statusCode = response.substring(4, 6);
if (statusCode == "00") {
Serial.println("Setpoint update successful (flow rate set to 50%).");
} else {
Serial.print("Error in setting setpoint. Status code: ");
Serial.println(statusCode);
}
} else {
Serial.println("Response too short; unable to verify status.");
}
}
delay(1000);
}
I am actually using pin 10 and 11 in mega and not uno
For baud rate i actually referred the manual and they sort of mentioned 38400
i will attach the link for the manual below for Ur reference
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwjGu8LU27OMAxWKQEEAHUqqMQAQFnoECAoQAQ&url=https%3A%2F%2Fwww.bronkhorst.com%2Fgetmedia%2F77a1438f-e547-4a79-95ad-53e81fd38a97%2F917027-Manual-RS232-interface&usg=AOvVaw1iYTDsBSROwxqqilOQ-ngR&opi=89978449
So this is my idea, but if you can suggest another to start with better success rate , it would much better
By mega, do you mean a MEGA2560 board?
You don't need to use a software serial port as your board has 4 hardware serial ports. Use TxD1 and RxD1 which are associated with Serial1 and connect to those pins.
ok. What about my connections and my coding part
Which RS232 converter are you using. It's unusual to power one from 2 different power sources at the same time.
Replace all your software serial port references to rs232Serial with Serial1 - assuming you choose to connect to TxD1 and RxD1.
Do you have any documentation for the device you are trying to communicate with? What does it say about serial comms.
I would initially make the code inside loop much smaller - simply print out each char/byte as it becomes available rather than waiting for a complete message, just to see what comes back.
The above is the link for communication related details of the mass flow controller
So now how should i change the code for initial time
A couple of things.
The document suggests that there is a binary protocol and an ASCII protocol - which one is your device configured for?
More importantly, which pins did you connect the 15v supply to on the 9-pin d-connector? It's possible that the RS232 module got fried as there shouldn't be a need for power to be supplied that way.
I am actually using the ACSII protocol for this purpose ,
The RS232 section of the drawing doesn't have a power source going to the d connector. It has a ground connection on pin 5 and an overall shield connection, but no +15v.
15v i am giving separately
from outsource , for rs232 power source i am giving form Arduino 5volt
As I said before, there is no +V power connection to the RS232 connector:
There's a ground on pin 5.
Can you provide a clearer picture of this connector:
It doesn't appear to tie in with the connections on the RS232 com port in the manufacturers image above.
Actually i have another doubt there are 3 out from max3232(rs232 to ttl) tx,rx,gnd and in addition i have +ve and -ve from the power source. so according to the above hook up diagram where to give the connections there is only one 0v powe , but for max3232 out gnd where to connect . Should i connect it with the 0V power line