Manage cookies

We use cookies to improve our services. Read more about how we use cookies and how you can refuse them.

The necessary cookies help to make the website work properly.

Anonymous statistical cookies help to understand how visitors use the website.

  • MicroPython
    2 min | 5399

    #MicroPython: Camera stabilisation application

    MicroPython | 2 min | 5399


    To continue the series of posts "connecting sensors to MicroPython", this article is about the MPU6050 (you can use also the MPU9255, I am still waiting for the Chinese sensor package) and the WiPy 3.0. Combining the IMU sensor with the WiPy and two micro servos 9g, it is possible to stabilize a camera (tilt/rotate).

    To calculate the compensation needed for the stabilisation, I added the umatrix, quaternion and ulinalg libraries to the project to make matrix multiplication and quaternion to Euler conversion. The ahrs library from Madgwick fusions the data of the accelerometer, gyroscope (and magnetometer, only with MPU9255) and allows to calculate the rotation of the IMU in quaternion coordinates. I rewrote (most of) the libraries to be compatible with MicroPython.


    Hardware

    Connections

    The capacitors connected to the micro servos 9g are for the peak current consume of the servos, when the position is quickly changed. E.g. if you change the position from 0° to 180°, the current peak reaches about 1.2A, then the voltage (5v) drops down, and the motor does not move smoothly. You can choose a bigger power supply, or you can put some capacitors (I used 4700uF - that's too big, a smaller should also work.) near the servos.

    WiPy 3.0, MPU6055 & Micro Servo 9g
    Fig. 1: WiPy, MPU6055 & MicroServos

    Cable description


    Signal/CableColor
    5VRed
    GNDBlack
    3.3VYellow

    The 3.3V (yellow) is supplied by the WiPy board. The WiPy board needs 5V (top right pin or over USB). If you use the USB from your computer to power your WiPy, this 5V cannot be used for the servos! You need an external power supply!

    Code

    The code program can be found on:

    PythonCode: https://github.com/lemariva/uPyIMU

    The program loads the drivers of the MPU6050 and the Micro Servo 9g and connects to a Wi-Fi router. You need to modify the SSID and wpa-password variables in the file boot.py. Use Atom and the plugin Pymakr to upload the program to the board.

    The sample rate of the application is limited to 150 ms. Optimization is needed to reduce the time needed to acquire the data, process it and calculate the angles which are sent to the servos.

    Camera

    If you need to build a tripod for your camera, Thingiverse is a nice website to start with.


    Comments

    Paula 11.20.2020

    Hola, tengo un error con MPUException: No MPU's detected

    Estoy usando un MPU-6050

    Muchas gracias

    LeMaRiva|tech 11.22.2020

    Hola Paula, checkea los cables, o bien el orden de los pin. Me suena que tienes el SDA y SCL cambiados. Sino, prueba solo cargando el modulo I2C y has un scan del bus. Te tendría que salir un tuple con las direcciones de los dispositivos conectados.

    from machine import I2C, Pin
    i2c = I2C(sda=Pin(...), scl=Pin(...)....)
    i2c.scan()