Hello,
I am currently building a Nunchuk controlled electric Longboard, using HC-05 Bluetooth modules for communication, an Attiny45 in the Nunchuk and an Arduino Nano in the longboard, controlling a HobbyKing 150a X-car ESC. I am so far happy with how its working out besides one big issue: when controlling the board, it sometimes happens, that it first doesnt react at all, and then suddenly speeds up or slows down (Probably delayed inputs, but it rather feels completely random instead of delayed). The ESC gets controlled via Software Serial PWM Pin 9, and the bluetooth communication is done via Hardware Serial. Here's the Bluetooth reading code.
void recv() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) { //ÜBERPRÜFEN
recvInProgress = true;
}
}
}
void parseData() { // split the data into its parts
char * strtokIndx;
strtokIndx = strtok(tempChars, ",");
Mode = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
readvalue = atoi(strtokIndx);
}
I currently have no idea what the problem is caused by, but I kind of think it is the Bluetooth communication. Maybe input buffer overflow? Could that end up causing these problems? If yes, how do I prevent it, or in other words: how do I make the arduino only use the newest Info available? I will provide any other data needed, I am just not sure what informations to give.
Also: this never occurs on startup, it only happens a few seconds/minutes after starting