Hello and thank you in advance for any help. I have an application which reads speed, rpm and gear values from BeamNG Drive and Serial prints them to a COM Port. It works in a loop, separating the values using end bytes.
RPM_END_BYTE = '+';
SPEED_END_BYTE = '=';
GEAR_END_BYTE = '!';
Using these end bytes, I'm wondering how to, in arduino, split the input into three strings. I can either have them directly into an integer or use string.toInt();
to convert it. This is what one loop of the program's serial output looks like :
02500+120=6!
I have set up a virtual COM port on my PC to check that the software works and it does, however I can't seem to figure out how to split the input up.
I have also used the following code, which works when i input numbers through the Serial Monitor and end it with '+', but it does not work with my software in the same way.
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
#include <LiquidCrystal.h>
boolean newData = false;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '+';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '+'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
lcd.setCursor(0, 1);
lcd.clear();
lcd.print(receivedChars);
newData = false;
}
Thanks so much to anyone who can help. I apologize if a similar question has been asked already, but I cannot find one.
an example of solution: i have adapted the program which is okay with '+' with the 3 endMarkers