I have been trying to get a normal vector for the device without success. I tried rotating the up vector [0, 0, 1] by pitch around the x axis, then by the roll around the y axis, and finally by the yaw around the z axis. This appears to work (I'm streaming and displaying the data on a phone) except when rotating the device about its z-axis when the z-axis is perpendicular to gravity (https://mbientlab.com/tutorials/Orientation.html).
What's interesting is as I start to rotate the device in the previously specified orientation, the yaw changes. I would expect it not to change because when I rotate the device around the gravity axis when the device's z-axis is perpendicular to the gravity axis, the only value that changes is the yaw, so I would expect yaw not to change when the device is rotated about a perpendicular axis.
Thank you for taking the time to read my question.