Hi all,
I'm currently experimenting with an Arduino Nano BLE Sense and a relatively high sampling rate (every 50ms) for the IMU, Pressure sensor and Thermometer.
I used the provided Arduino_* sensor libraries first, but switched to the Adafruit ones, because they seemed a bit more reliable.
With all the mentioned libraries, i noticed a strange behaviour:
At the beginning, everything works perfectly. After a couple of minutes (or seconds, depending on the used libraries), the sensor readings start to take more and more time, up to half a second. There is no error, they just take ages to complete.
Does this have something to do with a clogged I2C-Bus or something like that?
I already tried to increase the bus speed without success...
At the beginning, I was wondering, if it could be connected to BLE, but if i comment everything out, there is no difference in the behaviour.
If you start the sketch and look into the serial console, you'll see that the updates happen quite quick, but after a few minutes, the logs after "BEGIN Sensors::Loop()" take longer and longer...
Interestingly ALL actions on the Wire1 bus seem to take ages. Its not a single sensor, that behaves strange...
void Sensors::Loop(SystemState &state) {
if(DEBUG) Serial.println("BEGIN Sensors::Loop()");
float temperature, humidity;
ReadTemperatureAndHumidity(temperature, humidity);
float pressure = ReadPressure();
float acc_x, acc_y, acc_z;
ReadAcceleration(acc_x, acc_y, acc_z);
float g_x, g_y, g_z;
ReadGyroscope(g_x, g_y, g_z);
float m_x, m_y, m_z;
ReadMagneticField(m_x, m_y, m_z);
DataPoint newItem = {state.VehicleState, millis(), pressure, temperature, acc_x, acc_y, acc_z, g_x, g_y, g_z, m_x, m_y, m_z};
state.CurrentDataPoint = newItem;
if(DEBUG) Serial.println("END Sensors::Loop()");
}
void Sensors::ReadAcceleration(float &acc_x, float &acc_y, float &acc_z ) {
if(DEBUG) Serial.println("BEGIN Sensors::ReadAcceleration()");
acc_x = -999, acc_y = -999, acc_z = -999;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(acc_x,acc_y,acc_z);
}
if(DEBUG) Serial.println("END Sensors::ReadAcceleration()");
}
void Sensors::ReadGyroscope(float &g_x, float &g_y, float &g_z) {
if(DEBUG) Serial.println("BEGIN Sensors::ReadGyroscope()");
g_x = -999, g_y = -999, g_z = -999;
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(g_x,g_y,g_z);
}
if(DEBUG) Serial.println("END Sensors::ReadGyroscope()");
}
void Sensors::ReadMagneticField(float &m_x, float &m_y, float &m_z) {
if(DEBUG) Serial.println("BEGIN Sensors::ReadMagneticField()");
m_x = -999, m_y = -999, m_z = -999;
if (IMU.gyroscopeAvailable()) {
IMU.readMagneticField(m_x, m_y, m_z);
}
if(DEBUG) Serial.println("END Sensors::ReadMagneticField()");
}
float Sensors::ReadPressure() {
if(DEBUG) Serial.println("BEGIN Sensors::ReadPressure()");
return lps35hw.readPressure();
}
void Sensors::ReadTemperatureAndHumidity(float& temp, float &humidity) {
if(DEBUG) Serial.println("BEGIN Sensors::ReadTemperatureAndHumidity()");
sensors_event_t temp_reading;
sensors_event_t humidity_reading;
hts.getEvent(&temp_reading, &humidity_reading);
temp = temp_reading.temperature;
humidity = humidity_reading.relative_humidity;
if(DEBUG) Serial.println("END Sensors::ReadTemperatureAndHumidity()");
}
You can find the complete code here:
Thanks in advance
Chris