Library 43- MPU-6050 6-axes gyro and accelerometer for STM32F4

Posted on October 28, 2014 at 9:51 PM
MPU-6050 6-axes gyroscope and accelerometer

MPU-6050 6-axes gyroscope and accelerometer

MPU-6050 is a 3-axes accelerometer and 3-axes gyroscope MEMS sensor in ona piece. It can also measure temperature. It is very cheap device but also very powerful. It can measure simultaneously three (X, Y and Z) channels for accelerometer and gyroscope at the same time with 16-bit resolution. This chip is also compatible with MPU9150, except that MPU9150 has 3axes magnetometer (or compass) included.

MPU-6050 Features

  • Accelerometer
    • 4 selectable full scales (2G, 4G, 8G and 16G)
  • Gyroscope
    • 4 selectable full scales (250°, 500°, 1000° and 2000°)
  • Temperature sensor
    • 1°C accuracy
  • I2C driven
    • Selectable LSB bit for I2C address, used with AD0 pin
      • AD0 low: I2C address is 0xD0
      • AD0 high: I2C address is 0xD2
    • Max SCL speed is 400kHz

Library

Features

  • Read accelerometer data
  • Read gyroscope data
  • Read temperature
  • Read everything above in one single function or separatelly
  • Use 2 independent MPU-6050 devices on the same I2C bus
    • Devices must have different AD0 pin state

Continue reading

Library 42- Control RC servo with STM32F4

Posted on October 26, 2014 at 11:28 PM

Library 42 allows you to simple connect and interface RC servo motors with STM32F4. They are small, cheap motors, commonly used for RC (Radio Control), small scale robotics and more.

Servos are really simple to interface. They expect 50Hz signal on the input. According to the pulse length (duty cycle) they rotate between 0 and 180 degrees. If signal has 1ms pulse length, motor rotation will be 0 degrees and if signal has 2ms length, then it will have 180degrees rotation. Any pulse length between will set degrees linear to the value.

Equation for pulse length to get specific rotation is:

Pulse length (degrees) = (MAX – MIN) * degrees / 180 + MIN

where:

  • MAX: maximum pulse length for servo, 2000us
  • MIN: minimum pulse length for servo, 1000us

If you want to get rotation in degrees from know pulse length:

Degrees (pulse_length) = (pulse_length – MIN) * 180 / (MAX – MIN)

Library

Features

  • Control RC servo motors
  • Number of available servos depends in STM32F4xx chip you will use
    • More timers means more servos possible

Continue reading

STM32F4 FFT example

Posted on October 23, 2014 at 9:22 PM

As you maybe know, STM32F4 is Cortex M4 with DSP instructions. This allows you to make a FFT with a few simple steps. For that purpose, I have made an example, on how to create FFT with STM32F4.

When the ARM company issued Cortex-M4 core, it also published DSP libraries for mathematics and other stuff. And there are also FFT functions. When you’ve downloaded ST’s standard peripheral drivers, you also downloaded CMSIS (Cortex Microcontroller Software Interface Standard), which are designed for all Cortex-M4 processors from every company.

CMSIS libraries are also included in Keil uVision (5 and newest), you just need to enable them. Under “Manager Run-Time Environment” -> CMSIS select DSP. DSP or Digital Signal Processing is a library for “high mathematics” instructions, which are supported by Cortex-M4 with floating point unit.

Enable DSP library in Keil uVision

Enable DSP library in Keil uVision

Fast Fourier Transform – FFT

Very fast about FFT. FFT or Fast Fourier Transform is an algorithm to convert time based signal into frequency domain. In other words, you are able to know from which sinus components is some signal created.

Everything about FFT is described on Wikipedia.

Continue reading

Library 41- STDIO implementation for STM32F4

Posted on October 19, 2014 at 1:51 AM

After I made a tutorial on how to use printf with STM32F4, I decided to make a library for printf and other functions that are able to output data to the stream. This library allows you to basically use unlimited different output streams, but just one can be use with printf at a time. You can use other output functions, like fprintf, which accepts stream pointer as parameter to know where to output data.

Library

Features

  • Output strings using printf or any other function, like fprintf, etc
  • Any function which is able to output data to the stream can be used
  • Basically unlimited output streams can be used
  • Version 1.1 – October 19, 2014
    • Added support to read from standard input (stdin) stream or user defined

Continue reading

Use printf to output stream on STM32F4

Posted on October 19, 2014 at 12:06 AM

It would be nice, if you can simply just use printf to direct output strings to USART, LCD, etc. With ARM C, you are able to do this. You just need to implement some things and you are ready to work.

New STDIO library is available here.

To enable printf functionality, first you need to create a new __FILE struct. This struct is then called with FILE struct. It can have only one dummy parameter, but it has to be created, because you need pointer to this structure if you want to output characters to stream. If you need any control for this, you can create your own. I created my own below:

After that, we have to create a variable with FILE struct:

Variable name __stdout is important. You can not use different name, otherwise printf will not work. Last thing we need to create is a function, that will be automatically called from printf and will actually print your charater by character to stream. Function has fixed name and can not be changed. Continue reading