Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not fast enough at 3200Hz #1

Open
hutauf opened this issue Dec 26, 2020 · 1 comment
Open

not fast enough at 3200Hz #1

hutauf opened this issue Dec 26, 2020 · 1 comment

Comments

@hutauf
Copy link

hutauf commented Dec 26, 2020

Hi,
I've tried your code on an ESP32 development board. If I run it as is, I get the message that the actual sampling rate is 320Hz, so only 1/10th of the desired 3200Hz. Which board did you use to achieve the 3200Hz?

I also had to reduce the aquisition_time to 0.1s, because otherwise I would ran into MemoryErrors.

Here is my code:

def start_measurement():
    accelerometer = Accelerometer()
    accelerometer.init_spi()
    accelerometer.set_sampling_rate(3200)
    accelerometer.set_g_range(16)
    accelerometer.set_fifo_mode('stream')
    accelerometer.set_power_mode('measure')
    cntr=0
    try:
        while True:
            cntr+=1
            buf, T = accelerometer.read_continuos_xyz_fromfifo(acquisition_time=0.1)
            x, y, z = accelerometer.xyzbytes2g(buf)
            print(len(x))
            if cntr>100:
                break
    except:
        pass
    finally:
        accelerometer.set_power_mode('standby')
        accelerometer.deinit_spi()

I've tried removing stream/standby switches and cs.value() calls to make it faster, but with no success. Only if I remove your "# it is impossible to read a block of measures from fifo"-for-loop, and read all the data inside the fifo at once, I can read ~28 samples at once (so right before the FIFO is full, maybe) and end up with an actual sampling rate of ~7200 or ~4500Hz, depending if I use cs.value calls or not. Which is strange, because I'm checking the size of the FIFO and I am only reading what is there. So I guess I'm not acually reading the whole FIFO, and it just pops one sample... But the size is not increasing to 32, so I'm really not sure what is happening. The data that I get from this also doesn't look plausible, there are a lot of 0's in there, but not everywhere as I would expect.
Why is it that we cannot read the complete FIFO at once?
Should I switch to Adruino IDE/C and back off of python if I need the 3200Hz? Did you manage to get it working?

Thanks

@AlekseyFedorovich
Copy link
Owner

AlekseyFedorovich commented Mar 21, 2021

Hi,
sorry for the late answer.

  1. MemoryError: In the readme I indicated that I used an ESP32-WROVER (4MB of RAM). If you use a ESP32-WROOM32 you will probably end up in a memory error also with a very short acquisition time at max frequency because of the lack of ram of the MCU. Consider that also with the WROVER model you end your RAM after approximately 10 seconds of continuos measuring @ 3200Hz
  2. Sampling Rate: In the readme the suggested script for continuos measurement is very different from yours: you don't have to write your own while loop, please test your setup with the suggested code in the readme.
  3. FIFO: in my experience you can't read the fifo at once, probably with your code modification you are just reading following registers of the accelerometer
  4. ADXL345: in my experience the adxl345 is too noisy for reliable measures at decent sampling rates: I'm working on a library for ADXL355 and ADXL357: stay tuned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants