Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SK

Pages: [1] 2
1
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: February 27, 2017, 04:41:08 pm »
Thank you. I managed to fix the undefined error.

I'll run some tests with it and figure out the range and values.

This is the raw data I get on sigfox: 23.png

I'm using a online hex conversion website (http://www.scadacore.com/field-applications/programming-calculators/online-hex-converter/) to test if my losant values are correct: 24.png

2
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: February 27, 2017, 03:15:20 pm »
Thank you. Yes I used the motion trigger instead of transient.
If I make getOrientation() Shared and replace calls to getOrientation() with MotionLocation.getOrientation(), then I get and error which says the function is undefined? :/

Also if the range for the axis is between 0 to 1 then why do I get values such as 3.961e+28 for x axis? I'm having trouble understanding the values I get.

3
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: February 26, 2017, 04:16:32 pm »
I don't really understand what that line does, I modified you publish() function and took out the json vars and MQTT lines and left everything else including setFilterBypass.

My getOrientation():
Code: [Select]
Private Function getOrientation(type As Integer) As ListOfByte
        accel.SetFilterBypass(True) 'enable HP filter bypass (so that values read below do not go through HP filter) - this is the normal configuration
        accel.GetAccel() 'dummy read
        Do
            Thread.Sleep((accel.GetmsFromDataRate* 1000).ToInteger) 'wait 1 clock cycle for new unfiltered reading
        While Not accel.NewDataAvailable() 'wait for new data
        Dim accelValues As ListOfFloat = accel.GetAccel()
        Dim PitchRoll As ListOfFloat = accel.GetPitchRollDegrees()
        accel.SetFilterBypass(False) 'disable filter bypass again, this means the *values* given by interrupts (if you are displaying them) will be with HP filter enabled.
       
        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))
       
        Return msgData         
       
    End Function

Your publish() from End Motion program -> https://github.com/NickWaterton/mcScript/blob/master/libraries/accelerometer/lis2dh12/examples/EndMotionTest/EndMotionTest.mcScript:
   
Code: [Select]
Shared Event Publish() RaiseEvent Every 10 Seconds
        accel.SetFilterBypass(True) 'enable HP filter bypass (so that values read below do not go through HP filter) - this is the normal configuration
        accel.GetAccel() 'dummy read
        Do
            Thread.Sleep((accel.GetmsFromDataRate* 1000).ToInteger) 'wait 1 clock cycle for new unfiltered reading
        While Not accel.NewDataAvailable() 'wait for new data
        Dim accelValues As ListOfFloat = accel.GetAccel()
        Dim PitchRoll As ListOfFloat = accel.GetPitchRollDegrees()
        accel.SetFilterBypass(False) 'disable filter bypass again, this means the *values* given by interrupts (if you are displaying them) will be with HP filter enabled.
        Dim jint As Json = New Json
        'NOTE: If you put too much in a json object, it will cause a run time error (overlow) and the module will reboot
        '      Below is too much for one json object, so I've split it into two
       
        Dim jData As Json = New Json
        jData.Add("X_Accel", accelValues(0))
        jData.Add("Y_Accel", accelValues(1))
        jData.Add("Z_Accel", accelValues(2))
        jData.Add("Pitch", PitchRoll(0))
        jData.Add("Roll", PitchRoll(1))
        'jData.Add("PitchAlt", PitchRoll(2))
        'jData.Add("RollAlt", PitchRoll(3))
        If Start_Motion_Detected Then
            jData.Add("State", "Moving")
        Else
            jData.Add("State", "Stationary")
        End If
        MQTT.Publish("Data", jData)
       
        If pin1data.Count() > 0 Then
            jint.Add("Pin1 Count", pin1count) 'number of interrupts generated
            jint.Add("Pin1", pin1data)
        End If
        If pin2data.Count() > 0 Then
            jint.Add("Pin2 Count", pin2count) 'number of interrupts generated
            jint.Add("Pin2", pin2data)
        End If
        If jint.Count> 0 Then
            MQTT.Publish("Ints", jint)
        End If
       
        pin1data.Clear()
        pin2data.Clear()
        pin1count = 0
        pin2count = 0
    End Event

Should I leave it as true?

4
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: February 26, 2017, 02:31:32 pm »
This is my code:
Code: [Select]
// Based off 'End Motion' detection program by Nick Waterton (https://github.com/NickWaterton/mcScript/tree/master/libraries/accelerometer/lis2dh12/examples/EndMotionTest)
// This program detects Start and End of Motion for the MC DEMO 250 module
// After detecting End of Motion, it fires up the GPS and sends the location to Sigfox
// Needs Timing and LIS2DH12(accelerometer) libraries to run
// Libraries by N Waterton 25th January 2017 (https://github.com/NickWaterton/mcScript)

// default configuration is:
// Low Power mode, 50 Hz, 2G
// Sleep mode enabled only when interrupts are enabled (data rate is 10Hz in sleep mode) - wake time is 5 seconds (ie accelerometer wakes up for 5 sconds when threshold is exceeded).
// Motion detection on INT1, pin 1.

// For help go to (http://mcthings.createaforum.com/index.php)
// McScript user guide can be found here (https://www.mcthings.com/downloads/)
// Shaika.K February 2017


Class MotionLocation
    ' Libraries and accelerometer fields
    Shared accel As LIS2DH12 //accelerometer library
    Shared pin1data As Json //a Json object is a list and at each index of the list it stores a name and a value.
    Shared pin2data As Json //to access value at a particular index go (.Item(0).Value().Get___()) eg pin2data.Item(0).Value().Get___()
    //to access name at a particular index go (.Item(0).Name()) eg pin2data.Item(0).Name()
    Shared pin1count As Integer
    Shared pin2count As Integer
    Shared Start_Motion_Detected As Boolean //used to detect start of motion
    Shared End_Motion_Detected As Boolean //used to detect end of motion
    Shared motionStartTime As String
    Shared timer1 As Timing //Timer library
   
    ' Message Types
    Const MSGTYPE_LOCATION As Byte = 1
   
    ' Configuration Constants
    Const GPS_TIMEOUT_uS As Integer = 120000000 '120 second timeout
    Const GPS_MIN_SAT_COUNT As Integer = 3 'minimum satellites to get a fix
   
    ' Battery Status
    Const BAT_CRITICAL As Byte = 0
    Const BAT_LOW As Byte = 1
    Const BAT_NORMAL As Byte = 2
    Const BAT_OPTIMAL As Byte = 3
   
    Shared Event Boot()
        //Lplan.SetMidPowerMode(5000)
        Lplan.SigfoxRadioZone(SigfoxRadioZone.Australia)
        Led2 = False
        Led3 = False
        pin1data = New Json
        pin2data = New Json
        Start_Motion_Detected = False
        End_Motion_Detected = True
        timer1 = New Timing()
        accel = New LIS2DH12
        If accel.online Then
            If LIS2DH12.VERSION < 5 Then
                'Both LED means error on Boot -> LIS2DH12 Library is out of Date, please upgrade!
                Led2 = True
                Led3 = True
            Else
                '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
                'Lplan.Sigfox(accelconfig.Item(0).Value().GetString())
            End If
        Else
            'Led3 means error on Boot -> accel didnt boot
            Led3 = True
        End If
        //MQTT.use_delay = True
        Led2 = True //indicates start of detection
    End Event
   
    Shared Event AccelerometerInt1() //this event is activated after pin1 is initialised and boot finsihes             
        //MOTION/TRANSIENT Detection INT1
        'Read Int source register To clear interrupt And get source
        Dim IntSource As Json = accel.GetInt1SourceAsJson(LIS2DH12.J_VALUES | LIS2DH12.J_SUMMARY)
        If IntSource.Count> 0 Then 'if we have an interrupt (of any kind, x,y or z)           
            MotionLocation.updateTimer(True) //next motion has started
            End_Motion_Detected = False   
            Led2 = False       
        End If         
    End Event
   
    Shared Event MotionCheck() RaiseEvent Every 10 Seconds //change time to max time without motion to detect (actual time could be double this in theory)
        If Start_Motion_Detected And End_Motion_Detected Then //no motion in last 10 seconds
            MotionLocation.updateTimer(False) //motion ended
        End If
       
        End_Motion_Detected = True               
       
    End Event
   
    Shared Function updateTimer(motion As Boolean) As Nothing
        If motion Then
            If Not Start_Motion_Detected Then //not old "start motion" but new one
                motionStartTime = Timing.GetTimestamp(TIME_FORMAT.T_SECONDS)
                timer1.GetTimeSpan() 'start timer
                Start_Motion_Detected = True
                Led2 = True
                Thread.Sleep(50000)
            End If
        Else
            Dim motionStopTime As String = Timing.GetTimestamp(TIME_FORMAT.T_SECONDS)
            Dim duration As Integer = (timer1.GetTimeSpan() / 1000).ToInteger         
            Start_Motion_Detected = False
            Thread.Sleep(50000)   
            Led2 = False
            Lplan.Sigfox(getOrientation(0)) 'send message to sigfox
            Thread.Delay(20000000)
            Lplan.Sigfox(getOrientation(1)) 'send message to sigfox
            Thread.Delay(20000000)
            Lplan.Sigfox(getOrientation(2)) 'send message to sigfox
            Thread.Delay(20000000)
            Led3 = True   
            Device.StartGPS(GPS_TIMEOUT_uS, GPS_MIN_SAT_COUNT)           
        End If
    End Function
       
    'runs after GPS starts up, when GPS location has been aquired OR timeout has been reached
    Shared Event LocationDelivery()
        Dim msg As ListOfByte = New ListOfByte() 'message to send to sigfox
       
        Dim Lat As Float = Device.GetLatitude()
        Dim Lon As Float = Device.GetLongitude()       
       
        'if GPS timed out when retrieving location
        If Lat.IsNaN() Then
            Lat = 0.0 'lattitude is 0
        End If
        If Lon.IsNaN() Then
            Lon = 0.0 'longitude is 0
        End If
       
        msg.Add(0x00) '00 is an indication to Losant that this payload contains location data
        msg.AddFloat(Lat)
        msg.AddFloat(Lon)       
       
        Lplan.Sigfox(msg) 'send message to sigfox
        Led3 = False 'turn off Led to indicate transmission complete     
    End Event
   
    Private Function getOrientation(type As Integer) As ListOfByte
        accel.SetFilterBypass(True) 'enable HP filter bypass (so that values read below do not go through HP filter) - this is the normal configuration
        accel.GetAccel() 'dummy read
        Do
            Thread.Sleep((accel.GetmsFromDataRate* 1000).ToInteger) 'wait 1 clock cycle for new unfiltered reading
        While Not accel.NewDataAvailable() 'wait for new data
        Dim accelValues As ListOfFloat = accel.GetAccel()
        Dim PitchRoll As ListOfFloat = accel.GetPitchRollDegrees()
        accel.SetFilterBypass(False) 'disable filter bypass again, this means the *values* given by interrupts (if you are displaying them) will be with HP filter enabled.
       
        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))
       
        Return msgData         
       
    End Function
   
End Class

Am I doing things correctly?
I got the values x = 5.603067e-39, y = 5.557149e-39, z = 1.75883332e-38 when I shook the the device and laid it on its back like normal.

5
mc-Studio / Re: mc-Studio not connecting to my devices
« on: February 25, 2017, 03:52:45 am »
I updated the Studio on Friday (17th Feb) and then the firmware on my Demo 205 on Wednesday (22nd Feb). Then when I created a new project and tried to connect, the Testboard gateway connected but then couldn't find my device.
I closed the studio and then re-opened and tried again but it still didn't work.
I closed the project and then studio and then reopened it (so it would open without any projects already on it) and tried to connect but it didn't work. I kept trying 4 or 5 more times and even waited 20-30 min for it to find my device.
I checked my FTDI drivers but they were the latest version so as a last resort I uninstalled and then reinstalled the same latest version of studio and then immediately connected my device before opening any projects. This worked and I have had no further problems with connecting so far.

I'm not sure what made it finally work.  :-\

6
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: February 24, 2017, 03:20:27 am »
Nick your accelerometer/timer libraries and examples have been so helpful. Thank you so much.

I managed to get a program working which sends x, y, and z values followed by the location to sigfox at the end of movement. However, I was wondering what the x, y, z values meant? What units are they in?

Eg. I got x = 5.603067e-39, y = 5.557149e-39, z = 1.75883332e-38.
 :-[

7
mc-Studio / Re: mc-Studio not connecting to my devices
« on: February 23, 2017, 07:17:10 pm »
I reinstalled Studio and connected to device before opening up my project. It seems to have worked but very unstable. Pls fix!

8
mc-Studio / Re: mc-Studio not connecting to my devices
« on: February 23, 2017, 06:05:19 pm »
I recently installed the new version of Studio and updated my device firmware but now I can't connect my device.

I go Tools -> Device -> Connect Testboard Gateway -> My device doesn't appear and I've waited 20min.

What can I do?

9
mc-Demo205 / Re: New accelerometer library for Demo 205 released!
« on: January 25, 2017, 09:34:11 pm »
Yay! Nice work.
Thank you!  :D

10
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« on: January 11, 2017, 07:27:15 pm »
Thanks for the feedback.

I just wanted to check if the MMA8652 could be used for the 205 since it already has a interrupt on orientation function in it.
I've been able to use the LIS2DH12 to detect movement, but I'm not sure on where to begin with figuring out how to detect/wake on change in orientation.
The functions from the LIS2DH12 library 'accel.Accel(LIS2DH12.X_AXIS)', 'accel.Accel(LIS2DH12.Y_AXIS)' and 'accel.Accel(LIS2DH12.Z_AXIS)' all return 0 but I haven't yet figured out why.

 :-\

11
mc-Demo205 / Wake up on Temperature
« on: January 11, 2017, 06:03:22 pm »
Is there a way to wake the module only when the temperature reaches below a certain degrees?
The data sheet for tmp102 http://www.ti.com/lit/ds/symlink/tmp102.pdf says that there is a 'interrupt mode' which could be used? Does this apply to the demo 205?

Cheers

12
mc-Demo205 / Tilting Trigger on the Accelerometer
« on: January 09, 2017, 06:48:10 pm »
Hi all,
Just a couple of questions on the x, y, z sensor on the accelerometer:
  • Is there a way to wake up the MC205 on change in axis?
  • Is there a way to make it wait until the device has stopped tilting and report to sigfox the final axis it has tilted to?
  • Can I use the MMA8652 library that comes with MCStudio for this?

I've looked at dmm's tilt code(http://mcthings.createaforum.com/mc-innovations/accelerometer-code-help/msg1303/#msg1303) but instead of waking up every 30 sec, I'd like it to only wake up only when it has changed orientation.
Cheers

13
mc-Studio / Re: MC-Studio Crashes on start up, even after re-installing
« on: December 19, 2016, 06:40:47 pm »
I've uninstalled it again and deleted every file and folder to do with mc, and then re-installed and and now it works!
The settings.xml has returned too!

I think the problem was that when it uninstalled, it didn't erase all the files. So when re-installing, if it found an already existing folder called mcThings, it wouldn't rewrite it with a fresh new copy.

I'll keep that in mind next time.
Thanks!

14
mc-Studio / Re: MC-Studio Crashes on start up, even after re-installing
« on: December 19, 2016, 05:53:58 pm »
There is no Settings.XML file
I've attached a screen shot of the folders in the mcStudio folder

15
mc-Studio / MC-Studio Crashes on start up, even after re-installing
« on: December 19, 2016, 03:37:02 pm »
MC studio crashes when I try to open it.

It says it can't find a file:
Code: [Select]
ERROR in mcStudio supporting thread.
System.IO.DirectoryNotFoundException: Could not find a part of the path...
even though the file is in the right folder.

Then it gives another error:
Code: [Select]
ERROR in mcStudio.
System.NullReferenceException: Object reference not set to an instance of an object.
at mcEditControl.Editor.get_Row()
...
and then crashes.

I've tried re-installing several times but it gives the same error.

Pages: [1] 2