I2c conections beetween pyboard and accelerometer W61P

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
zaord
Posts: 96
Joined: Fri Jan 31, 2020 3:56 pm

I2c conections beetween pyboard and accelerometer W61P

Post by zaord » Thu Mar 24, 2022 9:03 pm

Hi !
I try to get working the accelerometer W61P with micropython.

The documentation of all the i2c adresses are described here : https://drive.google.com/file/d/1d0UI3R ... sp=sharing

My verry simple code is here :

Code: Select all

from machine import Pin, I2C
import utime 
# construct spi
bus=I2C(scl=machine.Pin('Y9'), sda=machine.Pin('Y10'),freq=400000)
# send 0x2000 to soft reset sensor and wait 3 sec
re = bytearray([0x1a,0x40,0x00])
bus.writeto(0x50,re)
re2 = bytearray([0x00,0,0x00])
#bus.writeto(0x50,re2)
utime.sleep(1)
#scan for the sensor address
print(bus.scan())

while True :
    #Initialize Sensor send 0x1000 to sensor to start continuous measurement
    buf_angle = bus.readfrom_mem(0x50,0x3d,6)

    X_Angle = ((buf_angle[1]<<8)|buf_angle[0])/32768*180
    Y_Angle = ((buf_angle[3]<<8)|buf_angle[2])/32768*180
    Z_Angle = ((buf_angle[5]<<8)|buf_angle[4])/32768*180
    print('X_Angle',X_Angle,'Y_Angle',Y_Angle,'Z_Angle',Z_Angle)

    buf_angular_velocity = bus.readfrom_mem(0x50,0x37,6)
    X_AngVelocity = ((buf_angular_velocity[1]<<8)|buf_angular_velocity[0])/32768*2000
    Y_AngVelocity = ((buf_angular_velocity[3]<<8)|buf_angular_velocity[2])/32768*2000
    Z_AngVelocity = ((buf_angular_velocity[5]<<8)|buf_angular_velocity[4])/32768*2000
    print('X_AngVelocity',X_AngVelocity,'Y_AngVelocity',Y_AngVelocity,'Z_AngVelocity',Z_AngVelocity)


    buf_acceleration = bus.readfrom_mem(0x50,0x34,8)
    print(buf_acceleration)
    X_Acc = ((buf_acceleration[1]<<8)|buf_acceleration[0])/32768*16
    Y_Acc = ((buf_acceleration[3]<<8)|buf_acceleration[2])/32768*16
    Z_Acc = ((buf_acceleration[5]<<8)|buf_acceleration[4])/32768*16
    Temp  = ((buf_acceleration[7]<<8)|buf_acceleration[6])/32768*16
    print('X_Acc',X_Acc,'Y_Acc',Y_Acc,'Z_Acc',Z_Acc)
    print('temp',Temp)
    
    break

I get some problems.
1) I can't manage to change the i2c adress of this chip.
I tried to do that according to the sec 5.2.28 of the documentation (link above)

Code: Select all

re = bytearray([0x1a,0x40,0x00])
bus.writeto(0x50,re)
re2 = bytearray([0x00,0,0x00])
bus.writeto(0x50,re2)
utime.sleep(1)
The first line is suppose to change the adress and the second one to save the new adress, but after restarting the chip, nothing change...


Second problem, I get some weird values for the acceleration :

Code: Select all

buf_angle = bus.readfrom_mem(0x50,0x3d,6)

    
    buf_acceleration = bus.readfrom_mem(0x50,0x34,8)
    print(buf_acceleration)
    X_Acc = ((buf_acceleration[1]<<8)|buf_acceleration[0])/32768*16
    Y_Acc = ((buf_acceleration[3]<<8)|buf_acceleration[2])/32768*16
    Z_Acc = ((buf_acceleration[5]<<8)|buf_acceleration[4])/32768*16
    Temp  = ((buf_acceleration[7]<<8)|buf_acceleration[6])/32768*16
    print('X_Acc',X_Acc,'Y_Acc',Y_Acc,'Z_Acc',Z_Acc)
    print('temp',Temp)
    
The temp is egal to zero, and the Y_Acc is 30 and constant, even if the sensor is stead on my table ...

I'am sure is just a little small things, but I did not find my way alone, so thanks by advance if you find something that could help !

Post Reply