Skip to main content

Project Based Engineering Instrumentation High Level Coding and Microcontrollers

Section 21.1 Setup Pendulum Example

In this example I’m going to swing a pendulum in the X/Y plane of the accelerometer sensor so that I can ignore the Z axis data. I’m going to get the actual angle of the pendulum but if you’re building something else you can ignore this part. In order to convert the accelerometer values to pitch angle, I’m going to use the same equations discussed in the accelerometer lab (See Subsection 15.1.4)
Remember, on the CPX/CPB specifically you’ll want to import the math module and use the atan2 function. When I swing the pendulum, this is the result I get from Plotter in Mu.
Figure 21.1.1. Oscillations shown from atan2 measurement of accelerometer in Mu
If I then bring this into Python I get the following plot below. In my data set I only logged the angle. Since the time step between each point was 0.01 seconds I was able to create a time series. It’s pretty clear that there is some nonlinearity in the data so I chose to start the data at 0.5 seconds. Another thing I noticed was that the angle settled out to around 8 degrees so I chose to subtract off that bias from the angle data.
Figure 21.1.2. Oscillation data plotted in Thonny