Hello, I am just getting started with Carloop and was able to get up and running pretty quickly. However, I have run into an issue when I am trying to read the most recent value on the CANbus. My code transmits a request for a parameter, then I try to read the response.
The code below works however, it appears it gives me the oldest value in the buffer instead of the most recent one. I put in a 1 second for loop that works but is inefficient. Is there a way to clear out the buffer? Or is there another issue with my code.
for (unsigned long start = millis(); millis() - start < 1000;){
carloop.update();
CANMessage messageread;
if (carloop.can().receive(messageread)){
if (messageread.id == 0x18EFF82E) {
Serial.print(messageread.data[4], HEX);
STread = messageread.data[4], HEX;
}
}
}
The output I get in the serial monitor is below (the value is transmitted every 500ms and changed from 0 to 1 prior to calling this function). Thanks in advance for any help.