From Adafruit website, "If you've ever ordered and wire up a 9-DOF sensor, chances are you've also realized the challenge of turning the sensor data from an accelerometer, gyroscope and magnetometer into actual '3D space orientation'! Orientation is a hard problem to solve." The problem we met is exactly this one. After lots of trial and error, we decided to use Adafruit BNO055, which is a smart 9-DOF sensor that does the sensor fusion all on its own. So it will give absolute orientation as follows.
After testing, we managed to get meaningful data from BNO055. In the above figure on the left, the degree detected is 328 degree. When I turned the board to the right (in the figure on the right), the detected degree changed to 347 degree. Most important, when I don't move the board, the value keeps stable.