Hello,
I have a bicycle, a rpi and an arduino.
The arduino is connected serially with my rpi.
There's a speed sensor attached to the arduino.
Every time a magnet passes the sensor, the arduino sends the speed to the pi (with timestamp).
There's a accelerometer+gyro attached to my pi (mpu6050).
Every 500ms, i write the data from it to a file, with a timestamp.
Problem: I want to know the data from the mpu and the speed at the same time (thus with the same timestamp).
It is possible that for example in the interval 16:49:00.500 - 16:49:01.000 there passed more than 1 magnet (and it will be so since I work with 9 magnets). My wish is that at every half a second, the last known speed is written next to the data from the mpu.
My output file looks like this:
12:13:28.529606 1.35 1.01 2.30 1.11 -2.15 -2.82 -1.85
12:13:31.008576 1.72 1.44 2.43 1.25 -2.64 -2.88 -1.92
12:13:31.514792 1.80 0.02 2.33 1.12 0.44 -2.58 -1.58
12:13:32.026076 1.99 1.82 2.20 1.01 -2.35 -2.68 -1.69
12:13:32.536744 2.28 1.27 2.30 1.12 -1.65 -2.59 -1.61
12:13:33.043188 2.58 0.97 2.33 1.15 -2.09 -2.52 -1.55
12:13:33.557259 2.45 0.51 2.32 1.12 -2.77 -2.52 -1.57
12:13:34.064846 2.83 0.81 2.43 1.22 -1.47 -2.58 -1.63
with column 1: time 2: speed 3-8: mpu data
Unfortunately, the speed is wrong: it writes in this case the 8 first values it has read.
I know it has something to do with just writing the last value that's in the buffer of the arduino.
I do not know how to program it correctly. Probably the solution is something with a method from the pySerial class.
Can anyone help me out with this?