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

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Module 120 accelerometer communications
« on: October 01, 2016, 07:50:39 pm »
So, back from the road, and my 120 modules have arrived!

I set them up, with the hope of making some progress on a library for the new accelerometer.

First, a lot of trouble connecting and downloading code (even with the latest firmware, mcStudio etc.). The module has to be really close to the Gateway for it to download reliably. I mean inches away.

But, figured that out.

Now, can't talk to the accelerometer. Some odd behavior, if I set the I2C speed to 400kHz, the whole module hangs (have to "delete code" to recover). Set to 250kHz, it seems OK. I2C address set to 0x19.

So trying at 250kHz, first step is to read the WHO_AM_I register (either 0x0f or 0xaf - depending on register auto increment or not), this should yield 0x33. No matter what I try, I read 0. And it actually reads 0, not just "nothing". Trying to read other registers also yields 0.

I have checked the I2C data sequence, and it seems to be the same as the 110 module accelerometer (which works).

Does anyone have some example code using the new accelerometer (just who_am_i would be fine)?
I'm not sure if this is a bug (the hang at 400kHz is worrying), or something I'm missing.

Any help with the 120 module accelerometer would be appreciated.

Share on Facebook Share on Twitter


mc-Josh

  • Global Moderator
  • Newbie
  • *****
  • Posts: 27
    • View Profile
Re: Module 120 accelerometer communications
« Reply #1 on: October 03, 2016, 10:17:01 am »
Nick,

Just to be sure, are you using the latest versions of the mcMod120 firmware and mcStudio? Also, there is currently a bug on the mcMod120s with using the I2C at 400kHz so the bus can only be used at 250kHz or 100kHz.

Also, I have attached a very preliminary LIS2DH12 driver and test script. Please give it a try and let me know how it goes.

Thanks,

mc-Josh
Useful Useful x 1 View List

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #2 on: October 03, 2016, 10:29:11 am »
Thank you Josh!

Just what I was looking for. That explains the hang at 400kHz, so I'll just go with 250kHz right now.

I am using the latest FW and mcStudio (as far as I know).

The example should get me going, it looks to be the same as what I am doing, but we'll see when I get into it...

Thanks again!

mc-Josh

  • Global Moderator
  • Newbie
  • *****
  • Posts: 27
    • View Profile
Re: Module 120 accelerometer communications
« Reply #3 on: October 04, 2016, 03:05:01 pm »
Nick,

Were you able to get the LIS2DH12 up and running?

Thanks,

Josh

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #4 on: October 04, 2016, 03:06:46 pm »
Haven't had a chance to get to it just yet (doing the work thing). Maybe tomorrow? I'll let you know.

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Module 120 accelerometer communications
« Reply #5 on: October 15, 2016, 06:17:38 pm »
Hello Nick, would you be able to provide an example using the accelerometer on the 120 once you have it figured out?

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Module 120 accelerometer communications
« Reply #6 on: October 15, 2016, 07:13:45 pm »
Looks like the drive and test script Josh provided loaded and executed (no errors) on my 120 but, not sure what the test script is doing. How can I test it?

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #7 on: October 17, 2016, 12:31:25 am »
I haven't had much time to work on it lately, but I do have it working in my door knock sensor code.

I added LedRed on and off, so that I could see the interrupts.

One thing I noticed is that it is very sensitive, triggers at the slightest touch. If you trigger it too much (not very much), the module stops publishing (beacons still work).

I changed the response time from 2ms to 20ms, and it's better.

Not sure why it would stop publishing if you generate too many interrupts though.

I think I was confused about my previous code because the WHO_AM_I register returns a 0 when you query it (I expected 0x33) - so I thought I had a bug in my I2C code, but no, it does return 0. Weird.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #8 on: October 19, 2016, 07:01:58 pm »
Ok, had some time to work on this.

There is a new beta library published on my github site.

It's in projects.

The test code is a version of my door knock program.

It's a beta release, but it covers most functionality. Not fully tested yet.
Like Like x 1 View List

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Module 120 accelerometer communications
« Reply #9 on: November 09, 2016, 09:49:26 am »
When I run the example code for the LIS2DH12 that Josh provided I get the attached error.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #10 on: November 09, 2016, 09:55:17 am »
Yes,

You have to use my code, not his I use different names for some things, and the library works differently. I use "read" and "write" not "readsinglebyte" and so on.

I have implemented lots of methods, so you don't need to use "read" and 'write" directly. Look at the library, or my example, you'll see the difference.

his code won't work with my library. Use mine.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #11 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
        Thread.Sleep(100000)
        Thread.ClearHardwareEvent()
       
        '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.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #12 on: November 09, 2016, 10:37:58 am »
Hmm, just re-read your message. Do you mean you are using Josh's code as-is? ie his beta library?

That did work on my modules (120). This does only work on 120's not 110's.

I just compiled my example (with my library), uploaded it to a 120 module, and it works just fine...

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Module 120 accelerometer communications
« Reply #13 on: November 10, 2016, 09:33:45 am »
Hello Nick,

Apologies, I should have been more specific.

Yes, the error I attached below is while using Josh's code as is and with his library along with the new mod120's that just arrived the other day and latest firmware from mcThings download page.

I wanted to make sure I could execute Josh's example before trying yours.

Any suggestions?

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #14 on: November 10, 2016, 09:44:36 am »
I didn't have any problems other than the device only working at 250KHz (not 400), and the whoami returning 0 confused me for a while.

Have you just tried uploading and running it? seems an odd place for a breakpoint. I also haven't seen that error message before, when I tested, and got problems the error message was "I2C Bus is locked".

Do you have a screenshot of what you actually get?