Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Detect car crash G force with accelerometer

    Scheduled Pinned Locked Moved Discussion
    7 Posts 2 Posters 373 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      shaunix
      last edited by

      I know how to wake on accelerometer interrupt when sleeping but is it possible to detect a car crash or hard brake while a program is running? I assume that it would have to run in a separate thread (if that is even possible).

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @shaunix
        last edited by

        @shaunix You can probably just set up the accelerometer the same way as for wake up, and add a trigger on the pin going high.

        It should be much more efficient than constantly reading from the accelerometer just to detect if it goes over a threshold.

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          shaunix
          last edited by

          That makes sense. Thanks for pointing me in the right direction.

          1 Reply Last reply Reply Quote 0
          • S Offline
            shaunix @jcaron
            last edited by

            @jcaron So I managed to trigger the event but now I need to figure out how to return the G value. I'm using the LIS2HH12.py library found in the examples. acceleration() returns (x,y,z) and now I have to figure out how to get the G force. It is not clear to me how the G threshold that is passed is compared to the actual G force generated. I assume there is a calc in there somewhere but it is not obvious to me.

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jcaron @shaunix
              last edited by

              @shaunix do you actually need to get the value, or do you just need to be sure it exceeds the given threshold?

              Have you read the accelerometer’s data sheet? It’s the best source of information on the subject, though it has a few errors IIRC.

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                shaunix @jcaron
                last edited by

                @jcaron I'd like the value so I can assess how severe the force was before deciding how to act/report. Hard brake or collision for example.

                This code spits out (x,y,z):

                def acceleration(self):
                        x = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_X_L_REG, 2)
                        self.x = struct.unpack('<h', x)
                        y = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_Y_L_REG, 2)
                        self.y = struct.unpack('<h', y)
                        z = self.i2c.readfrom_mem(ACC_I2CADDR , ACC_Z_L_REG, 2)
                        self.z = struct.unpack('<h', z)
                        _mult = self.SCALES[self.full_scale] / ACC_G_DIV
                        return (self.x[0] * _mult, self.y[0] * _mult, self.z[0] * _mult)
                

                So I think I need to use a formula to calculate the g force from these values. I think

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jcaron @shaunix
                  last edited by

                  @shaunix just compute the magnitude of the vector...

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom