Author Topic: Tilting Trigger on the Accelerometer  (Read 3985 times)

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Tilting Trigger on the Accelerometer
« on: January 10, 2017, 11:33:25 am »
Hi SK,

1) Yes, you can use the accelerometer to wake up the mcDemo205
2) Yes, you can write a code that allows the device to wait until it does not detect movement again and then send that information via SIGFOX
3) No, the mma8625 library is for the accelerometer on the mcmod110. the mcMod120 and the mcDemo205 use the LIS2DH12 accelerometer library. Here is a link to the datasheet for this accelerometer: http://www.st.com/content/ccc/resource/technical/document/datasheet/12/c0/5c/36/b9/58/46/f2/DM00091513.pdf/files/DM00091513.pdf/jcr:content/translations/en.DM00091513.pdf


You can find the correct library here (Thanks to Nick_W!): https://github.com/NickWaterton/mcScript/tree/master/projects/DoorSensor%20-%20120 . You can also check out Nick's script that uses the accelerometer to detect a knock. You can modify this to your use-case.

Also, this may help:

http://mcthings.createaforum.com/support/accelerometer-events/msg1139/#msg1139

We released a beta version of a garage door open/closed detection using the accelerometer on the mcMod110 (MMA8652 accelerometer). You could use some of this code (modified to use the LIS2DH12 library). You can also take sections for dmm's code (http://mcthings.createaforum.com/mc-innovations/accelerometer-code-help/msg1303/#msg1303) for relaying the tilt value and using the above different codes, can incorporate the interrupt function to relay that information.

I would recommend looking through the mcScript guide (https://static1.squarespace.com/static/5644f11fe4b0d6ca7d80d351/t/57c61f35b8a79ba9708b2cc4/1472601916268/mc-ScriptUserGuide.pdf) to become familiar with the different functions available within the programming language. This document should help you to write the wait time required before sending the information out via SIGFOX.
There are two accelerometer interrupts available so you may want to look at using both interrupts for your code. maybe something like:
1) have the accelerometer 'wake up' when it detects movement
2) have the accelerometer detect when it has stopped moving
3) wait a specific period of time before sending the last tilt axis to the cloud via SIGFOX

I also have an example project that I found in my projects that might also help you out:
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
        Thread.Sleep(100000)
        Thread.ClearHardwareEvent()
       
        'Read Int source register to clear interrupt
        If ((accel.ReadSingleByte(LIS2DH12.INT1_SRC_REG) & LIS2DH12.INT_ACTIVE) = LIS2DH12.INT_ACTIVE) Then
            'interrupt generated
           
            LedRed = Not LedRed
           
        End If
       
        'restart interrupt       
        accel.WriteSingleByte(LIS2DH12.INT1_CFG_REG, 0x2a)
    End Event
End Class
This is a simple example of using the accelerometer to detect movement in any axis and then turn on the LED on the module. A combination of all the codes mentioned and listed above should give you a good starting point to create code specific to your use-case.

Hope that helps!
« Last Edit: January 10, 2017, 11:47:01 am by mc-T2 »
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB