SPEED PID inconsistent read/transform data

This is a simple issue and I know that you guys are reading the speed properly.

I’m trying to read the speed but I never get a speed higher than 70 Km/h . I did a 2 hours trip on a highway, and I expected to get a higher speed (I was reading the panel to see the “average” speed I was driving) with no luck.

This is how I read/parse the speed

int VEHICLE_SPEED =(int) data[3];

Am I doing something wrong ?

Thanks

@maleficarum,

With the ‘int’ in front of VEHICLE_SPEED, you are declaring it as a new variable each time that line of code executes.
I suspect that you also have another ‘int VEHICLE_SPEED’ declared somewhere else, possibly a global variable?
In which case, you may have both a local variable and a global variable with the same name. In such cases, the code is using the proper variable, just not the variable you think it is using.

So, casting data[3] as int is the proper way to parse the speed (Ill check the global/local declaration anyway)?

Here is how the data is parsed for vehicle speed for this app:

//void mathVEHICLE_SPEED() {
    if (data2 == 13) {
        float vehicleSpeed;
        vehicleSpeed = (data3);
        VEHICLE_SPEED = vehicleSpeed;
    }
//}

In his code, the vehicleSpeed variable is a float, rather than an int.
However, before looking at this, I am certain you will have to check the scope (global/local) of your variable.