Hi,
I'm trying to add a software low pass filter to a noisy sensor to make the output smoother. I think I have the idea right and it compiles and uploads fine, but my arduino seems to crash when I run it; no serial output when if I call the lowPassFilter function. I'm used to seeing run time errors when I usually program, and now that I don't I'm stuck figuring out my error. Is there any way to simulate run time somehow to figure out errors? Or do I need a hardware debugger? I'm new to arduino so I'm just using the standard arduino IDE. It's not very feature rich in terms of auto completion or built in documentation. Should I be using something else?
here is my code:
float data[10];
void setup(){
Serial.begin(9600);
// initialize array
for (int i = 0; i < sizeof(data); i++){
data[i] = 0.0;
}
}
void loop(){
float current_value = readData();
float filtered_value = lowPassFilter(current_value, data);
Serial.print("Value = ");
Serial.println(filtered_value);
}
float lowPassFilter(float new_data, float *data_array){
float filtered_value = 0;
float data_array_sum = 0;
// remove oldest data in array (first index) and shift all other indexes to the left
for (int i = 0; i < sizeof(data_array); i++)
data_array[i] = data_array[i + 1];
// add new data to array (last index)
data_array[sizeof(data_array) - 1] = new_data;
// get average value from the data array
for (int i = 0; i < sizeof(data_array); i++){
data_array_sum += data_array[i];
}
filtered_value = data_array_sum / sizeof(data_array);
return filtered_value;
}
Any ideas of what my problem could be or how I could figure it out without a hardware debugger?
Thanks