Recent Posts

Pages: [1] 2 3 ... 10
1
mc-Dongle / Re: Erase Failed!!!
« Last post by wxhzk on Today at 11:30:49 am »
Thanks a lot. I tried to use a new battery, and it works.
2
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« Last post by Nick_W on Today at 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.
3
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« Last post by Nick_W on February 26, 2017, 04:51:22 pm »
I think that was more in the way of an example, normally you leave it on true, and you don't need to do any of the other stuff - dummy read, sleep etc, you just read GetAccel().

To explain the HP filter, when it is enabled, it removes the DC component (caused by gravity ie 1). This is what is then used by the interrupt routines (except orientation). So if you want an interrupt to trigger on acceleration of 0.5, with the hp filter on, gravity is ignored, and it triggers when the change of acceleration exceeds 0.5 (otherwise it would trigger all the time as acceleration due to gravity is 1.0).

If you read GetAccel(), you would read 0 for X,Y and Z, unless you were shaking the module or something.

So to get the real reading, you turn hpbypass on, now the readings from GetAccel() are the absolute values (including gravity). The interrupts are not affected, they still use the filtered values.

Anyway, I'll take a look tomorrow, and see what I can do.
4
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« Last post by SK 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?
5
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« Last post by Nick_W on February 26, 2017, 02:45:06 pm »
I'll try this on my 205 tomorrow, first thing I notice is that you keep tuning the HP bypass on and off, why not just leave it on? if you accidentally read with bypass off, you'll just get 0's.
6
mc-Demo205 / Re: Tilting Trigger on the Accelerometer
« Last post by SK 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.
7
Announcements / Re: Announcing mcStudio Version 0.9!
« Last post by Nick_W on February 25, 2017, 07:52:27 pm »
Looks great!

I may have some rewriting to do, but it looks like I can scrap some old work arounds in the process.
Thanks for clearing up the divide confusion, and thanks for arctan2 (now I can get rid of the one I wrote)!

Yeah! for threading and Thread locks. And finally a long data type! Awesome!

Quick question about pins, I see you have methods value and voltage. If I read an analog pin value (not voltage), do I get the underlying digital value ( ie 0 to 1023 or whatever the bit resolution is)? I'm usually interested in the value, not the voltage, so I have to constantly divide by Vref (3600). It would be great to be able to read the value and not the voltage.

Also is it possible to set the analog resolution? I believe it's 14 bits at the moment, but it would be great to set it to say 10. Just a suggestion.

Looking forward to the new release.
8
mc-Studio / Re: mc-Studio not connecting to my devices
« Last post by SK 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.  :-\
9
mc-Module / Re: Erased mcScript and module stopped working
« Last post by Cochrane on February 25, 2017, 12:14:47 am »
I just had the same issue. I have an original mcModule 110 and trying to get into it to do an update. I did the erase script, which went through fine. Then I did Erase database, and it "Erase Failed!" and now I can't connect to it. I've tried a couple batteries, and the red light doesn't flash. I think I bricked it. Also, I had just installed OTA app and mcStudio onto my PC for the first time.
10
Announcements / Re: Announcing mcStudio Version 0.9!
« Last post by bdevlin on February 24, 2017, 01:40:15 pm »
Awesome!. I can code and understand polymorphism, but what about the wizard from the kickstarter for all of the non coders?
Pages: [1] 2 3 ... 10