danjperron/mpu6050TestInC

Reading Fifo continuosly

Closed this issue · 4 comments

Hi, first of all thank you for your code
What I was trying is to read continuosly from fifo and write to file, but I am confused on the convert data
this is the error that I face, Can you help me?
Thank you in advance

Screenshot_2023_03_01_15_59_26

Code
# Import Library
import MPU6050_lib_3 as MPU6050
import RPi.GPIO as GPIO
import time

pin = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# TargetSampleNumber= 1024
# TargetRate =  33    # frequency =  8000 / ( integr value + 1)  minimum frequency=32,25

# Adjust read rate
TargetRate = 1000 # max = 2000Hz 

# Setting Sensor
mpu6050 = MPU6050.MPU6050()
mpu6050.setup()
mpu6050.setGResolution(2)
mpu6050.setSampleRate(TargetRate)
mpu6050.resetFifo()
mpu6050.enableFifo(True)
time.sleep(0.01)

print ("Capturing {0} samples/sec".format(mpu6050.SampleRate))
value=[]
#FO = open("RawData.txt","a")


for i in range(10000):
    f = open("data.txt", 'a')
    t1 = time.time()
    trigger = GPIO.input(pin)
    value = mpu6050.readDataFromFifo()
    I = mpu6050.convertData(value)
    print(I.Gyrox)
    f.write("{0:1.1f}\t{1:1.1f}\t".format(t1,trigger))
    f.write("{0:0.3f}\t{1:2.3f}\t{2:2.3f}\t".format(I.Gx,I.Gy,I.Gz))
    f.write("{0:3.3f}\t{1:3.3f}\t{2:3.3f}\t{3:3.2f}\n".format(I.Gyrox,I.Gyroy,I.Gyroz,I.Temperature))
    value.clear()
    t2 = time.time()
    print((t2-t1)*1000)

Thank you for your detail explaination

I use MPU6050 library before and sucess, but I want to read sensor value every 1ms, but using this library I can only read sensor value fatest at 1.8ms

so I want to read from sensor Fifo

I use MPU6050 library before and sucess, but I want to read sensor value every 1ms, but using this library I can only read sensor value fatest at 1.8ms

I'm confuse is it about my library or another one?

If it is mine you should use the C version.

I am sorry, I ask in wrong place
but thank you for your kind explaination
appreciated