Arduino Uno assisted Dji Naza

Hi All,

I just bought my Arduino Uno 2 days ago. Before Arduino, I was using Basic stamp. Arduino's capabilities and society seems amazing. Anyway, I would like to mention that my protyping knowledge is beginner level but my idea is beyond of it :slight_smile: I am planning to assist naza with Arduino Uno by connecting ping)) sensors around my quadrotor. At first Reciever signals and sensor signal will be taken by Arduino and sent to Dji Naza contorller.

I wrote a code where i can read and write my receiver signal but I cant arm my Naza when arduino is connected to Naza. This start up code is intended to see whether I can arm or not. It seems that I cant for right now :slight_smile:

Thanks for any suggestions in advance

Giray Yillikci

int ch1; // Here's where we'll keep our channel values
int ch2;
int ch3;
int ch4;
int ch5;
//int ch6;
int Pwm1;
int Pwm2;
int Pwm3;
int Pwm4;
int Pwm5;
//int Pwm6;

void setup() {
  
pinMode(2, INPUT); // Set our input pins as such
pinMode(4, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT); 
pinMode(12, INPUT);
//pinMode(13, INPUT);

pinMode(3, OUTPUT); // Set our output pins as such
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT); 
pinMode(10, OUTPUT);
//pinMode(11, OUTPUT);

Serial.begin(9600); // Pour a bowl of Serial

}

void loop() {
  
  ch1 = pulseIn(2, HIGH, 25000); // Read the pulse width of 
  ch2 = pulseIn(4, HIGH, 25000); // each channel
  ch3 = pulseIn(7, HIGH, 25000);
  ch4 = pulseIn(8, HIGH, 25000); 
  ch5 = pulseIn(12, HIGH, 25000);
  //ch6 = pulseIn(13, HIGH, 25000);
  
  Pwm1= map(ch1,900,2100,900,2100);
  analogWrite(3,Pwm1);
  Pwm2= map(ch2,900,2100,900,2100);
  analogWrite(5,Pwm2);
    Pwm3= map(ch3,900,2100,900,2100);
  analogWrite(6,Pwm3);
    Pwm4= map(ch4,900,2100,900,2100);
  analogWrite(9,Pwm4);
    Pwm5= map(ch5,900,2100,900,2100);
  analogWrite(10,Pwm5);
    //Pwm6= map(ch6,900,2100,900,2100);
  //analogWrite(11,Pwm6);
  
Serial.print("ch1:");
Serial.println(ch1);

Serial.print("Pwm1:");
Serial.println(Pwm1);

Serial.print("ch2:");
Serial.println(ch2);
Serial.print("Pwm2:");
Serial.println(Pwm2);
Serial.print("ch3:");
Serial.println(ch3);
Serial.print("Pwm3:");
Serial.println(Pwm3);
Serial.print("ch4:");
Serial.println(ch4);
Serial.print("Pwm4:");
Serial.println(Pwm4);
Serial.print("ch5:");
Serial.println(ch5);
Serial.print("Pwm5:");
Serial.println(Pwm5);

Serial.println(); //make some room

//delay(1000);// I put this here just to make the terminal 
           // window happier
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Hi,

i dont know what a nzaz is, but are you sure that it expects the type of signal you are giving it?

My guess is that it expects an radio control style signal which is not what you are giving it.

Have a look at the how to read rc channels posts on my blog, the give you the gackground and plenty of code examples for reading in and outputting RC Signal.

once you have done that, look up the analogWrite function to see why it is not doing what you want.

The post you should start with is at the topnof the list of popular posts on the right of the s reen or just have a look around the projects pages.

rcarduino.blogspot.com

duane B

Thank you very much for your help. Naza is a quadrotor controller by the way. I looked in to the code that you wrote but as a beginner like me it is little bit confusing.

For now I just want to replicate receiver signals with arduino and send replicated signal to quadrotor controller. I can read the signals by pulsein but cannot produce same signals via map and analogwrite functions. Basically, I just want to create same signals of receiver that i read with arduino

Giray

The servo object does that for you.

Duane B

rcarduino.blogspot.com

Thank you very much Duane B.

I achieved with servo objective. I tried for only one esc now i ll try for 5. I just adjusted map value in order to reach esc signals. l did it in this order:
ch1 = pulseIn(2, HIGH, 25000);
ch1 = map(ch1, 900, 2100, 900, 2100);

Thanks again

What is map doing ?

Duane

file:///C:/Users/Giray/Desktop/arduino-1.0.1/reference/Map.html

For servo objective it is given that the lowest value as 0, highest value as 1023 and re-scales this range in to given range, 0-179 for servo. In my case receiver was signalling out from 940 to 2050 so I duplicated this range by just putting the same values to signal out, 900 to 2100. reference would be more helpful.

Hi,

I asked because as you have it in the two code samples you have posted its doing nothing -

ch1 = map(ch1, 900, 2100, 900, 2100);

map from 900,2100 to 900,2100 ?

As your simply passing the signal through with no adjustment you can safely get rid of all the map statements.

Duane.

I got it now. Actually i realized it before this conversation and remove the map from my sketch but I experienced an error so in order to make things faster I kept it not create unnecessary potential problems. So far, I only bypass one channel from arduino to Naza controller yet the idea is working properly.

I ll update my works.

Giray :slight_smile:

Map function is needed in order to pulse required pwm signals. First I tried without map function and the system did not worked then the system started to work after adding map function. But , i don't know why. I am waiting for the motors that are ordered from Hobbyking.com to fly :slight_smile:

Hey Giray,

What components did you buy to connect the arduino uno to the naza controller? I'm not entirely sure how to do it, and I'd like to know before purchasing them. Is it possible to retrieve telemetry data from the naza controller through the arduino? or would I need to purchase separate gyro/accelerometer/gps components to integrate with the arduino uno?

Thanks for the insight!

Pat

I only used male to male leads from receiver to Arduino uno for reading of pwms and male to male leads from arduino uno to naza controller. I havent connect any sersor to my arduino.

Hey Guys

Today I made my first flight with Ardunio assisted Dji Naza. I ll put its video tomorrow. :slight_smile:

Hi,
Can you post yr video ?
and yr last code ?

Thanks in advance

I would love to see the final sketch and a diagram of your setup. I'm working on a sensor setup for a proper soft landing...

Thanks in advance!

Hello gyillikci

can i see your code ? please