-1

i have a acceleration sensor which continuously outputs reading in 400 Hz ( like [0.21511 0.1451 0.2122] ). I want to store them and post process them. Now im able to store the first entry of the reading not all.

How to make it happen.

thanks

from altimu10v5.lsm6ds33 import LSM6DS33
from time import sleep
import numpy as np

lsm6ds33 = LSM6DS33()
lsm6ds33.enable()

accel=lsm6ds33.get_accelerometer_g_forces()

while True:


    DataOut = np.column_stack(accel)
    np.savetxt('output.dat',np.expand_dims(accel, axis=0),  fmt='%2.2f %2.2f %2.2f') 

sleep(1)

´

backtrack
  • 7,996
  • 5
  • 52
  • 99
saran
  • 29
  • 7

2 Answers2

0

Actual problem is, You are calling get_accelerometer_g_forces() only once. Just move it inside While looop

Updated:

while True:
    accel=lsm6ds33.get_accelerometer_g_forces()
    f=open('output.dat','ab')
    DataOut = np.column_stack(accel)
    np.savetxt(f,np.expand_dims(accel, axis=0),  fmt='%2.2f %2.2f %2.2f') 

sleep(1)

Here is a reference :How to write a numpy array to a csv file?

backtrack
  • 7,996
  • 5
  • 52
  • 99
0

Make sure that reading the data is enclosed within to loop!

You don't need numpy here yet:

while True:
    with open("output.dat", "w") as f:
        f.write("%.5f, %.5f, %.5f" % tuple(accelerometer_g_forces()))

Note that there is no condition to stop outputting the data.

user508402
  • 496
  • 1
  • 4
  • 19