@all
thanks for the reply guyz...i m working on to develop my arduino programming skills...BY using pwm pins it will be easy but the thing is original library code by YMFC uses interrupt to generate pwm pulses...and i figured it out that without any inputs the drone remains in flight without crashing down.... and i have other option instead of sending few values to the quadcopter i can send various values according to position of seekbar....this code is for motor attached to pwm pin...but its very difficult to design PID control thats why i want to modify the exisitng code by YMFC..
#include <String.h>
#include <Servo.h>
//----------------------------------------------------------------------------------------
int n=4;
char Byte_received;
//String read;
char prefix;
char text[4];
Servo motor;
int minimum=10,maximum=150;
//----------------------------------------------------------------------------------------
void change_speed(int speed)
{
speed = map(speed,0,100,minimum,maximum);
motor.write(speed);
}
//--------------------------------------
void arm_motor()
{
// arm the speed controller by setting speed to 0 and delay for 1 second.
// Some speed controllers may need longer delay.
change_speed(minimum);
delay(2000);
change_speed(78);
delay(200);
change_speed(minimum);
}
//--------------------------------------
void send_data()
{
//
}
//----------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600);
motor.attach(9);
arm_motor();
Serial.write("Ready System");
Serial.println ();
}
//----------------------------------------------------------------------------------------
void loop ()
{
int y = Serial.available();
//Serial.println(y);
int cont=0;
int suffix=0;
//--------------------------------------
while (cont!=y && cont<n)
{
Byte_received = Serial.read();
//read += Byte_received;
text[cont]=Byte_received;
cont++;
}
//--------------------------------------
if (y>0)
{
//Serial.println(read);
suffix = (atoi(&text[1]));
Serial.print(text[0]);
Serial.print("-");
Serial.println(suffix);
switch (text[0])
{
case 'M'://Speed
if(suffix >65 && suffix < maximum)
{
change_speed(suffix);
}
//speed += step;
//suffix=0;
//cont=0;
//index=0;
break;
case '0'://Speed
change_speed(minimum);
break;
default:
break;
}
}
//--------------------------------------
send_data();
delay(500);
}
//----------------------------------------------------------------------------------------
@lastchancename "Yes thats the thing i want to do...6 ch R/C into single bit stream of BT...help me with that" @srnet i am trying my best i work day to night on same code to find out every possible way..but i dont know i m capable of cracking code still i m trying my best to understand...help me with that..yes it has flight controller designed by using arduino and i want to add just bluetooth command in it...it can remain stable through entire flight without having input.. @robin2 thank you..
@all
i will send one code today or tomorrow please let me know that it will map the 6 channels to one serial bluetooth data...
Why change out a working RF system that has maybe a mile or so range with something that has what? 50yd range?
The quads I've built & flown would be in & out of bluetooth range in a couple seconds. Why is this something you want to do? What problem is it solving for you?
Anyway, Lets assume you have a wonderful reason. Sombody in Zambia is offering you $560,087,876 to develop this thing.
Here's what you do.
#1 Get your machine working the "Normal way". Your favorite flight controller, maybe AfroNaze, Mulitwii what have you and a good reliable RC setup. There is a good brand people are using now but I forget the name.
#2 You are now flying and gaining confidence. Good! Probably learning a LOT as you go. Now the next step is to add a second processor (arduino) between your receiver & your flight controller. For now just use it to "listen" to the control signals and run some LEDs. Be able to switch them from your RC transmitter.
Example : Second Aduino controlling lights
#3 We can see the inputs, we can act on them. Good! Now instead of just listening to the RC, lets change it so it passes through the signals from the receiver to the flight controller. You are still flying using the RC transmitter, but now all the info. is being passed through your secondary Arduino. And you can tweak it in code..
See where this is going?
#4 Add your bluetooth to the secondary Arduino. Set it up so its choosen as a flight controller by a switch on your RC transmitter. This way if some.. WHEN something goes wrong you can switch it back and possibly save your machine.
This reinforces the concerns I expressed in Reply #17
I cannot imagine what role the PWM pins will have in any communication system. In any case I presume they are already in use for controlling the speed of the motors.
I agree 100% with what @jimlee said "#1 Get your machine working the "Normal way".
Why do you want a Bluetooth controlled copter?
Bluetooth is designed for short range, and as it shares the same frequency spectrum as wifi its prone to interferance from wifi, hardly ideal for flying something around in the open.
@all i am not arduino designer i work for android and iots so i want basic bluetooth controlled quadcopter for my apps to get work with...please let me knw if it going to work or not...Soon i will try my code that it is working fine or not..wish me luck...thus code in post #22 works or not... @jimlee i m trying it on leds my first program works fine in that i have mapped 6 differtn value according to characters now i m going to try my new code thus it is going to work or not... @robin2 i m working on hardware part and making YMFC DIY quadcopter but i don't want to invest money on RF tx and rx it will cost 2500INR thats why i m asking you guyz can it will help or not if i don't find out any way then good to be using two arduino boards one or flight controller using RF tx n rx and one for bluetooth...
tell me about code i have made in post #22 thus it separate my A2000 to A and 2000 "suffix = (atoi(&text[1]));"
nickstotle: @robin2 i m working on hardware part and making YMFC DIY quadcopter but i don't want to invest money on RF tx and rx it will cost 2500INR thats why i m asking you guyz can it will help or not if i don't find out any way then good to be using two arduino boards one or flight controller using RF tx n rx and one for bluetooth...
I am not able to make any connection between this comment and the remarks I made in Replies #17, #25 or #27
Maybe you are trying to say that you want to avoid testing the quadcopter with a conventional RC system because that would cost a lot extra. While I can understand the desire not to waste money I strongly recommend that you develop your modified system step-by-step from a working standard system.
And as I have already said, I don't think your understanding of programming concepts is sufficient to enable you to get the modified system to work EVEN IF the standard system works. Sorry if that sounds harsh, but if money is in short supply you should face up to reality before spending anything.
Build your programming knowledge with other projects and come back to the quadcopter in 6 or 12 months.
@robin2 i know that i can't make it..but i have to give the try...i am modifying existing library that means that i am not able to design by my own...i have figured out way to send inputs at the same time by using string format"R1000P1000T1000Y1000" through cell phone or bluetooth controller..then i will decode this existing string by using my decoder code..as follows
int receiver_input_channel_1, receiver_input_channel_2, receiver_input_channel_3, receiver_input_channel_4;
int n=26;
String stringOne;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0 && Serial.available() < n)
{
stringOne = Serial.read();
String text0 =stringOne.substring(0,5);
String text1 =stringOne.substring(5,10);
String text2 =stringOne.substring(10,15);
String text3 =stringOne.substring(15,20);
char charBuf0[6];
text0.toCharArray(charBuf0, 6) ;
char charBuf1[6];
text1.toCharArray(charBuf1, 6) ;
char charBuf2[6];
text2.toCharArray(charBuf2, 6) ;
char charBuf3[6];
text3.toCharArray(charBuf3, 6) ;
char decBuf[5]={charBuf0[0],charBuf1[0],charBuf2[0],charBuf3[0]};
//--------------------------------------
if (strcmp(decBuf,"RPTY")==0){
//Serial.println("Matched");
int suffixR = (atoi(&charBuf0[1]));//receiver_input_channel_1=(atoi(&charBuf0[1]));
int suffixP = (atoi(&charBuf1[1]));
int suffixT = (atoi(&charBuf2[1]));
int suffixY = (atoi(&charBuf3[1]));
if(suffixR >999 && suffixR < 2001)
{
receiver_input_channel_1 = (suffixR);
Serial.println("Roll : ");
Serial.println(receiver_input_channel_1);
}
if(suffixP >999 && suffixP < 2001)
{
receiver_input_channel_1 = (suffixP);
Serial.println("Pitch : ");
Serial.println(receiver_input_channel_2);
}
if(suffixT >999 && suffixT < 2001)
{
receiver_input_channel_1 = (suffixT);
Serial.println("Throttle : ");
Serial.println(receiver_input_channel_3);
}
if(suffixY >999 && suffixY < 2001)
{
receiver_input_channel_1 = (suffixY);
Serial.println("Yaw : ");
Serial.println(receiver_input_channel_4);
}
}
}
now the problem is..is it going to work or not...thnks all....