#MicroPython: Camera stabilisation application
MicroPython | 2 min | 4960
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
ulinalglibraries to the project to make matrix multiplication and quaternion to Euler conversion. The
ahrslibrary 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.
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.
Fig. 1: WiPy, MPU6055 & MicroServos
Signal/Cable Color 5V Red GND Black 3.3V Yellow
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!
The code program can be found on:
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.
If you need to build a tripod for your camera, Thingiverse is a nice website to start with.
Hola, tengo un error con MPUException: No MPU's detected
Estoy usando un MPU-6050
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.