Arduino code for Gaui 330X quad copter




I've been doing some work with arduino and GAUI 330X. In this example we controlling the throttle speed of the engines. On the 330X throttle is also used to reset and config the ESCs (4 small boards that control the power to the engines and speed).

I removed the blades and replace those with plastic circles, so I can test the code without having the 330x flying all over the place.

Since I don't own a radio/receiver, it took me a while to get the 330X configure and working.

This example, should allow you to configure the ESCs, and start the 330X, and throttle the engine up and down with the potenciometer.

One thing I didn't realize for a while is that the ESCs are the ones that beep (not the GU334), and since all four are connected to the GU3344 is difficult to configure them because they all beep at same time and are not really synchronized, so you can't really figure out what is the current state of each one.

Probably in the future, I need to figure out a easy way to configure the ESC one by one, without redoing all the wiring.

This code should be used with a potenciometer on pin analog 1.

The wires from GU334 gyroscope should connected to the arduino in the order below:
  • yellow is the rudder wire connect to pin 9
  • orange is the throttle wire connect to pin 10
  • red is the int elevator wire connect to pin 11
  • green is the gain/gear don't connect this wire
  • white is the aileron wire connect to pin 12 (this connector also has power (3 wires). Only connect the white wire to the arduino)
GU334 wires behave like servos, so you can use the servo arduino library, to control the GU334.

Just take it consideration that 90(the user is not pushing the controls) is the neutral value on the servo and 0(user pushing the controls backwards at max) is max backwards value and 180(user pushing the controls forward at max) is max forward value.




#include

int aileronPin = 12;
int rudderPin = 9;
int throttlePin = 10;
int elevatorPin = 11;
int gainPin = 8;
int potPin = 1;

Servo aileron; //White
Servo rudder; //Yellow
Servo throttle; //Orange
Servo elevator; //Red
Servo gain; //Green (Gain/Gear)

void arm(){
setSpeed(aileron, 90);
setSpeed(rudder, 90);
setSpeed(throttle, 90);
setSpeed(elevator, 90);
setSpeed(gain, 90);
delay(1000);
}

void setSpeed(Servo &s, int speed){
if (s.read() != speed) {
s.write(speed);
Serial.print(speed);
Serial.print("\n");
}
}

void setup() {
aileron.attach(aileronPin);
rudder.attach(rudderPin);
throttle.attach(throttlePin);
elevator.attach(elevatorPin);
gain.attach(gainPin);
Serial.begin(9600);
arm();
}

void loop() {
int foo = analogRead(potPin);
setSpeed(aileron,90);
setSpeed(rudder,90);
setSpeed(throttle,map(foo,0,1023,0,180));
setSpeed(rudder,90);
setSpeed(elevator,90);
setSpeed(gain,90);
delay(10);
}



NOTE: Created a library for arduino to control the Gaui 330X available here https://github.com/hagleitn/QuadCopter/

Comments