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

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Tilting Trigger on the Accelerometer
« on: February 27, 2017, 09:33:38 am »
Ok, I have it working, as is!.

There are a couple of problems, mostly minor. First, your GetOrientation() function is declared as Private, which is not valid (but does work due to a bug in mcStudio) it should be shared, and then referenced as MotionLocation.GetOrientation(). You can leave it as it is, but just note that this is not strictly a valid definition.

Second, you have mixed two of my examples together. The "EndMotion" example uses accel.ConfigureTransientInterrupt(0.15, 20.0, 1, 1, True), which you have changed to accel.ConfigureMotionInterrupt(1.15, 20.0, 1, 1, True). This is important as they are two similar but different things.

ConfigureTransientInterrupt uses the High Pass filter, hence the example has all the enabling and disabling of hpbypass to get absolute values.
ConfigureMotionInterrupt does not use the High Pass filter, so no manipulation of hpbypass is needed to get absolute values, but the threshold value has to be greater than 1.0 to prevent the interrupt triggering constantly because of earths acceleration due to gravity.

Having said that, it doesn't matter, you just don't need it.

So substituting MQTT.Publish for your SigFox publishing (we don't have SigFox in Canada), I get this:

Code: [Select]
MCThings/00020004/Sigfox 0 -0.064000
MCThings/00020004/Sigfox 1 0.064000
MCThings/00020004/Sigfox 2 -1.008000
MCThings/00020004/Sigfox GPS 43.601692,-79.708992

Which looks correct (Z is -1 as it depends which way up the module is). This is without changing your code.

I would remove the hpbypass stuff as you don't need it (you don't need accel.ReadConfiguration(0) either unless you want to see the accelerator configuration):

Code: [Select]
    Private Function getOrientation(type As Integer) As ListOfByte
        Dim accelValues As ListOfFloat = accel.GetAccel()
        Dim PitchRoll As ListOfFloat = accel.GetPitchRollDegrees()

        Dim msgData As ListOfByte = New ListOfByte()
        msgData.Add(0x08) '08 is an indication to Losant that this payload contains location data
        msgData.AddInteger(type)
        'msgData.AddFloat(accelValues(0)) //x
        msgData.AddFloat(accelValues(type)) //y
        'msgData.AddFloat(accelValues(2)) //z
        'msgData.AddFloat(PitchRoll(0))
        'msgData.AddFloat(PitchRoll(1))
        Dim top_msg As String = "Sigfox " + type.ToString()
        Dim msg_payload As String = accelValues(type).ToString()
        MQTT.Publish(top_msg, msg_payload)
        Return msgData         
       
    End Function

Boot() event
Code: [Select]
'Nicks's setup:                 
                accel.Setup(LIS2DH12.LOW_POWER_MODE, LIS2DH12.DATA_RATE_50HZ, LIS2DH12.SCALE_2G)               
                accel.ConfigureMotionInterrupt(1.15, 20.0, 1, 1, True) 'INT1 pin 1, Latched. Pin 1 activates AccelerometerInt1()
                'accel.ConfigureTransientInterrupt(0.15, 20.0) 'same as above
                'accel.ConfigureTransientInterrupt(0.15, 20.0, 1, 1, True, LIS2DH12.INT_SRC_YH) ' as above, but only Y High axis interrupt enabled
                'accel.SetFilterBypass(False) 'disable HP filter bypass (values read will be with HP applied - usually this is enabled, or you just read 0's with interrupts enabled, but gets re-enabled in Publish() )
               
                'To publish a paramterer value to Sigfox insert the corresponding number.
                '0= general control registers
                '1= Interrupt 1 settings
                '2= Interrupt 2 settings
                '3= Click Interrupt settings
                '4= Misc others
                'Dim accelconfig As Json = accel.ReadConfiguration(0) //general control registers
                MQTT.Publish("Status", "Online")
                'Lplan.Sigfox(accelconfig.Item(0).Value().GetString())

If you are getting 0's in losant, its due to something else. I do notice that you are publishing to SigFox every 20 seconds. This does not seem allowable by SigFox, as they restrict you to 140 messages per day, or one per 10 minutes. Maybe they don't restrict frequency, just the total number per day - as I say we don't have SigFox so I don't know. Once per 20 seconds does seem a bit fast for SigFox though.

Anyway, your code does work as is. Your problem is elsewhere.

Hope this helps.
« Last Edit: February 27, 2017, 09:47:54 am by Nick_W »