Proper way to handle 1.5g Accelerometer in firmware v1.2.7?

Proper way to handle 1.5g Accelerometer in firmware v1.2.7?

Hello, I am new to tinker some Grove modules with Pi and I have a question about the 3-axis Digital Accelerometer 1.5g module.

According to the changelog in official repository, the GrovePi’s latest firmware version 1.2.7 no longer supports MMA7660. Therefore the function grovepi.acc_xyz() still exists in Python library but does not work, resulting zeros for all axes. I assume it is because the MMA chip remains uninitialized in standby mode.

The following code using generic smbus library goes fine.
The question is: Is the 1.5g module now intended to drive directly with the smbus library? I am making instructions for a project using this device and willing to know the proper way to handle. Any advice would be appreciated.
Thank you.

#!/usr/bin/python3

from smbus import SMBus
from math import nan
from time import sleep

def read_accel():
    # Read three bytes of raw value starting from base address
    xyz = bus.read_i2c_block_data(0x4c, 0x00, 3)
    # Convert it to gravity units
    gxyz = [x/21.33 if x<32 else (x-64)/21.33 if x<64 else nan for x in xyz]
    return gxyz

bus = SMBus(1)

if __name__ == '__main__':
    # Set the device "active mode"
    bus.write_byte_data(0x4c, 0x07, 0x01)
    
    # Get-and-print repeatedly
    while True:
        print(read_accel())
        sleep(1)

Distro: Raspbian Stretch Lite
uname -a: Linux rpi3b 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT 2018 armv7l GNU/Linux
Test log: log.txt (5.8 KB)

Hi @kayeksspectrum,

The library you use is a matter of personal choice and usability.
There are literally dozens of libraries to interface with I2C devices in Python. What has worked really well, especially with the latest releases of the kernel (and of Raspbian) so far, is python-periphery library. It has even performed better than smbus.

Here’s a link to this library:
https://pypi.python.org/pypi/python-periphery/1.1.0

Thank you!

Thank you for reply @RobertLucian.
I am now sure that I2C-connected modules are unmanaged by on-board AVR microcontroller with the latest firmware, and I can choose any library for application programs to handle with. Your introduction of periphery would be very good for my project.

Hi @kayeksspectrum,

I’m glad to hear you got a clear view of what it can be done. If there any more questions/problems, please let us know.

Thank you!