Author Topic: Module 120 accelerometer communications  (Read 556 times)


  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« on: November 09, 2016, 10:33:43 am »
Hope this helps,

Here is the equivelent of Josh's example code, but using my library:

Code: [Select]
Class LISDH12_Test
    Shared accel As LIS2DH12
    Shared Event Boot()
        accel = New LIS2DH12
        'set accelerometer to cause interrupt if accelation is > 1.15Gs for longer than 2ms (any axis)
        accel.ConfigureShockInterrupt(1.15, 2.0)
    End Event
    Shared Event AccelerometerInt1()
        'debounce interrupt
        'Read Int source register to clear interrupt
        If ((accel.GetINT1ActiveInterrupt() & LIS2DH12.INT_ACTIVE) = LIS2DH12.INT_ACTIVE) Then
            'interrupt generated
            LedRed = Not LedRed
        End If
        'restart interrupt       
        accel.SetINT1ActiveInterrupt(LIS2DH12.INT_SRC_XH | LIS2DH12.INT_SRC_YH | LIS2DH12.INT_SRC_ZH)
    End Event
End Class

You can see that I don't use read (or readsinglebyte) or write directly.

I do plan to re-write this using Millenials method of passing strings - so much easier!

make sure you have the latest firmware! much more reliable.