MicroPython

#MicroPython: Camera stabilisation application!


To continue the series of posts "connecting sensors to MicroPython", this article is about the MPU6055 (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



WiPy 3.0 WiPy 3.0 x 1
MPU6055 MPU6055 x 1
MPU9255 MPU9255 x 1
Micro server 9g Micro server 9g x 1
Camera Tripod Camera Tripod x 1

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/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!

Code

The code program can be found on:

Python Code: https://github.com/lemariva/uPyIMU

The program loads the drivers of the MPU6055 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.

{{ message }}

{{ 'Comments are closed.' | trans }}