jelynch
Posts: 1
Joined: Fri Mar 25, 2016 6:36 pm

Set_rotation messing up accelerometer values?

Fri Mar 25, 2016 6:45 pm

I'm trying to get true accelerometer values from the Sense HAT. It works great if I don't use the set_rotation to properly orient the LED matrix. But, when I do use set_rotation to change from the default orientation, my accelerometer values switch up between x, y, and z randomly (at least from what I can guess). I'd like to be able to change the orientation of the LED matrix without effecting the accelerometer values. I'm using

x, y, z = sense.get_accelerometer_raw().values()

to get my accelerometer values. Any suggestions?

Thanks in advance!

alphanumeric
Posts: 2152
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Set_rotation messing up accelerometer values?

Tue May 17, 2016 12:26 pm

Flipped 180? If yes X and Y will be reversed. You'll just have to take it into account in your code and correct the values for it. I have my display flipped 180. My joystick detection is now upside down. I just wrote my code accordingly. Stick up is really stick down etc.

scotty101
Posts: 3750
Joined: Fri Jun 08, 2012 6:03 pm

Re: Set_rotation messing up accelerometer values?

Tue May 17, 2016 2:57 pm

I can't see any connection between set_rotation for the LED matrix and the accelerometer data.
https://github.com/RPi-Distro/python-se ... nse_hat.py

What are you trying to achieve?
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

alphanumeric
Posts: 2152
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Set_rotation messing up accelerometer values?

Tue May 17, 2016 8:08 pm

scotty101 wrote:I can't see any connection between set_rotation for the LED matrix and the accelerometer data.
https://github.com/RPi-Distro/python-se ... nse_hat.py

What are you trying to achieve?
I think that's the issue. Look at the accelerometer data, turn your Pi 180 degrees, then look at it again. The X and Y axis are likely now reversed, backwards.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Set_rotation messing up accelerometer values?

Fri May 20, 2016 10:33 am

I think it's because you're using .values() this returns the values unsorted. So it will look like the axes are changing all the time.
Try this instead;

Code: Select all

accel = sense.get_accelerometer_raw()

x = accel["x"]
y = accel["y"]
z = accel["z"]

Return to “Astro Pi”