Reading accelerometer data

Now you're ready to write a code on your Raspberry Pi to read the accelerometer on your smartphone. The code will output accelerometer values on the x, y, and z axes of the smartphone or tablet in m/s2:

  1. Modify the main.cc file with the source code listed in Listing 6.1:
Listing 6.1: Reading the accelerometer on the smartphone
  1. Then, save the file and exit the nano text editor by pressing Ctrl + O, followed by Enter, followed by Ctrl +X.
  2. Build the project with the following command:
pi@raspberrypi:~/blynk-library/linux $ ./build.sh raspberry  
  1. Then, run the program with the auth token associated with your Blynk project:
pi@raspberrypi:~/blynk-library/linux $sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f 
  1. Tap the play button on the Blynk app builder to start the Blynk app on your mobile device. The console will output the readings for accelerometer values on the x, y, and z axes.
  2. Let's take some accelerometer values for different gestures, such as face-up, up, and left.
  3. Place your mobile device face-up on a table, as shown in Figure 6.5; the z-axis measures the acceleration of Earth's gravity and outputs ≈9.81 in m/s2. The x and y axes, which are perpendicular to the acceleration of Earth's gravity, both output ≈0.00 in m/s2:
Figure 6.5: Face-up gesture (created by Zlatko_plamenov—Freepik.com)
  1. The following screenshot shows the accelerometer readings for the face-up gesture:
Figure 6.6: Accelerometer output for face-up gesture
  1. For the opposite gesture of face-up, which is face-down, the accelerometer will produce negative values on the z-axis (Figure 6.7):
Figure 6.7: Accelerometer output for face-down gesture
  1. Then, place your mobile device on a table (so the mouthpiece side is on the table), as shown in Figure 6.8. The y-axis measures the acceleration of Earth's gravity and outputs ≈9.81 in m/s2. The x and z axes, which are perpendicular to the acceleration of Earth's gravity, both output ≈0.00 in m/s2:
Figure 6.8: Up gesture (mouthpiece side is on the table)—Created by Freepik
  1. The following screenshot shows the output values on each axis for this gesture:
Figure 6.9: Accelerometer output for up gesture
  1. If you place the earpiece side of the mobile device on the table (down gesture), the accelerometer will produce negative values on the y axis (Figure 6.10):
Figure 6.10: Accelerometer output for down gesture
  1. Finally, place your mobile device on a table (the left-hand side of the mobile device should be on the table), as shown in Figure 6.11. The x-axis measures the acceleration of Earth's gravity and outputs ≈9.81 in m/s2. The y and z axes, which are perpendicular to the acceleration of Earth's gravity, both output ≈0.00 in m/s2:
Figure 6.11: Left gesture (created by Freepik)
  1. Figure 6.12 shows the output values on each axis for this gesture:
Figure 6.12: Accelerometer output values for left gesture
  1. If you place the phone as shown in Figure 6.13 (opposite of the left gesture, which is the right gesture), the accelerometer will produce negative values on the x-axis:
Figure 6.13: Right gesture (created by Freepik)
  1. Figure 6.14 shows the output values on each axis for the right gesture:
Figure 6.14: Output values for the right gesture
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.23