This Jupyter notebook shows how to analyse BBC micro:bit motion sensor data saved into a csv text file.
I generated this data by fastening one microbit to my kettle as the water heated up then boiled. That microbit ran my logging program microbit-logger.py
in 'tx'
mode to transmit csv data by radio. The data was received by a second microbit, which was connected to my computer via USB. This microbit ran microbit-logger.py
in 'relay'
mode. Finally my computer ran usb-receiver.py
redirecting output to the text file data-kettle.csv
:
$ python usb-receiver.py > data-kettle.csv
The text file can be loaded most easily using pandas
.
In [2]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
In [7]:
df = pd.read_csv('data-kettle.csv')
df['Time'] /= 1000.0 # Convert from ms (int) to sec (float)
df.set_index('Time', inplace=True)
df.info()
In [8]:
accXYZ = df[['AccX','AccY','AccZ']]
accXYZ.plot()
Out[8]:
In [9]:
accXYZ = df[['AccX','AccY','AccZ']]
g = accXYZ[50.0:200.0].mean()
g
Out[9]:
In [10]:
s = (accXYZ - g).pow(2).sum(axis=1)
In [11]:
s.plot()
Out[11]:
In [12]:
plt.specgram(s, NFFT=512, Fs=100, noverlap=32)[3]
Out[12]: