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)