If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov"


Good day comrades!

This week I've devoted all my free time to the project, to complete its programming part.


So this week I've done the following:

  • connected indication led (now - RGB, in a future - 3 independent leds);
  • connected avionics (IMU): Gyro - L3G4200D, Accelerometer - ADXL345;
  • PID-regulators, complimentary filter etc.


Now my stand looks like this:



New components:

  1. Gyro L3G4200D
  2. Accelerometer ADXL345


Let's look at the final PSoC schematics:


Red-module consists of 3 leds:

  • stablePin = red led: ON - horizon hold mode, OFF - acrobatic mode;
  • buzzerPin = green led: BLINK in some service functions (gyro-calibration, EEPROM write, etc);
  • ledPin = blue led: ON - armed mode (propellers are spining), OFF - disarmed mode (propellers are stoped).


Configuration of the led:


To realise this functions I use the next code:


#define BUZZERPIN_PINMODE { buzzerPin_Write(0x01); }
#define BUZZERPIN_TOGGLE { led_state ^=  0x01; buzzerPin_Write(led_state & 0x01); }
#define BUZZERPIN_ON    { led_state &= ~0x01; buzzerPin_Write(led_state & 0x01); }
#define BUZZERPIN_OFF    { led_state |=  0x01; buzzerPin_Write(led_state & 0x01); }

#define LEDPIN_PINMODE { ledPin_Write(0x01); }
#define LEDPIN_TOGGLE { led_state ^=  0x02; ledPin_Write((led_state & 0x02)/2); }
#define LEDPIN_ON    { led_state &= ~0x02; ledPin_Write((led_state & 0x02)/2); }
#define LEDPIN_OFF    { led_state |=  0x02; ledPin_Write((led_state & 0x02)/2); }

#define STABLEPIN_PINMODE { stablePin_Write(0x01); }
#define STABLEPIN_TOGGLE  { led_state ^=  0x04; stablePin_Write((led_state & 0x04)/4); }
#define STABLEPIN_ON      { led_state &= ~0x04; stablePin_Write((led_state & 0x04)/4); }
#define STABLEPIN_OFF    { led_state |=  0x04; stablePin_Write((led_state & 0x04)/4); }


Some comments:

  • PINMODE - initialization diode;
  • ON - enabling diode;
  • OFF - off diode;
  • TOGGLE - change led status from ON to OFF and viseversa.


Orange-module: my gyro and accelerometer use I2C interface and  to work with them I need two functions:


1. Write data to register of the I2C slave device:

void i2c_writeReg(uint8_t add, uint8_t reg, uint8_t val)
    I2Csys_I2CMasterSendStart(add/2,0); // I2C write direction
    I2Csys_I2CMasterWriteByte(reg);    // register selection
    I2Csys_I2CMasterWriteByte(val);    // value to write in register


2. Read data from the I2C slave device:

void i2c_getSixRawADC(uint8_t add, uint8_t reg)
    while (I2Csys_I2CMasterStatus() & I2Csys_I2C_MSTAT_XFER_INP);

    if ( I2Csys_I2CMasterSendStart(add/2,0) != 0)
    if ( I2Csys_I2CMasterWriteByte(reg) != 0)
    I2Csys_I2CMasterReadBuf( add/2, rawADC, 6, (I2Csys_I2C_MODE_REPEAT_START | I2Csys_I2C_MODE_COMPLETE_XFER) );

    while (I2Csys_I2CMasterStatus() & I2Csys_I2C_MSTAT_XFER_INP);


I2C configuration:


It was'nt very good, so, if in case of MultiWii the failure of one of sensors does not prevent the tricopter from continuing its flight with what is left, in my solution it is not currently supported. I just contacted Cypress, in order to find together the best solution, however, it is not a matter of first importance.


If you read carefully, you probably have already noticed, that the tricopter has two modes of flight: the so-called acro (acrobatic) and the stable (hold horizon). I want to dwell on them in more detail:


  • acro mode uses only gyroscope. In this mode we stabilise angular speeds of the ROLL, PITCH and YAW . This is the most difficult flight mode, but it makes it possible to perform aerobatics;
  • stable mode uses gyro and accelerometer. In this mode the tricopter tries to maintain a horizontal position, i.e. the regulation is carried out by the angular of YAW speed and the angular deviation of the ROLL and PITCH. In this mode, the pilot may relaxe a bit
  • magnetometer (MAG) is used for stabilization of the angular deviations by YAW;
  • altitude hold mode uses altimeter to stabilize the altitude of the tricopter's flight  (hold the Z-coordinate);
  • GPS is often used to hold the X and Y coordinates.


And now we make important conclusions:

  • gyro only: the machine can rotate at a constant speed on a ROLL, PITCH and YAW. The driver controls the ROLL, PITCH, YAW, X, Y and Z;
  • acc and gyro: the machine can rotate in YAW and move on axes X, Y and Z. The driver controls the YAW, X, Y and Z;
  • mag, acc and gyro: the machine can move along the axes X, Y and Z. All angular speeds are stable. The driver controls the X,Y and Z;
  • altimeter, mag, acc and gyro: the machine can move along the axes X and Y. The driver controls the X and Y;
  • gps, altimeter, mag, acc and gyro: the device can be operated completely independently.



  • there is a mode (which uses mag), in which the control YAW is left for the pilot, automation seeks to YAW angular speed to zeros only in those moments when you want to manage this axis;
  • GPS has a low resolution and does not work indoors, so for fully autonomous flight are also used other sensors: echo sounders and optical rangefinders;
  • classic altimeter uses baro-sensor for accurate positioning, the echo sounder and the optical rangefinders are also used;
  • megnetometer is just an electronic compass! It is very sensitive and not only to the magnetic field of the earth, but also to the magnetic field created by electrical wires (which abound on tricopters);
  • I chose the most simple and adequate solution and I use two modes: arco mode (aerobatics) and stable mode (for daily use).


I took PID-regulators, complimentary filter and other magic system from MultiWii. As soon as I finished writing, it appeared that my program took up more memory than you had in PSoC! The reason was the use of library <math.h>, which "eat" all of the memory. In this connection, I had to implement a variety of mathematical functions: sin, cos, abs etc. After that, my program finally "got" in PSoC!



Lastly I want to show you the interface of the MultiWii GUI nowaday:



I put the stand at an angle of 45 degrees, so you can see how the stabilization system works: "virtual tricopter" tilted to the left, thus stabilizing system took a decision to decrease throttle of the right front motor and increase throttle of the front left motor. Everything is very simple, and logical what is most important!


Now, I encountered a small problem, I have no special programmer for PSoC and I have to get out somehow to flash a single microcontroller. However, no sooner than I thought about this,  Gagan sent me a gift! Thank you very much, now No need now to make PCB for experiments, that  will accelerate considerably the development!



I'm still waiting for a parcel from HobbyKing. I began to get a bit nervous, because if it does not come I can not finalize my project:(

However, I hope for their decency and until announce the stage of writing the firmware closed! The next step - fabrication of PCB of the flight controller and construction of the tricoter frame (I have already started searching for the necessary wooden and aluminum components in local stores).


See you next week!


1PSoC 4 Tricopter Part #1Introduction
2PSoC 4 Tricopter Part #2Purchase of components from Farnell and HobbyKing
3PSoC 4 Tricopter Part #3PSoC firmware: upTime & Rx
4PSoC 4 Tricopter Part #4PSoC firmware: UART & MultiWii GUI
5PSoC 4 Tricopter Part #5PSoC firmware: EEPROM emulation
6PSoC 4 Tricopter Part #6PSoC firmware: Servo & ESC control
7PSoC 4 Tricopter Part #7PSoC firmware: IMU, LED's & PID
8PSoC 4 Tricopter Part #8Hardware: PCB
9PSoC 4 Tricopter Part #9Hardware: tricopter's frame
10PSoC 4 Tricopter Part #10Hardware: YAW mechanics & motors
11PSoC 4 Tricopter Part #11Hardware: ESC's, wires & misc
12PSoC 4 Tricopter Part #12Final: The first fly


If you like my project vote for "A Smarter Tricopter - Yuri Tikhonov"