Bluetooth wireless connection data fluctuates

Issue #465 open
xixicarry created an issue

Hi John, when I use (HC-SR04), I found that the data obtained by HC-SR04 is stable with wired connection, when I use Bluetooth wireless connection, the data obtained by HC-SR04 fluctuates, which affects the results of the experiments

test video

Comments (4)

  1. xixicarry reporter

    I found that the data fluctuation is even more dramatic for devices with I2C added, such as the 4-way line sensor.

  2. John Maloney repo owner

    Thank you for reporting this.

    It sounds as though Bluetooth is stealing enough cycles to make the time measurements of the HC-SR04 unreliable. That is an unexpected downside of using BLE!

    We may need a low-level timing function to ensure timing accuracy for things like the HC-SR04 and IR remote features. It's a tricky problem but I will give it some thought.

  3. John Maloney repo owner

    I've investigated the problem. On the micro:bit, running BLE adds a tiny bit of timing jitter, up to about 60 microseconds. That does not introduce significant noise into the HC-SR04 distance measurements.

    Unfortunately, things are much worse on the ESP32. I observed timing glitches of up to 2500 microseconds, which would translate to many cm of error in HC-SR04 measurements.

    We'll need to either find some way to reduce the ESP32 timing jitter while using BLE or, as I said, use a low-level, interrupt driven timer to get an accurate time measurement of the HC-SR04 echo return pulse. I will work on that.

    Meanwhile, your best bet to disconnect from BLE when using the HC-SR04 sensor.

  4. Log in to comment