Board Orientation Detection
Learning Objectives:
After performing this lab exercise, you will be able to:
Create Arduino sketch (code) and program Arduino/Genuino 101 board
Understand the working of Accelerometers
Read the acceleration experienced by the Arduino/Genuino 101 board using on-board on-board accelerometers
Process the accelerometer signals to estimate the board orientation
Working principle of key components
Before performing this lab experiment, it is important to learn following concepts:
Arduino/Genuino 101 is a low-power consumption and high-performance version of Arduino board with Bluetooth low-energy (BLE) and accelerometer on board. It is compatible with Arduino/Genuino Uno in term of form factor and peripheral list. (For more details, please visit: https://www.arduino.cc/en/Main/ArduinoBoard101).
Arduino/Genuino 101 can be easily programmed using Arduino IDE (version 1.6.7 and higher). However, the hardware libraries for Arduino/Genuino 101 board needs to be updated / installed. (Refer appendix for detailed procedure).
An accelerometer measures proper acceleration (g-force), which is the acceleration it experiences relative to freefall and is the acceleration felt by people and objects. An accelerometer at rest would experience and measure an acceleration of 9.81m/s2 or simply 1g.
Arduino/Genuino 101 has on-board inertial measurement unit (IMU) – BMI 160, developed by Bosch. BMI 160 IMU consists of a low-power 3-axis accelerometer and a 3-axis gyroscope. ( A Details datasheet is available at : http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf).
CurieIMU library is used for working with the on-board IMU of Arduino/Genuino 101. Using this library, you can access all the parameters, features and reading of IMU chip.
Based on the orientation of the board, the acceleration value for 3-axis would change. At rest, the axis facing opposite to gravity will indicate acceleration of 1g (16K ADC levels). The axis facing downwards (aligned with gravity) will indicate -1g (negative sign indicates pull towards earth’s gravity).
The axes perpendicular to earth’s gravity will indicate 0g.
Thus when board is held with USB connector facing downwards, x-axis would indicate acceleration value of +1g.
The orientation detection mechanism is used in smartphones to stop the caller tone / snooze alarm when the phone is flipped.
Key commands
Before programming the Arduino/Genuino 101, it is important to learn following key commands:
CurieIMU.begin
Initialize the IMU of the board
CurieIMU.setAccelerometerRange
Set the accelerometer range in terms of ‘g’
CurieIMU.readAccelerometer
Read the acceleration values (Ax, Ay and Az) from on-board IMU
digitalWrite
Turn on/off a digital pin of the Arduino / Genuino board
abs
Returns the absolute value of the input
Check Your Understanding
IMU stands for:
Input Measurement Unit
Input Microprocessing Unit
Inertial Measurement Unit
Isolation Measurement Unit
Arduino/Genuino 101 board is kept on a table. The axis facing upwards would indicate:
+1g
-1g
+2g
-2g
Arduino/Genuino 101 board is kept on a table with ‘digital pin edge’ facing upwards. Which axis will show +1g acceleration?
X-axis
Y-Axis
Z-axis
No axis will show +1g, one of them would indicate -1g.
CurieIMU.begin command will
Initialize the IMU
Start reading the acceleration values from IMU
Set the ‘g’ range
Read the gyroscope values
What is NOT part of Genuino 101 board?
Accelerometer
Pizzo Buzzer
Bluetooth
Analog pins
CurieIMU. setAccelerometerRange command will
Initialize the IMU
Start reading the acceleration values from IMU
Set the ‘g’ range
Read the gyroscope values
CurieIMU. readAccelerometer command will
Initialize the IMU
Read the acceleration values from IMU
Set the ‘g’ range
Read the gyroscope values from IMU
The answers to the above questions can be found at Appendix B.
Procedure
Hardware Setup
Connect the Arduino/Genuino 101 board with computer using USB cable.
Arduino IDE / Library Setup
Make sure you have Arduino IDE version 1.6.7 or higher and Intel Genuino 101 drivers installed on your computer. For installation of Arduino IDE and drivers, you can follow instructions from Appendix A.
Creating Sketch / Program
Open the sketch (G101_Ex-3_Board_Orientation_Detection.ino) on Arduino IDE.
From Tools menu, select the right board (i.e., Arduino/Genuino 101) and COM Port it is connected to.
Compile (verify) and run (upload) the sketch on Arduino board. In case of any upload error, try pressing the Master Reset Button just at the start of upload process.
Open the “serial monitor” of Arduino IDE. It will be used to display the accelerometer values and board orientation.
Keep the Arduino/Genuino 101 board on a table. When it is at rest, the LED (on-board LED at pin 13) will be off. Initially nothing would come up on the Serial monitor.
Now change the orientation of the board – flip it or put analog pin side up etc. The LED should blink as and when you change the orientation of the board. The orientation of the board and acceleration values for 3-axis corresponding to that orientation would be displayed on serial monitor.
Verify the value of the accelerometers and orientation reported by the program against actual orientation of the board.
Additional Exercise
You can extend your learning by trying following programming exercises:
Make a system where the LED on board blinks every 20s, simulating a caller ring. The blink should be turned off when the board is flipped upside down (components facing down).
Combine the current program with Bluetooth and make an orientation detector where the board orientation is indicated on a mobile through Bluetooth app.
Last updated