Terms of service
Brokking
 
 
.net
Let's keep it simple
 

 
   Home
   Projects
 

   Articles
 

   Donation
         
 
 
 
 

 
Brokking.net - Video: YMFC-32 | Part 3 | a DIY 32-bit STM32 and Arduino based quadcopter flight controller

YMFC-32 | Part 3 | a DIY 32-bit STM32 and Arduino based quadcopter flight controller

This page contains the full script that I used for making this video.

Hello and welcome to this STM32 quadcopter project.

My goal is to make a quadcopter flight controller with this STM32F103 microcontroller board. In the previous videos I explained all the details from how to upload you first program via the Arduino IDE up to the more complex input capture mode for reading the receiver pulses.

And now that all the software is explained it's time to start building the hardware. As you can see I have the flight controller ready and it is time to test all the functions.

Please ignore this pin header as I might use it for further development. During this video it will not be used.

If you want to build this quadcopter yourself make sure to test all the components on a breadboard first. This is to make sure that all the parts are ok and you don't get disappointed when it does not work on the PCB. Once soldered it's very hard to replace the individual parts.

And please, don't use a breadboard on a quadcopter. I know it's might look very convenient but the inevitable vibrations will definitely cause problems.

The base for this contraption is the same as the Arduino balancing robot that I made earlier. It's just a piece of prototype board with single islands. This makes it very easy to make reliable connections between the various part.

For convenience I made a simple diagram that explains how the connections need to be made. So, with a little patience and a soldering iron it's actually quite fun to build it.

And as always, you can find detailed information on my website. Including drawings, detailed photos, a parts list, the Arduino programs, setup instructions and much more. You can find a link in the description.

These wires are directly connected to the receiver and are supported with two component epoxy. Just to make them more rigid and protect them against vibrations.

Power for the receiver is provided by the esc as you can see here in the diagram.

And yes I still use the FTDI programmer for uploading the various programs to the STM32.

As explained in the previous video the code that I'm working on should also work on the so called Flip32. This flight controller has an onboard USB to serial converter that functions like an FTDI programmer.

In short, the USB connector on the microcontroller board has not the same purpose as USB connector on the Flip32. But of course you are free to use the USB connector for uploading the various programs.

Also important is the orientation of the MPU-6050. If mounted in the wrong orientation the quadcopter will not work properly and directly flip upside-down. So make sure to get it right. As you see the dot on the MPU-6050 needs to point to the left rear of the quadcopter.

The same goes for the Flip32 as you can see here.

The rest of the schematic is very straight forward. As you can see all the parts are powered by the 5V battery eliminator circuit, or BEC for short, from the ESC. Make sure that you only connect one BEC and leave the rest unconnected. I made the isolation on the back side of the PCB as you can see here. This way I don't have to isolate the connectors.

Because the ground is connected to the ground -or negative- of the flight battery, only the plus connection is needed to measure the battery voltage. So only a single wire that is connected to the plus of the power distribution board is needed. This wire is connected via a voltage divider to the analog input A4.

The resistor values are the same as the Flip32 so both boards will give equal results with the analog read function.

One of the most important parts are these LEDs. During startup and flight they provide valuable information about calibration, errors, power, etc. So make sure to connect them.

On the flip32 these LEDs are already on the board and connected to the same ports as shown on the diagram.

Now that the hardware is finished it's time to test it and setup the transmitter. For this I made a small test program that can be downloaded from my website.

If you haven't setup the Arduino IDE for programming the STM32F1 microcontroller I suggest to watch this video where I explain the process of uploading the first program.

Don't connect the ESC's or flight battery at this point.

When the setup program is opened in the Arduino IDE, connect the FTDI programmer to the flight controller with the boot jumper in the one position. Directly after the connection some LEDs should lit up.

When all the LEDs stay off directly disconnect the FTDI programmer and check the wiring for shorts.

Now open the serial monitor at 57.6kbps. Switch on the transmitter and make sure it binds to the receiver. Now click upload.

When everything is working a message is printed on the serial monitor.

By sending an -a- via the serial monitor the receiver inputs are shown on the serial monitor. For simplicity I will not use the same setup feature as I did with the Arduino quadcopter. Although it was very easy the software used the EEPROM that was quit confusing when people start adding their own code.

So my goal with this flight controller is to make it as easy and understandable as possible. The only downside is that it will use standardized inputs. And you need a digital transmitter like this FlySky T6, or any other digital transmitter. The important part here is that you need to adjust the endpoints of the first four channels. That is roll, pitch, throttle and yaw.

As you can see here I setup the first four channels so they have a 1500us center pulse and a 1000 till 2000us travel.

It's important that the start function works by lowering the throttle and fully yaw left. When the stick is back in the center position the start variable should be 2. This means that the quadcopter is started. Throttle low and yaw right turns the quadcopter off.

Channel 5 and 6 are not important at this moment but can also be tested with this program.

This is also a good time to test the pulse outputs for the ESC's. If I connect channel 6 to the ESC pulse outputs you can see that it is 1000us.

When the transmitter is setup and the all the ESC ports are tested you can quit by sending a -q-.

By sending a -b- an I2C scanner is called that will detect all the connected I2C devices. As you can see the MPU-6050 is detected on the hexadecimal address 0x68.

With the -c- and -d- function we can check the raw gyro and accelerometer data.

After sending an -e- the gyro is calibrated and the angles of the quadcopter are shown. Please don't move the flight controller during calibration otherwise the angles are not shown correctly.

Nose up should give a positive pitch angle and nose down must result in a negative pitch angle.

Left wing up should give a positive roll angle and left wing down results in a negative roll angle.

The yaw value is gyro based only. So no movement should result in a zero. Nose right will give a positive value and nose left a negative value.

To calibrate the IMU pitch and roll angles you must place the quadcopter on a spirit level surface and note the roll and pitch angles as shown here. Next, enter the roll and pitch angles in the main program.

Upload the program again and check the angles. They should now be around zero degrees.

And don't forget to use these calibration values in the main flight controller program to.

Next we can check the LEDs by sending an -f-.

To test the voltage input you need to connect the wire that is connected to the voltage divider to +5V. In this case I will connect it to the +5V of the receiver. And as you can see the voltage is shown on the serial monitor.

And now that everything is working it's time to connect all the parts together. Connect the ESC's as shown on the schematic and double check the location of the motor.

ESC one should be connected to the right front motor that is rotating counterclockwise and should be connected to port B6 of the STM32. Any changes will definitely result in a crash. So make sure to double check everything.

For safety, it's very important that the propellers are removed for the next test.

With all the connections in place it's time to calibrate the ESC's. This is needed because without calibration the standardized 1000 till 2000us pulse is not recognized by the ESC's. And they will simply not work.

Calibration is also needed to get the motors to rotate at approximately the same rpm.

The calibration procedure can be found in the manual of the ESC and may vary from what I'm showing here. So make sure to check the manual of your own ESC on how to calibrate them.

First I turn the transmitter on and set the throttle in the highest position. With the test program uploaded to the STM32 and the boot jumper in the zero position I connect the flight battery.

After several beeps I lower the throttle and the ESC's are all calibrated.

You can check this by slowly increasing the throttle. The motors should start to spin at approximately the same throttle position.

If this is not the case, or the ESC's keep beeping because the pulse is not recognized, you need to check the calibration procedure in the manual of the ESC.

Because the transmitter is already set to a 1000 till 2000us pulse during setup, it's also possible to calibrate the ESC's with the transmitter.

Final thing to do is to check the rotation of the motors.

Send a -1- to check the rotation of the first motor. This is the right front motor. When the throttle is increased the motor should start to spin in a counterclockwise direction.

If the motor is spinning clockwise you need to reverse the direction of the motor. You can do this by swapping two motor wires.

Make sure to do the same with remaining 3 motors.

And that wraps it up for this video. In the next video I will explain how to balance the propellers and how to setup the quadcopter for the first flight.

Please don't forget to share this video and give it a thumbs up if you liked it. Thank you for watching and see you next time.