Vibrations All Around Us 2: Tools Setup


In this post of the Vibrations All Around Us blog series, we will be discussing the setup of the Nicla Sense ME microcontroller that will be used for measuring vibrations in all of the future labs in this series. For those of you completing the labs with us, this will be an important lab for you as this is the tool we will use for all of the following experiments. If you are just finding this page, be sure to start from the beginning introduction to the series.

Getting Started with the Nicla Sense ME

To test out the board’s sensors, you can follow the instructions in this example from the Arduino website to install the appropriate libraries and get a basic understanding of the sensors available on the board. We’ll only be utilizing the boards’ accelerometers for this blog series so I’ve adapted the sketch to only publish accelerometer information to increase the rate that data can be transmitted over Bluetooth Low Energy (BLE).

We used a Python script that has been adapted from Bleak (an SDK for Python BLE connections) to read the accelerometer information published by the board over BLE connection. We will be using this script extensively over the course to log data. Within the script, the Service and Characteristic Bluetooth UUID has been set to match the UUID’s in the Arduino script, so if you change one, make sure you change the other. Finally, you can choose the time of data capture and the location/name of the data file.

Let’s get some data now! When you run the script, you should see the terminal print the accelerometer data packets as they’re received. After the number of seconds specified by runtime, the script will automatically terminate and print a message print a message indicating the publishing speed of the data:

X accel: 1167.0, Y accel: 37.0, Z accel: 3948.0, time: 4540400.0
X accel: 1175.0, Y accel: 34.0, Z accel: 3956.0, time: 4540408.0
X accel: 1165.0, Y accel: 48.0, Z accel: 3945.0, time: 4540416.0
X accel: 1169.0, Y accel: 38.0, Z accel: 3958.0, time: 4540424.0
X accel: 1179.0, Y accel: 53.0, Z accel: 3958.0, time: 4540432.0
X accel: 1171.0, Y accel: 37.0, Z accel: 3959.0, time: 4540440.0
Accel data gathered for 10 s at frequency of 112.3 Hz

For the first couple of seconds the Bluetooth connection is slow, but we can expect a consistent 125 Hz sampling rate after the first 2 seconds.

A couple of things to note:

  • The data coming from the Nicla’s accelerometer is scaled by 4096 counts per unit of gravity. Therefore, to get real world units of gravity we can divide the reported values by 4096.
  • We are deleting the first 2 seconds of data. The BLE connection is usually poor for the first couple of seconds while establishing a connection. Make sure to account for this when you are setting your experiment length.

Plot Accelerometer Data

To verify that we are gathering meaningful data, I have taken a 10 second data capture where I am holding the Nicla and shaking it along its X, Y, and Z components in that order (these directions are indicated on the physical board). Let’s add another helper function to which allows me to plot the individual components of the accelerometer.

You should see the distinct components shaking like so. If your plot doesn’t look like this, just double check that you’ve shaken the device along the correct components. Let’s take another test where I’ve let the board sit completely still and change its orientation every few seconds. If we take the resultant acceleration measured, which is the magnitude of the resultant vector from adding the 3 acceleration components, we should see the value be close to 1 G of acceleration while the board is sitting still since the only force acting on the object is the force of gravity. The resultant is calculated as follows:

resultant = \sqrt{x^{2} + y^{2} + z^{2}}

We can see that in between the periods of movement, the accelerometer rests at a steady 1 G. ( the large spikes are me adjusting the board to different orientations). This value will likely be slightly off due to variations in temperature which the accelerometer is sensitive to. There are techniques to compensate for the effect of temperature on the accelerometer, but we don’t need that level of precision for this blog series. 

In the next post, we’ll be looking at Aliasing, Real-Time/Batching Techniques, and Causal/Non-Causal Techniques.

Leave a Reply

Your email address will not be published. Required fields are marked *