I am trying to use an Arduino board (SparkFun Pro Micro) to communicate with a waveform generator box. The manufacturer created computer software to control the box and gave me the developer document (not for public distribution) required to create my own control software. Trying to implement the control software on an Arduino 8 bit board. Given the 9600 bus speed and 200ms minimum between commands, expecting any Arduino to be capable of this task.
For hardware, I have the box with UART interface and the Arduino board connected with ground, TX/RX, and RX/TX with successful communication.
The waveform generator box sends out a lengthy response string after every command received. So far, have only been sending "V" for the version command and get this string in response:
744:0:0:100:100:0:L:1:2.106
It is sent as a series of ASCII characters with ":" as the separator. My current task is trying to separate out the parts into the battery level, mode, and 4 waveform parameters. So, starting with the first number, need to read characters into another string until finding the first ":" (744 usually, raw ADC battery voltage). Can't figure out how my code sends out ~240 instead.
Of note, last night's edits to the responseParse() function created compile errors in the commented out section. Also, the responseParse() function as shown halts the Arduino processor.
/*
Serial control of Waveform Generator
*/
String com;
String commandResponse = "744:0:0:100:100:0:L:1:2.106";
uint8_t mode, paramA, paramB, paramC, paramD;
unsigned long battery;
uint8_t pauseTime = 220;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial1.begin(9600);
version();
}
void loop() {
version();
// put your main code here, to run repeatedly:
/*
while (Serial.available() > 0) {
inByte = Serial.read();
Serial.println(inByte);
} */
delay(pauseTime);
}
void responseParse() {
uint8_t length = commandResponse.length();
Serial.println(length);
uint8_t parts[6];
uint8_t piece = 0, stringPartNumber = 0, index = 0;
char stringPart[4] = "";
while (piece < 6) {
char atIndex = commandResponse.charAt(index);
index++;
/*
if (atIndex == ':') {
String stringy = stringPart[].toString();
parts[piece] = stringy.toInt();
piece++;
stringPart = "";
stringPartNumber = 0;
} else {
stringPart[stringPartNumber] = atIndex;
stringPartNumber++;
} */
}
battery = parts[0];
mode = parts[5];
paramA = parts[1] / 2;
paramB = parts[2] / 2;
paramC = parts[3] / 2;
paramD = parts[4] / 2;
// printParams();
}
void printParams() {
Serial.print("Battery = ");
Serial.print(battery);
Serial.print(": Mode = ");
Serial.println(mode);
}
void version() {
Serial1.println("V");
commandResponse = Serial1.readString();
Serial.println(commandResponse);
responseParse();
}
Looking for help editing the responseParse() function to correctly identify the first number in the response string and store it into the battery variable as an integer. Hoping this information will also allow me to correctly store the next 5 numbers in the string. Of note, the parameters are 0-200 and mode is 0-16.