Cli-data-forwarder frequency off by one

Dear all,

For a while now I have been using the data-forwarder to acquire data in edge-impulse.
Initially I wrote a simple piece of firware to forward x, y and z accelerometer values at 100Hz. The forwarder detected 101Hz, which was weird, but maybe it was because of my simplistic firmware.
Now, a few months later I had the problem with the spectrogram (see my previous post), so that frequency of 101Hz kept giving issues.
I have refined my piece of code and wrote it in two ways (mbed), once with a ticker, once with an event queue. I post the code with the event queue below.

I tried out different call times and checked the detected frequency of the data forwarder:

  • 10ms --> 101Hz
  • 20ms --> 51Hz
  • 1000ms --> freq should be higher than 2Hz
  • 500ms --> 3Hz

I still doubted about my code, so I measured the on- and off-time of the LED on the device with a scope, which shows that it is actually exactly 500ms! (when configuring 500ms).

Photo of the scope:


#include "mbed.h"
#include "USBSerial.h"
#include "LSM303AGRAccSensor.h"

USBSerial serial;
DigitalOut led((PinName)0x6C);
EventQueue queue(32 * EVENTS_EVENT_SIZE);
SPI devSPI(PB_15, NC, PB_13);  // 3-wires SPI on SensorTile  
static LSM303AGRAccSensor accelerometer(&devSPI, PC_4);

FileHandle *mbed::mbed_override_console(int) {
    return &serial;

void toggleLed() {
    led = !led;

void initializeAccelerometer() {
    uint8_t id;
    int32_t axes[3];
    //printf("LSM303AGR accelerometer           = 0x%X\r\n", id);
    //printf("LSM303AGR [acc/mg]:      %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);

void readAccelerometer() {
    int32_t axes[3];

int main(void)
    led = 1;
    queue.call_every(500ms, readAccelerometer);

Is it possible that the data forwarder adds one Hz too much?
Or when looking at the actual software, does it count one “\n” too much in 1000ms?

Is the best way to go to always override the detected frequency with the --frequency option?

Best regards,

I just had a look at the source code here:

I do not see anything that could increase the frequency by 1 except maybe the let l = lines[1];
I check with the core engineering team and I let you know.


@JLannoo Could you try with this branch?

I’ve done some work today and this gives me 100% accurate sampling frequency when using hardware timers on an ST board. Would be good to see if this also resolves your issue!

Hi Jan,

It seems like this actually solved it, checked it multiple times for 10ms, 200ms, 500ms and detected 100Hz, 5Hz and 2Hz. Thanks!

Best regards, Jonas

1 Like

Awesome, will merge it in and release in the coming days!

Now released in CLI version v1.13.11.

1 Like