How to measure orientation with IMU sensor on handheld product

I am working on a project which use an IMU (accelerometer + gyroscope) sensor to detect the movement of a handheld product. I do not need an accurate measurement because I only need to detect whether a person is holding the product or place in rest position. I have created two prototypes for testing. One with the ADXL345 accelerometer, another one with the MPU6050 (accelerometer + gyroscope) sensor.

I know that solely the accelerometer can be used to detect the orientation of the product by measuring the gravity direction when there is no other force applied to the product. This is probably when the product is placed at rest state when power on the product. However I encountered a problem that as my application is a handheld product, when it is switch on, the product can be not in a rest state. In another words, when I power on the product, there may be hand movement force with the gravity force. As such I can not measure the orientation.

As I cannot measure the orientation, I also cannot reduce the gravity force from the accelerometer reading.

Any idea how to solve the issue? Thank you very much.

Another thing is when I test with the MPU6050 DMP, the "roll" and "pitch" in "yaw,pitch,roll" is correct immediate after I switch on it. However the DMP real(reduced gravity) accelerometer reading is not stable in this moment. How can the "roll and pitch" is correct if the accelerometer reading is not stable?

Thank you very much.

You could experiment with an absolute orientation sensor, such as the BNO055.

While that may be satisfactory for your project, don't expect this to be an easy project. Such sensors are constantly under development, with varying degrees of success. For a comparison of several approaches, this long article is worth reading. Also check out Affordable 9 DoF Sensor Fusion · kriswiner/MPU6050 Wiki · GitHub.

The main problems today are that the sensors need to be properly calibrated, and nobody is doing that very well due to microprocessor limitations. Also, for stable yaw estimation, magnetometers are required, and they are not only very difficult to calibrate properly, magnetic materials in the vicinity can render them completely useless.

Actually the MPU6050 has the DMP function, with the software library it can get the accelerometer value with the gravity removed. When power on, if I place the sensor in the same orientation that when it is calibrated, the data is good. However if I place the sensor in different orientation when power on, the accelerometer value change continuously for about 10s until it become stable.

I would like to ask is there any way to avoid waiting for that 10 seconds?