GawiQ
Posts: 12
Joined: Sat Mar 24, 2018 3:31 pm

SPI works/not works in turns

Thu May 17, 2018 11:10 am

Hi
I have a problem running python script which uses SPI to read data from two LIS3DH accelerometers. One is tied to spi0 cs0 and the other to spi1 cs2.
The problem is that it works in turns :? One time I hit 'run' and it works, next time it doesn't and next it works, and next it doesn't...
It's probably some silly problem but I'm a beginner and have no idea how to solve this.
When it works the reading looks like this:

Code: Select all


 -0.453125	 -0.796875	 -0.281250	 0.218750	 0.968750	 0.484375	 3518.711409	 0.000289

 -0.453125	 -0.796875	 -0.281250	 0.218750	 0.968750	 0.484375	 3539.497046	 0.000287

 -0.453125	 -0.796875	 -0.281250	 0.218750	 0.968750	 0.484375	 3542.486486	 0.000287
and when it does not like this:

Code: Select all

 
 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 3545.480981	 0.000288

 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 3521.665827	 0.000290

 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 0.000000	 3512.817420	 0.000291
Here is the code:

Code: Select all

import LIS3DH_SPI_0
import LIS3DH_SPI_1
import time, spidev, sys

#accel = LIS3DH.Accelerometer('i2c',i2cAddress = 0x19)
accel0 = LIS3DH_SPI_0.Accelerometer(spiPort = 0, spiCS = 0)  # spi connection alternative
accel0.set_ODR(odr=5000, powerMode='low')
accel0.axis_enable(x='on',y='on',z='on')
accel0.set_scale(8)

accel1 = LIS3DH_SPI_1.Accelerometer(spiPort = 1, spiCS = 2)  # spi connection alternative
accel1.set_ODR(odr=5000, powerMode='low')
accel1.axis_enable(x='on',y='on',z='on')
accel1.set_scale(8)

t_end = time.time() + 1 
while time.time() < t_end:        
        t = time.time()
        x = accel0.x_axis_reading()/64
        y = accel0.y_axis_reading()/64
        z = accel0.z_axis_reading()/64
        x1 = accel1.x_axis_reading()/64
        y1 = accel1.y_axis_reading()/64
        z1 = accel1.z_axis_reading()/64
        print ("\r %.6f\t %.6f\t %.6f\t %.6f\t %.6f\t %.6f\t %.6f\t %.6f" % (x, y, z, x1, y1, z1, (1/(time.time()-t)), (time.time()-t))) 
where LIS3DH_SPI_0 and LIS3DH_SPI_1 are from here:
https://github.com/owainm713/LIS3DH-Pyt ... /LIS3DH.py

GawiQ
Posts: 12
Joined: Sat Mar 24, 2018 3:31 pm

Re: SPI works/not works in turns

Thu May 17, 2018 8:23 pm

Solved - turns out block data update has to be turned on.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 5 guests