Hi. My goal is to extract a number out of a line of data from a serial device.
I have a device's rs232 connected to a rs232 to TTL converter and then to my Arduino mega. Using this IDE example code I connect to the device and I can see the device sending the data on the IDE comm terminal.
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(19200);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
The input from the serial device looks like this on my serial comm terminal. It's a constant feed from the serial device.
2020/07/20 14:12:28 0 D 141.57 Ft
2020/07/20 14:12:29 0 D 141.57 Ft
2020/07/20 14:12:31 0 D 141.57 Ft
...etc
What I want to do is extract the last number (currently 141.57) so I can send it out to a spreadsheet on my PC.
I've tried making inByte into an array using int inByte[] = {Serial1.read()};
And then Serial.write(inByte[1]);
to see if anything is getting stored in the array but I get nothing.
Can you please point me in the right direction for getting that number? ![]()
Thanks.