Maandelijks archief: augustus 2016

How to enable Motion Detection Interrupt on MPU6050.

The MPU6050 data sheet has a nice “marketing” section, claiming it has a DMP unit, and a couple of useful interrupts, among them a accelerometer event interrupt.

However, how to actually use these features is not documented there. And I want to use the Motion Detection Interrupt (so I can put the host MCU to sleep and wake it up when the MPU6050 senses motion – quite probably there’s a cheaper and better documented chip that can do this too, but I already bought a few MPU6050’s… “gy521” breakout board).

http://www.i2cdevlib.com/devices/mpu6050#registers is a in progress development to reverse engineer how to use the DMP. It also has a very useful register map (Thanks!), that fills the gaps in the “RM-MPU-6000A-00” document. With that register map, and a slightly older data sheet that actually has the section 8.3 that’s referred to elsewhere (found at https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/General%20IC/PS-MPU-6000A.pdf , but that URL seems like it might not stay.), I could figure out how to enable the Motion Detection Interrupt.

After power on (0x00 to register (decimal) 107), the Motion Detection Interrupt can be enabled as follows:

  • (optionally?) Reset all internal signal paths in the MPU-6050 by writing 0x07 to register 0x68;
  • write register 0x37 to select how to use the interrupt pin. For an active high, push-pull signal that stays until register (decimal) 58 is read, write 0x20.
  • Write register 28 (==0x1C) to set the Digital High Pass Filter, bits 3:0. For example set it to 0x01 for 5Hz. (These 3 bits are grey in the data sheet, but they are used! Leaving them 0 means the filter always outputs 0.)
  • Write the desired Motion threshold to register 0x1F (For example, write decimal 20).
  • To register 0x20 (hex), write the desired motion duration, for example 40ms.
  • to register 0x69, write the motion detection decrement and a few other settings (for example write 0x15 to set both free-fall and motion decrements to 1 and accelerometer start-up delay to 5ms total by adding 1ms. )
  • write register 0x38, bit 6 (0x40), to enable motion detection interrupt.

Translate the above into code for your favourite micro controller. (Or, maybe, the existing Arduino library for MPU6050 already supports this. I don’t know, I’m using STM32 this time. But it could be translated to AVR/PIC/MSP430 etc… as long as it has I2C/TWI)

Now, INT pin should go high when MPU6050 is moved/shaken/dropped. Play with threshold, duration and filter to set sensitivity.

Relevant excerpt from the linked older data sheet (PS-MPU-6000A-00 Revision: 3.1) above:

8.3 Motion Interrupt
The MPU-60X0 provides Motion detection capability with similar functionality to Free Fall detection. Accelerometer measurements are passed through a configurable digital high pass filter (DHPF) in order to eliminate bias due to gravity. A qualifying motion sample is one where the high passed sample from any axis has an absolute value exceeding a user-programmable threshold. A counter increments for each qualifying sample, and decrements for each non-qualifying sample. Once the counter reaches a user-programmable counter threshold, a motion interrupt is triggered. The axis and polarity which caused the interrupt to be triggered is flagged in the MOT_DETECT_STATUS register.

Like Free Fall detection, Motion detection has a configurable acceleration threshold MOT_THR specified in 1mg increments. The counter threshold MOT_DUR is specified in 1 ms increments. The decrement rate has the same options as Free Fall detection, and is specified in the MOT_DETECT_CTRL register.

HH! Comment section below is open (no login required) for questions & remarks!

Fine motor skills?

I did not know this was possible.

The hollow core motors of a Cheerson CX-10 can actually be opened, and a new wire can be soldered to the brushes when the original one broke of.

IMG_7643_holowcoremotor

This started as a challenge, me stating it was impossible to open these motors without damaging them beyond repair and my father insisting it is possible. So don’t ask me how to open them, I still think it is impossible. I only soldered the wire and closed it again. (Make a hole for the new wire by removing all residue of the old wire, remove part of the glue over the brushes, tin the new wire, then very quickly solder it, as to not overheat the plastic. Carefully press the back back on the motor again, making sure the brushes don’t bend in ways they are not supposed to)

IMG_7642_holowcoremotor

And now my CX-10 is flying again. With a battery that’s slightly to large, a half-painted side to help orientation (Does not actually help), and rubber bands instead of screws holding it together. Also, half its props are pink because those where the last ones I had around. So its almost as ugly as possible, but it’s flying again. And that’s kind of crazy.

cx10

(And yes, I bought new motors just in case, and I still think this repair should be above my fine motor skills (pun intended) as everything is way to tiny and way to melt-able, but apparently its less impossible then I thought.)