element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RIoTboard
  • Products
  • Dev Tools
  • Single-Board Computers
  • RIoTboard
  • More
  • Cancel
RIoTboard
Blog Riotboard Xtrinsic accelerometer : Tilt detection
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RIoTboard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tusharp
  • Date Created: 26 Nov 2014 8:07 PM Date Created
  • Views 725 views
  • Likes 1 like
  • Comments 0 comments
  • driver
  • tusharp
  • Ubuntu
  • yocto
  • gpio
  • freescale
  • imx6
  • riotboard
  • accelerometer
  • embedded
  • xtrinsic
  • quick-start
  • setup
  • riot
  • cortex-a9
  • mma8491q
  • bsp
  • arm
  • arm9
  • sensor
  • linux
Related
Recommended

Riotboard Xtrinsic accelerometer : Tilt detection

tusharp
tusharp
26 Nov 2014

Previously we managed to measure the inclination angle and calculated  pitch and roll of xtrinsic mma8491q .

In the guide we will be measuring the 45 degree tilt detection using the dedicated pin-outs in xtrinsic.

 

2nv78eq.jpg

 

 

Before moving on we will be automating the accelerometer EN pin GPIO setup process, so that we don't have to manually setup the gpio everytime we restart Riotboard.

 

below code will do that.

system("devmem 0x20E009C w 0x5  > /dev/null ");  // setup EN pin high.

system("echo 112 > /sys/class/gpio/export");          

system("echo out > /sys/class/gpio/gpio112/direction");

system("echo 1 > /sys/class/gpio/gpio112/value");

 

 

Tilt detection procedure

 

The MMA8491Q offers a 45 degree tilt detection per axis.

There are dedicated pins for each axis, which can be easily implemented in driver to detect tilts.

 

from xtrinsic datasheet pg-7, pins 2,3 & 4 in CN1 are used to detect 45 degree tilts on Z-axis, Y-Axis and X-axis.

24d55ir.jpg

 

locating the pins on xtrinsic board ...

30krr45.jpg

 

 

Setting up Hardware ...

 

we will be using 8 pins of Xtrinsic board.

 

Pin Mapping for Xtrinsic Accelerometer.

21enfo1.jpg

 

8  Male to Female jumper wires are used  to connect Riotboard Expansion port pins to Xtrinsic CN1 & CN2 .

 

 

Connecting female headers in Xtrinsic CN2 Connector.

t7d0qx.jpg

 

Setup after connections ...

de39rm.jpg

 

 

Pins 2,3,4 in Xtrinsic are connected to Pins 7,9,11 in J13 port on Riotboard.

 

Pin7  = GPIO4_17 = (4-1)*32+17 = 113

Pin9  = GPIO4_18 = (4-1)*32+18 = 114

Pin11 = GPIO4_19 = (4-1)*32+19 = 115

 

 

determine PIN location from i.MX processor reference manual :  page 2004

 

 

10wi6ub.jpg

GPIO4_17 = DI0_PIN15 = 0x20E00A0

GPIO4_18 = DI0_PIN2   = 0x20E00A4

GPIO4_19 = DI0_PIN3   = 0x20E00A8


 

Configure GPIO settings for the 3 tilt pins connected:

system("devmem 0x20E00A0 w 0x5  ");

system("echo 113 > /sys/class/gpio/export");

system("echo in > /sys/class/gpio/gpio113/direction");

 

system("devmem 0x20E00A4 w 0x5  ");

system("echo 114 > /sys/class/gpio/export");

system("echo in > /sys/class/gpio/gpio114/direction");

 

system("devmem 0x20E00A8 w 0x5  ");

system("echo 115 > /sys/class/gpio/export");

system("echo in > /sys/class/gpio/gpio115/direction");

 

After exporting pins, a file named value will be available in gpio directory under sysfs filesystem.

In linux the exact location is /sys/class/gpio/gpioNUM/value

 

 

below code helps to determine if X-Axis is tilted more than 45 degree, If value contains 1, it means Tilted:

fd_x = open("/sys/class/gpio/gpio115/value",O_RDONLY);

- - - -

- - - -

ret = read(fd_x,buf,sizeof(1));

if(ret>0 && (atoi(buf)==1))

  printf("X is tilted\n");

 

if(lseek(fd_x,0,SEEK_SET) < 0) return 1;   //return back read cursor to beginning of file

 

 

Lets Tilt and test:

 

Tilt X-axis :

110zn60.jpg

 

Tilt Y-axis :

14dijro.jpg


Tilt Z-axis :

10citkp.jpg


The completed code is in attachments.


So we completed Xtrinsic Accelerometer integration on Riotboard.



Attachments:
6012.xtrinsic_acc.c.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube