element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Microstack accelerometer won't work on Raspberry PI A: a workaround to the issue
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: balearicdynamics
  • Date Created: 20 May 2015 4:02 PM Date Created
  • Views 2045 views
  • Likes 1 like
  • Comments 6 comments
Related
Recommended
  • raspberry
  • i2c
  • i2c_issue
  • accelerometer
  • raspberry-pi-a
  • raspberry-pi
  • accelerometer_issue
  • i2c_channels
  • microstack

Microstack accelerometer won't work on Raspberry PI A: a workaround to the issue

balearicdynamics
balearicdynamics
20 May 2015

This is not a problem but a fact. And there is also a precise reason: the first model of the PI, with 256 Mb ram uses the I2C channel 0 instead of the I2C channel 1 adopted in the further versions. So, as the Microstack accelerometers is hardware compatible with the PI model A+, the software no.

 

The key was to discover from what was depending this issue, that is the i2C channel settings. And nothing changes if you manually enable also the channel 1 because it is question of internal settings of the system.

 

The problem

Install the Microstack software as explained in the guides. Then with the suggested tests with the accelerometer you see that instead of the coordinates you see on the terminal a series of communication errors. The most important is the last line returned from the command

 

/usr/lib/python3/dist-packages/microstacknode/accelerometer $ python3 /usr/share/doc/python3-microstacknode/examples/accelcat.py

 

Traceback (most recent call last):
  File "/usr/share/doc/python3-microstacknode/examples/accelcat.py", line 8, in <module>
    accelerometer.init()
  File "/usr/lib/python3/dist-packages/microstacknode/accelerometer/mma8452q.py", line 114, in init
    self.i2c_master.open()
  File "/usr/lib/python3/dist-packages/microstackcommon/i2c.py", line 61, in open
    posix.O_RDWR | extra_open_flags)
OSError: [Errno 2] No such file or directory: '/dev/i2c-0'

 

The reason is that the PI tries to manage the i2c-0 while the Microstack is set to work with the i2c-1

 

Workaround

Enable the i2C0 (I have left also the i2C 1 but it is meaningless)

 

$>sudo nano /boot/config.txt

 

and add (if not yet present) the following three lines to the bottom of the file.

 

dtparam=i2c0=on
dtparam=i2c1=on
dtparam=i2c_arm=on

 

Then save the file and reboot. After reboot, with the command

 

$>i2cdetect -y 0

 

you should see a table with the currently installed i2C devices

 

    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- 1d -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU
70: -- -- -- -- -- -- -- --                   

 

At the address 0xd3 you will see 1d that is just the i2C ID of the Microstack accelerometer. All this is correct but it is only half of the solution of the problem. As a matter of fact, if you launch again the accelerometer test program you continue to see a problem connecting with the device.

 

The reason is that the Microstack-common land Microstack-node installed libraries try to open by default the i2C address 1 that we can't use

 

Make nother couple of extremely simple changes:

 

open with a sudo editor the following two files

 

/usr/lib/python3/dist-packages/microstacknode/accelerometer/mma8452q.py

 

and

 

/usr/lib/python3/dist-packages/microstackcommon/i2c.py

 

In one of the first top lines, you see

 

DEFAULT_I2C_BUS = 1

 

in both of them. Change to

 

DEFAULT_I2C_BUS = 0

save the files and the accelerometer will work!

  • Sign in to reply

Top Comments

  • clem57
    clem57 over 10 years ago in reply to balearicdynamics +1
    Yuk. Is that a technical term?
  • mcb1
    mcb1 over 10 years ago +1
    Nice work. I've bookmarked it because I'm sure I'll come back to it later and wonder why it doesn't work. ... Mark
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to mcb1

    Thank you image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago

    Nice work.

    I've bookmarked it because I'm sure I'll come back to it later and wonder why it doesn't work. ...

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to clem57

    What term ? Yuk ???

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to balearicdynamics

    Yuk. Is that a technical term? image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to clem57

    The problem is evil and is none of the two. The problem is that they changed the internal use of the processor i2C (there are two AFAIK) and the software of these things has nothing to parametrise it. So, the only possibility is (avoiding to drastically change the libraries with a more flexible and parametrised init method) to correct the python sources depending on where the installation is. On the same pins i2C is differente through the models image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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