I am using RS232 female port to the machine who gives me 5 readings as output , I have connected Tx port to 12th pin of arduino uno and Rx port to 13th port of arduino uno and add GND connection
I have received the Output HEX format by - Serial2.print(Serial1.read(),HEX); line and output is like -
80 00 80 00 78 00 78 80 78 80 00 80 00 80 F8 00 80 80 78 00...... and so on,
I need the readings which is shown on the screen of that machine which are : 4.5, 0.01,100.0 etc
also if i change this - Serial2.print(Serial1.read(),HEX); and convert in char() still the output is -
??////////??//?????*///////
please help me to get it done with axact output showing on screen
I set the baud-rate 9600 for the first time and got the data which is in HEX format after that i have tried and test with different baud-rate below 9600 it gives me the data which was not in proper format and if i have set baud-rate above 21000 then data shows only 00000000000000000 or null(no data),
I need the output as readings shown in that machine display
I assume that you realise that both ends of the serial link need to be set to use the same baud rate - Yes
I have received data with HEX :
78
80
0
80
0
80
0
...... So on
and Without HEX - 01921200128012802481280128012801280128012801280128012..... So on
Readings are shown in machines are - FAT - 0.04, SNF - 0.0, Density - 0.00, Added Water - 100, protien - 0.00
Please post your sketch, using < CODE/ > tags when you do
Do you have a data sheet for the machine that is sending the data and does it describe the format of the data that it outputs ? What machine is it ? Link ?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
void setup()
{
Serial.begin(9600); // open serial port for debugging
mySerial.begin(9600); // open software serial port for RS232 device
}
void loop()
{
if (mySerial.available())
{
Serial.println(mySerial.read()); // read data from RS232 device and output to serial monitor
}
}
MOD edit - added code tags
this is milk analyser machine showing the readings as data i need to just decode it when i received it in arduino uno
I have check with your code and the output is -
128128120128120120012001280128248128128012801280128012801280128012801280128120128120128120...... and so on
Is the analyser set up to print data or to pass it to the Milk Data 2001 software on the PC ?
yes its set up to print the data there is one app which is used to take the data from serial port with wired connection
its generic printer this machine is also supported for mairy dairy app
i have try the -
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
void setup()
{
Serial.begin(2400); // open serial port for debugging
mySerial.begin(2400); // open software serial port for RS232 device
}
void loop()
{
if(mySerial.available()>0){
Serial.print((char)mySerial.read());
}
}
---------- and the output is redundant-
(00300000000099990000000010029)(00300000000099990000000010029)(00300000000099990000000010029)(00300000000099990000000010029)
Assuming that it prints correctly when you use the printer, what baud rate is the printer set to ?
I note that once again you did not use code tags when posting your sketch. Please edit the post, select the sketch and click on < CODE/ > above the edit window to add the code tags before saving your post
I have set the baud-rate 2400 and my code is below:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
void setup()
{
Serial.begin(2400); // open serial port for debugging
mySerial.begin(2400); // open software serial port for RS232 device
}
void loop() {
if (mySerial.available()) { // Check if there is data available
String data = mySerial.readStringUntil('\n'); // Read the data until a newline character is encountered
String temp = ""; // Temporary variable to store the digits
int count = 0; // Counter to keep track of the number of digits read
for (int i = 0; i < data.length(); i++) {
char c = data.charAt(i);
if (isdigit(c)) { // Check if the character is a digit
temp += c; // Add the digit to the temporary variable
count++; // Increment the counter
if (count == 5) { // If we have read 5 digits, it means we have a complete value
float value = temp.toFloat()*100 / 100.0; // Convert the string to a floating-point value and divide by 100 to get the actual value
Serial.print(value, 2); // Print the value with 2 decimal places
if (i < data.length() - 1) { // If this is not the last value, print a comma
Serial.print(", ");
}
temp = ""; // Reset the temporary variable
count = 0; // Reset the counter
}
}
}
Serial.println(); // Print a newline character at the end of the line
}
}
showing the output which is quite similar but still its showing all reading as 0.00
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
Simplifying things, but if you use your code from post #11 with the baud rate set to 2400, do you see anything that looks like the expected output being displayed?