- Rpi3 running Stretch
- The sense hat hardware (and rpi3) are rotated 90 degrees clockwise so that 8x8 grid is above the joystick and the USB/ether ports face the ground.
- The “electronic bubble” function uses the sense_hat lib’s orientation functions to get pitch and roll (yes these are correct for my orientation) and displays on the 8x8 led grid an indication of “level”
- Based on a lot of research and help from this site, http://www.starlino.com/imu_guide.html, I determined that I need to change the AXISROTATION value in the /home/pi/.config/sense_hat/RTIMULib.ini file from a default of 0 to 5.
- I’ve also made sure to copy this file to /etc/RTIMULib.ini.
- AXISROTATION=5 is not optional, this is because the IMU at rest, with only the force applied by gravity can read a range of -1 to 1. The formulas which compute the angle make use of the ACOS function so the range in radians is 0 to Pi (mathematical pi 3.14……). As degrees that’s 0 to 180. So I can’t have the 0-180 axis in the same plan as my orientation, because the degrees values go from 178, 179, 180, 179, 178 and 2,1,0,1,2 as the device is rotated. In this case the system can’t tell if it's leaning left or right or front or back. AXISROTATION=5 rotates these axes out of the plane of interest so that I not only know the magnitude but also the direction of "unlevelness".
- The core python script file is executed from the line “python3 /pathToMyScript/myScript.py” which is in an script.sh file which is called from /etc/rc.local on boot.
To confirm the above suspicion, I kill all python processes after boot. Then I enter the following in the command terminal, “sudo python3 /pathToMyScript/myScript.py”. This produces that exact same faulty behavior as running from boot. To test the pi user, I enter “python3 /pathToMyScript/myScript.py”, the system acts as expected.
My theory is that if the script can be executed at boot as the pi user then the system should work. As an attempt to fix this, I changed the script.sh line to “sudo -u pi python3 /pathToMyScript/myScript.py”.