DIY RC

Do It Yourself RC => 3d Printed Inspire Clone => Topic started by: CdRsKuLL on July 08, 2015, 08:41:56 PM

Title: Inspire Clone Electronics
Post by: CdRsKuLL on July 08, 2015, 08:41:56 PM

To control the movement of the legs / leds I've used an Arduino nano. This is a small hobby microprocessor that only costs about £5.00. I'm by no means an expert and this code can most likely be greatly improved on. If you would like to improve on it then please do, I would be happy for the help :-)

You will need to program this with the below code for it to work correctly and wire the pins up.

Code: [Select]

// Designed for Skull Quadcopter
// Rev 1.0


#include <Servo.h>
#include <PinChangeInt.h>




// Define RX variables
#define PIN1 2
#define PIN1dataReg PIND
#define pin1state (PIN1dataReg & (1 << PIN1))
volatile long pulseStart1; // pulse start time measured from millies in ISR for pin 1
volatile long pulseTime1; // pulse width time measured from millies in ISR for pin 1 <-- this is the output we require


Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position


// Define Microswitch pins
const int msdown = 5;
const int msup = 4;
int msdownstate = 0;
int msupstate = 0;


// Define Variables for LEDs
int led1 = 6;                    // output pin for LED 1
int led2 = 7;                    // output pin for LED 2
int led3 = 8;                    // output pin for LED 3
int led4 = 9;                    // output pin for LED 4
int led13 = 13;                   // onboard LED indictor incase no others are attached
unsigned long time;              // holds current time for change of state
int flashtime = 400;            // time to flash LEDs in milliseconds
boolean ledon = false;         // remembers start of LED
boolean movedown = true;      // safety feature
boolean moveup = true;        // safety feature


// The below procedure handles the pulse from the RX input
void handlePin1() 

  if(pin1state) 
    pulseStart1=micros(); // we got a positive edge 
  else 
    pulseTime1=micros()-pulseStart1; // Negative edge: get pulsewidth 



// LED Control - very basic, can be expanded.
 void turnledoff() {
    digitalWrite(led1, LOW);     
    digitalWrite(led2, LOW);     
    digitalWrite(led3, LOW);     
    digitalWrite(led4, LOW);
    digitalWrite(led13, LOW);   
  }
  void turnledon() {
    digitalWrite(led1, HIGH);     
    digitalWrite(led2, HIGH);     
    digitalWrite(led3, HIGH);     
    digitalWrite(led4, HIGH);     
    digitalWrite(led13, HIGH); 
}
  void flashled() {
      // LED Flash
  if (millis() - time > flashtime){
      time = millis();
     
      if (ledon){
        turnledoff();
        ledon = false;
      } else {
        turnledon();
        ledon = true;
      }
     
  }


  }


// Lets set everything up
void setup() {
 // initialize serial communication at 115200 bits per second so we can see whats going on:
  Serial.begin(115200);
 
  pinMode(PIN1, INPUT);          // Initialize rx input pin
  digitalWrite(PIN1, HIGH);      // Set the rx pin to High to start the counter
  PCintPort::attachInterrupt(PIN1, &handlePin1, CHANGE); // Attach the interrupt
 
  pinMode(led1, OUTPUT);         // Assign output mode to pin for LED 1
  pinMode(led2, OUTPUT);         // Assign output mode to pin for LED 2
  pinMode(led3, OUTPUT);         // Assign output mode to pin for LED 3
  pinMode(led4, OUTPUT);         // Assign output mode to pin for LED 4
  pinMode(led13, OUTPUT);         // Assign output mode to pin for LED 4


  pinMode(msup, INPUT);
  pinMode(msdown, INPUT);
  msupstate = digitalRead(msup);
  msdownstate = digitalRead(msdown);
  time = millis();               // Save current millis reading (this is a counter that always runs in milliseconds)
  turnledon();
 }


// Main Program
void loop() {
 
  msupstate = digitalRead(msup);
  msdownstate = digitalRead(msdown);
  // read the input channels


   if (pulseTime1 > 900 && pulseTime1 < 1300){ //legs down
   myservo.attach(3);
    pos = 0;
    moveup = true;
    if (msupstate == LOW){
      if (movedown){myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      movedown = false;
      myservo.detach();
      turnledon();
    }
   }
    if (pulseTime1 > 1299 && pulseTime1 < 1701){ //no movement
    myservo.detach();
   
    pos = 100;
   }
   
  if (pulseTime1 > 1700) { //legs up
  myservo.attach(3);
    pos = 180;
    movedown = true;
    if (msdownstate == LOW){
       if (moveup) {myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      moveup = false;
      turnledon();
      myservo.detach();
    }
  } 
   
}








INFORMATION

1. You will need to download the Arduino program from arduino.cc and install.
2. I have also used an extra interrupt library which you will also need to install from https://code.google.com/p/arduino-pinchangeint/downloads/list (https://code.google.com/p/arduino-pinchangeint/downloads/list) and unzip and copy it into C:\Program Files (x86)\Arduino\libraries\PinChangeInth
3. Open up the arduino software and plug in your arduino nano, you will now need to set the port / board type from the drop down menus. Paste the boards code in above and upload.

(http://diyrc.co.uk/images/quad-arduino.jpg)

The 3A DC-DC converter is used to output 7.2 volts to the servo, this increases the transforming speed.
Both microswitches have a positive and negative input. They output with positive OR negative depending if the switch is active. This is required as if no input is received by the arduino it can actually change it's self as it would be floating. You could use a pull down resistor but I thought this way would be easier and less components required.
The LED pins output 5v's and receive an negative feed off the ESC in the foot. You only need to feed the signal wire from the ESC up the leg. At the moment the LEDs are on normally and flash when transforming. I think I'll look at adding a voltage divider so they can flash when your lipo is getting low as an indicator.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on July 10, 2015, 10:53:56 PM
Little photo of on board arduino programming..

(http://diyrc.co.uk/images/programming.jpg)
Title: Re: Inspire Clone Electronics
Post by: huy507 on July 18, 2015, 04:36:14 AM
how can stop servo at middle limit like this

(http://i185.photobucket.com/albums/x93/huy507/as_zpsbdvblhcu.jpg)
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on July 18, 2015, 07:41:45 AM
Hi Huy,  You could map the 3 position switch maybe on your remote.. up / down / stop. ? Or add an extra sensor or a timing event so it guesses where it is?  The problem with a 360deg servo is you have no way of tracking it's position like a normal servo. It just rotates, you can control the speed of the rotation but thats about it.

There are a few options just need to decide which way you want to  do it.

Steve
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on July 19, 2015, 03:42:13 AM
Steve is there a way you can show me how the servo is mounted cause i do not understand how it works. Thanks

Fede
Title: Re: Inspire Clone Electronics
Post by: huy507 on July 20, 2015, 04:24:18 AM
Hi Steve,
i have an idea for retractable, instead ardruino, can use "Tarot Electric Retractable Landing Gear Tripod Controller" (http://www.himodel.com/multi_rotors/Tarot_Electric_Retractable_Landing_Gear_Tripod_Controller_TL8X002.html)
This board is reading the current feedback (proportional voltage) from the H-Bridge. This current measurement is used to determine end positions of both actuators, rather than implementing complicated limit switches. i think this way 's simple and cheaper ardruino.

i will try for my build :D

(http://i185.photobucket.com/albums/x93/huy507/Capture_zpsvpp11qdm.jpg)
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on July 20, 2015, 09:43:35 AM
Let me know if you need anything from me, good luck with the development. Interesting idea.
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 10, 2015, 10:39:06 PM
Regarding your microswitches. The 3 pins are Common, Normally open, Normally Closed. What do you mean when you say positive, negative and ground? Is it this
Common=Ground
Normally open= Negative
Normally closed=Positive
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 10, 2015, 11:27:27 PM
The common is your signal wire. This will be either positive or negative depending if the switch is open or closed. The NO and NC will have the positive and negative from the arduino wired to them. I'll make a diagram of them tomorrow as it's late now and I need sleep!... lol
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 11, 2015, 01:10:50 AM
Thanks a million..I got it working. Bench tested Arduino with servo and transmitter and it works great. I had to use my Arduino mini pro but works great. Waiting for the nano to get here.
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on August 11, 2015, 01:15:00 AM
Why did this guy put the pins of the microswitch cables like this?
Can I also remove the little pins in the arduino?

Attached a picture.

Thanks
Title: Re: Inspire Clone Electronics
Post by: jkralinddd on August 11, 2015, 12:36:14 PM
Hi,


Quick question on the electrical diagram.  Where does the RX get power from?  I don't see any positive in looking at the schematics unless I am reading it wrong.
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 11, 2015, 09:17:18 PM
You can take power from a power distribution board or just another line from a BEC or as he listed from the dc converter. Just make sure it matches your receiver. Usually 3-10v.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 11, 2015, 09:21:21 PM
If you are running a NAZA then this will power the RX when you plug it in. I also power my arduino via the 7.2v dc-dc mini board that's used to get a better transition speed on the servo.
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on August 11, 2015, 09:43:56 PM
If you are running a NAZA then this will power the RX when you plug it in. I also power my arduino via the 7.2v dc-dc mini board that's used to get a better transition speed on the servo.

In the first post you say that we shod only put up the leg the signal wire but certainly I must run a positive one also right?
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 11, 2015, 11:23:06 PM
Hi, the esc gets it power from the main power inputs so no need to run the positive wire up... Not sure on opto esc's but mine seems to work OK just using the signal wire.  If they do have a bec built in you could run a single one up if you want.
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on August 12, 2015, 11:29:03 AM
What about flight times. How much are you getting on a single battery?
Title: Re: Inspire Clone Electronics
Post by: jkralinddd on August 16, 2015, 08:49:32 PM
Any progress on the diagram for the microswitch Arduino wiring?  Can't seem to get this to function properly.  I have both pins from microswitch N.C. wired to Arduino 5v out.  Both pins from microswitch N.O. wired to Arduino ground and C. to respective top bottom positions.  I think this is correct but maybe I'm missing something because I can't get it to workk properly.


Thank you!
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 16, 2015, 09:10:02 PM
You could have play with the code.. and change the state it's looking for.. ie..

current code -
 if (msupstate == LOW){
      if (movedown){myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      movedown = false;
      myservo.detach();
      turnledon();
    }

Change to

 if (msupstate == HIGH){
      if (movedown){myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      movedown = false;
      myservo.detach();
      turnledon();
    }


Also change the LOW to HIGH here;


if (msdownstate == LOW){

Let me know if that helps...

If the switches are working back to front ie.. when you press the bottom one it stops moving up then swap the pins around in the code;


const int msdown = 5;
const int msup = 4;

becomes



const int msdown = 4;
const int msup = 5;


Hope this helps
Title: Re: Inspire Clone Electronics
Post by: jkralinddd on August 17, 2015, 03:32:31 AM
Thanks for getting back, I'll give this a try.
Title: Re: Inspire Clone Electronics
Post by: jkralinddd on August 17, 2015, 03:55:01 AM
FYI, I began this project to try out a 3D printer I had just purchased.  I am new to 3D printing and this project seemed like a good test of making parts and trying to make something functional.  Knowing nothing about quads or 3D printers I dove right in. Needless to say I am a little overwhelmed.  I believe the Arduino is programmed properly and the wires seem to be correct for the leg lift.  Is it possible there is something I am missing with the assignment to the switch I am using with my transmitter?  Just a thought.  I also was unaware there is a Tower Pro MG995 and a Tower Pro MG995 360 which I did not have the correct one.  I hacked the Tower Pro by removing the limit pin on one of the gears, removed the plastic around the potentiometer so the gear spins free of the potentiometer and wired in two 2.2k resistors and it keeps spinning around now.  So I think the servo is ok.  I have no clue how to use my transmiitter yet and was thinking I am doing something wrong as far as the signal for direction of travel goes when I flip the switch.  Could this be an issue?
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 17, 2015, 08:18:16 AM
Hi, you can test to see if your transmitter is working by plugging the servo directly into the channel you have your TX programmed to. So if it's a two position switch then when you power everything up your servo should rotate one way. When you move the switch to the other position then your servo should rotate the other way.

Which transmitter do you have and we should be able to help you double check everything and get it working :-)
Title: Re: Inspire Clone Electronics
Post by: jkralinddd on August 17, 2015, 02:58:54 PM
Thanks for your help, nothing was wrong with your code.  As you have previously advised the updown position needed to be changed in the Arduino code due to mixing of wires (my error) when routing wires on build.  Thanks again for your help.


Dan
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on August 21, 2015, 03:29:46 AM
Steve is it possible for you to make a diagram of the arduino ?

Thanks

Fede
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 26, 2015, 09:53:09 PM
Can you help me out. I'm new to the Arduino stuff. I got it working with normal leds but would rather use a pwm signal to operate my led driver instead of the 4 outputs to leds. any chance you can help me out with a modified code?
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 27, 2015, 07:45:35 AM
Hi,

Fede, there is a diagram on the first page.. Let me know what more you need.

Rcfiddy1
. no probs, I've not seen one of these LEDs before. How do they work?  Txs
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 27, 2015, 09:58:40 AM
They are great, extremely bright. The led driver can power up to 10 of these once, so I will run 1 driver and 4 leds. 2-red in front and 2-green in rear. I can take a pwm signal from the arduino pin 9 to the driver board PWM and it should blink them just like the original led code. I might just need to modify the code for the pwm analog write. Still trying to figure it out.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on August 27, 2015, 03:43:22 PM
Yep, will need to rewrite the LED sub so it has analogWrite(ledPin, Value);

You can try replacing the turnledoff and turnledon with the below;



 void turnledoff() {
   analogWrite(led4, 0);
  }
  void turnledon() {
   analogWrite(led4, 255); 
}


might also need to get rid of the set up line - pinMode(led4, OUTPUT);         // Assign output mode to pin for LED 4



Let me know if this works.


Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 28, 2015, 10:11:32 PM
Thanks a million....Its working..I just needed tp switch the analogWrite to 255 for off and 0 to on.
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on August 29, 2015, 01:45:22 PM
Steve I don't get the part where you want me to connect the signal in from Rx and then to the receiver. Any help would be highly appreciated.

Thanks
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 29, 2015, 09:31:03 PM
Here is the way mine is working.
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on August 29, 2015, 09:34:20 PM
Steve I don't get the part where you want me to connect the signal in from Rx and then to the receiver. Any help would be highly appreciated.

Thanks

You need to take your gear channel (say ch5)from receiver and the orange or white wire is the signal wire. That wire will go to the Arduino pin D2. Pin D3 is the orange or white wire from servo. The way I wired my Arduino is, I connected 5 JST connectors to the Arduino board. Than the other side will connect to correct wires from receiver and switches,etc. That way I can just unplug it if I need to.
http://www.ebay.com/itm/Clearance-100mm-JST-Line-JST-Connector-Plug-f-RC-BEC-LIPO-BATTERY-10-pairs-EM-01/311387405628?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D333008%26algo%3DRIC.MBE%26ao%3D1%26asc%3D33097%26meid%3Dea95730e40a24615ad43c94a75e4afb1%26pid%3D100011%26rk%3D3%26rkt%3D10%26mehot%3Dag%26sd%3D311325201505
Title: Re: Inspire Clone Electronics
Post by: eaglesight on September 01, 2015, 12:16:29 AM
any one in usa can program this thing I'm lost i get the wires to unit and receiver signal wire to unit but lost on rest. hell ill send you all the stuff. not a board person or programer. lol
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on September 01, 2015, 05:08:58 PM
Steve I don't get the part where you want me to connect the signal in from Rx and then to the receiver. Any help would be highly appreciated.

Thanks

You need to take your gear channel (say ch5)from receiver and the orange or white wire is the signal wire. That wire will go to the Arduino pin D2. Pin D3 is the orange or white wire from servo. The way I wired my Arduino is, I connected 5 JST connectors to the Arduino board. Than the other side will connect to correct wires from receiver and switches,etc. That way I can just unplug it if I need to.
http://www.ebay.com/itm/Clearance-100mm-JST-Line-JST-Connector-Plug-f-RC-BEC-LIPO-BATTERY-10-pairs-EM-01/311387405628?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D333008%26algo%3DRIC.MBE%26ao%3D1%26asc%3D33097%26meid%3Dea95730e40a24615ad43c94a75e4afb1%26pid%3D100011%26rk%3D3%26rkt%3D10%26mehot%3Dag%26sd%3D311325201505 (http://www.ebay.com/itm/Clearance-100mm-JST-Line-JST-Connector-Plug-f-RC-BEC-LIPO-BATTERY-10-pairs-EM-01/311387405628?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D333008%26algo%3DRIC.MBE%26ao%3D1%26asc%3D33097%26meid%3Dea95730e40a24615ad43c94a75e4afb1%26pid%3D100011%26rk%3D3%26rkt%3D10%26mehot%3Dag%26sd%3D311325201505)

Okay, much better. What do you mean with tapped off?

Thanks
Title: Re: Inspire Clone Electronics
Post by: eaglesight on September 01, 2015, 05:18:35 PM
trying mine little different, using a 360 servo with the (2) 3a limit switch and 2 diodes  and the wires going into the servo motor lead off the board
Title: Re: Inspire Clone Electronics
Post by: yen on September 08, 2015, 07:58:36 AM
Help guys,,,


burnt 2 servo already. Tower Pro 360. Become heated up and dead.  i set voltage to 6.8v on stepper DC converter.
Then i replace another servo and happy for 5 minute. :) . Burnt.....
Title: Re: Inspire Clone Electronics
Post by: Dibbler666 on September 08, 2015, 04:01:41 PM
Hi Yen,
I had similar issue but was doing the lifting/lowering when it was on the ground (as you do when testing)
Suggest you put a block under the frame so the legs aren't on the table/ground when testing. That way it is not under strain from lifting the weight of the chassi.
Bear in mind when the rotors are turning they will assist in the raising of the legs.
I bought a replacement Tower Pro and did the conversion to 360 myself and haven't had an issue since following my advise above.
Title: Re: Inspire Clone Electronics
Post by: eaglesight on September 08, 2015, 04:13:36 PM
did you do the mode with the limit switches wired into the servo with 2 diodes
Title: Re: Inspire Clone Electronics
Post by: Dibbler666 on September 08, 2015, 04:16:58 PM
Nope, I added 2x 2.2K resistors and removed the limiting pin from the cog. Youtube has a good video.
https://youtu.be/cnOKG0fvZ4w

Title: Re: Inspire Clone Electronics
Post by: yen on September 09, 2015, 01:40:58 AM
tq guys,


btw have to wait for servo... ;)


Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 09, 2015, 06:34:19 PM
Can someone confirm this. Using the Arduino, the microswitches should be wired as follows.
common---signal wires
N-O of both switches wired together for either pos or neg on Arduino
N.C of both switches wired together for either pos or neg on Arduino.

Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on September 09, 2015, 08:38:28 PM
Yes, that's correct.

To test, unconnect your servo but set it in the middle position so not touching either of the switches. When you first turn on nothing will move, this is coded in so no fingers get trapped. Flip your controller switch and you should see your led's start to flash. Now, click one of your switches with a screwdriver and hold it down. If your LED's go solid then you know this is the direction your servo should be moving for that switch on your controller. Flip the switch and double check the other microswitch.  Lastly connect the servo up and make sure its driving the right way. It will burn out if it's going in the opposite direction.  If it needs reversing you can just swap the pin numbers in the top of the code and reprogram.

You can also check with a multi-meter that the + and - (NC / NO ) pins on the switch never see each other when activated.

Does this all make sense?
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 09, 2015, 08:41:12 PM
Yes, I actually had it working. But my mental lapse caused me to forget how I wired it. I than needed to redesign the lower block that holds the switches and took it apart....lol.....forgot how I wired it.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on September 09, 2015, 08:43:13 PM
I'm on my third servo too.. lol I did the same thing 'TWICE'  so you're not alone.
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 09, 2015, 08:45:38 PM
I was so close to finishing. Wired up my motors and LEDs. Now just need to tidy it all up and try to fit it all under the Dji canopy.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on September 09, 2015, 09:01:45 PM
Yeah, been there :-)


Not sure you want these but I've designed some simple hooks so I can hang mine on the wall. They fit the new larger feet I did.  Will need two of them, just screw em to a wall the right distance apart and hand it up :-)
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 09, 2015, 09:03:02 PM
Cool, thanks. I will be printing the bigger feet soon as I add a gimbal.
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 16, 2015, 01:56:47 AM
Anyone have any pics of your wiring? I am almost complete and trying to fit in all my wires but struggling with it.
Title: Re: Inspire Clone Electronics
Post by: yen on September 16, 2015, 06:41:30 AM
Here my half finish wire array.....
Title: Re: Inspire Clone Electronics
Post by: yen on September 16, 2015, 10:06:59 AM
more pic...
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on September 16, 2015, 04:17:22 PM
more pic...

YEN do you have better quality images? it also seems that you did not use the naza, is that correct?
Title: Re: Inspire Clone Electronics
Post by: yen on September 16, 2015, 04:25:57 PM
here....im flying with APM mini....
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on September 17, 2015, 05:48:42 PM
How do I knwo which lenght of which M3 screw goes in each hole? Do i just need to guess?
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 17, 2015, 06:04:22 PM
Pretty much guess. but heres a list of amounts and length of what I used and where.
Motor mounts-6x35mm
Outer arm joints 6x25mm and 2x35mm for cf tube
Inner arm joints 2x40mm for cf tube, 6x15mm
Canopy 4x30mm
The rest should be easy to figure out.
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on September 17, 2015, 06:08:37 PM
I got 50 of each so I should be fine. Thanks rcfiddy.
Title: Re: Inspire Clone Electronics
Post by: yen on September 19, 2015, 05:24:59 PM
what a nice day.... ;D ;D ;D
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on September 19, 2015, 10:16:00 PM
Nice....
Title: Re: Inspire Clone Electronics
Post by: Eltrocha on September 30, 2015, 01:03:01 AM
I would greatly appreciate if you guys could help me in my topic.

Thanks a lot.

http://diyrc.co.uk/inspire-build-diaries/my-build!!-(under-construction-still)-help!/msg866/?topicseen#new
Title: Re: Inspire Clone Electronics
Post by: Salona on October 10, 2015, 02:15:14 PM

To control the movement of the legs / leds I've used an Arduino nano. This is a small hobby microprocessor that only costs about £5.00. I'm by no means an expert and this code can most likely be greatly improved on. If you would like to improve on it then please do, I would be happy for the help :-)

You will need to program this with the below code for it to work correctly and wire the pins up.

Code: [Select]

// Designed for Skull Quadcopter
// Rev 1.0


#include <Servo.h>
#include <PinChangeInt.h>




// Define RX variables
#define PIN1 2
#define PIN1dataReg PIND
#define pin1state (PIN1dataReg & (1 << PIN1))
volatile long pulseStart1; // pulse start time measured from millies in ISR for pin 1
volatile long pulseTime1; // pulse width time measured from millies in ISR for pin 1 <-- this is the output we require


Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position


// Define Microswitch pins
const int msdown = 5;
const int msup = 4;
int msdownstate = 0;
int msupstate = 0;


// Define Variables for LEDs
int led1 = 6;                    // output pin for LED 1
int led2 = 7;                    // output pin for LED 2
int led3 = 8;                    // output pin for LED 3
int led4 = 9;                    // output pin for LED 4
int led13 = 13;                   // onboard LED indictor incase no others are attached
unsigned long time;              // holds current time for change of state
int flashtime = 400;            // time to flash LEDs in milliseconds
boolean ledon = false;         // remembers start of LED
boolean movedown = true;      // safety feature
boolean moveup = true;        // safety feature


// The below procedure handles the pulse from the RX input
void handlePin1() 

  if(pin1state) 
    pulseStart1=micros(); // we got a positive edge 
  else 
    pulseTime1=micros()-pulseStart1; // Negative edge: get pulsewidth 



// LED Control - very basic, can be expanded.
 void turnledoff() {
    digitalWrite(led1, LOW);     
    digitalWrite(led2, LOW);     
    digitalWrite(led3, LOW);     
    digitalWrite(led4, LOW);
    digitalWrite(led13, LOW);   
  }
  void turnledon() {
    digitalWrite(led1, HIGH);     
    digitalWrite(led2, HIGH);     
    digitalWrite(led3, HIGH);     
    digitalWrite(led4, HIGH);     
    digitalWrite(led13, HIGH); 
}
  void flashled() {
      // LED Flash
  if (millis() - time > flashtime){
      time = millis();
     
      if (ledon){
        turnledoff();
        ledon = false;
      } else {
        turnledon();
        ledon = true;
      }
     
  }


  }


// Lets set everything up
void setup() {
 // initialize serial communication at 115200 bits per second so we can see whats going on:
  Serial.begin(115200);
 
  pinMode(PIN1, INPUT);          // Initialize rx input pin
  digitalWrite(PIN1, HIGH);      // Set the rx pin to High to start the counter
  PCintPort::attachInterrupt(PIN1, &handlePin1, CHANGE); // Attach the interrupt
 
  pinMode(led1, OUTPUT);         // Assign output mode to pin for LED 1
  pinMode(led2, OUTPUT);         // Assign output mode to pin for LED 2
  pinMode(led3, OUTPUT);         // Assign output mode to pin for LED 3
  pinMode(led4, OUTPUT);         // Assign output mode to pin for LED 4
  pinMode(led13, OUTPUT);         // Assign output mode to pin for LED 4


  pinMode(msup, INPUT);
  pinMode(msdown, INPUT);
  msupstate = digitalRead(msup);
  msdownstate = digitalRead(msdown);
  time = millis();               // Save current millis reading (this is a counter that always runs in milliseconds)
  turnledon();
 }


// Main Program
void loop() {
 
  msupstate = digitalRead(msup);
  msdownstate = digitalRead(msdown);
  // read the input channels


   if (pulseTime1 > 900 && pulseTime1 < 1300){ //legs down
   myservo.attach(3);
    pos = 0;
    moveup = true;
    if (msupstate == LOW){
      if (movedown){myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      movedown = false;
      myservo.detach();
      turnledon();
    }
   }
    if (pulseTime1 > 1299 && pulseTime1 < 1701){ //no movement
    myservo.detach();
   
    pos = 100;
   }
   
  if (pulseTime1 > 1700) { //legs up
  myservo.attach(3);
    pos = 180;
    movedown = true;
    if (msdownstate == LOW){
       if (moveup) {myservo.write(pos);}
    flashtime = 200;
    flashled();
    } else {
      moveup = false;
      turnledon();
      myservo.detach();
    }
  } 
   
}








INFORMATION

1. You will need to download the Arduino program from arduino.cc and install.
2. I have also used an extra interrupt library which you will also need to install from https://code.google.com/p/arduino-pinchangeint/downloads/list (https://code.google.com/p/arduino-pinchangeint/downloads/list) and unzip and copy it into C:\Program Files (x86)\Arduino\libraries\PinChangeInth
3. Open up the arduino software and plug in your arduino nano, you will now need to set the port / board type from the drop down menus. Paste the boards code in above and upload.

(http://diyrc.co.uk/images/quad-arduino.jpg)

The 3A DC-DC converter is used to output 7.2 volts to the servo, this increases the transforming speed.
Both microswitches have a positive and negative input. They output with positive OR negative depending if the switch is active. This is required as if no input is received by the arduino it can actually change it's self as it would be floating. You could use a pull down resistor but I thought this way would be easier and less components required.
The LED pins output 5v's and receive an negative feed off the ESC in the foot. You only need to feed the signal wire from the ESC up the leg. At the moment the LEDs are on normally and flash when transforming. I think I'll look at adding a voltage divider so they can flash when your lipo is getting low as an indicator.


Hi. I've just tried to load the sketch onto my Arduino Nana but keep getting the following message:

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Nano, ATmega328"


Inspire_One_Nano.ino:8:26: fatal error: PinChangeInt.h: No such file or directory
compilation terminated.
Error compiling.


I have the PinChangeInt library in the Arduino/Libraries folder but can't get the sketch to compile. Has anyone else had the same problem?
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on October 10, 2015, 02:47:34 PM
Make sure you restart the arduino after you copynthe folder across otherwise it won't find it can cause the error you're getting
Title: Re: Inspire Clone Electronics
Post by: Salona on October 10, 2015, 03:36:03 PM
Thanks, that worked a treat. I have a new problem now though. There is no usb serial option showing in the Port drop down menu, only Bluetooth-Incoming Port and Bluetooth-Modem. Weird! I downloaded the latest Apple signed FTDI drivers but there is still no USB-Serial option.
Title: Re: Inspire Clone Electronics
Post by: Salona on October 10, 2015, 07:49:36 PM
Got it sorted. Apparently Arduino Nano's don't like Macs. Never had a problem with Uno or Mega boards but had to use a Windows pc to upload the sketch to the Nano board.
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on October 17, 2015, 02:10:20 AM
Hi,

I have a Arduino Pro mini. Will the sketch work on this board? Would I have to change the pin configuration in the sketch to suit this board?

I'm new to this so any help would be much appreciated.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Nobby on November 05, 2015, 04:58:14 PM
Can I power all the components with one NAZA PMU v2 unit (output 7.2 V - 3A) ? I mean: NAZA-controller, Radio Receiver, Arduino and Servo ? Or do I need a other one (Step-up Power Converter) specially for the Servo (and maybe the Arduino)? I am worried that the Servo might drain to much power when moving the legs ! (and the controller or receiver will stop working). Can any one tell me how to power my components ?
Title: Re: Inspire Clone Electronics
Post by: revo442 on November 14, 2015, 11:06:17 PM
I can wait to get started.  my question which might have been answered, is there a complete electronic parts list?
Title: Re: Inspire Clone Electronics
Post by: rcfiddy1 on November 15, 2015, 07:43:16 AM
Can I power all the components with one NAZA PMU v2 unit (output 7.2 V - 3A) ? I mean: NAZA-controller, Radio Receiver, Arduino and Servo ? Or do I need a other one (Step-up Power Converter) specially for the Servo (and maybe the Arduino)? I am worried that the Servo might drain to much power when moving the legs ! (and the controller or receiver will stop working). Can any one tell me how to power my components ?
I would advise against that. It's best to power the servo thru a DC-DC convertor direct from battery. You don't want to draw from naza pmu and risk a brown out. I suggest a power distribution board with bec for arduino and you can run batt voltage from board to naza pmu and motors, and DC-DC convertor. You can run a fuse inline servo in case of issues it will blow and not burn out anything.
Title: Re: Inspire Clone Electronics
Post by: Nobby on November 15, 2015, 12:30:00 PM
Thanks, rcfiddy1. I thought so. I'll first buy a dc-dc converter than before I try anything.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 20, 2015, 05:20:21 AM
I really need help here, please.
Ok, I've got PinChangeInt H file, and Servo H File inside Libraries at C:\Program Files (x86)\Arduino\libraries\ the problem now is that they don't show any files ending in .ino or .pde when clicked on them in libraries. For that reason when I try to open them using Arduino 1.0.6, nothing happens. Only a sign asking for .ino and .pde. endings I downloaded them several times with same bad result.
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 20, 2015, 01:06:42 PM
I really need help here, please.
Ok, I've got PinChangeInt H file, and Servo H File inside Libraries at C:\Program Files (x86)\Arduino\libraries\ the problem now is that they don't show any files ending in .ino or .pde when clicked on them in libraries. For that reason when I try to open them using Arduino 1.0.6, nothing happens. Only a sign asking for .ino and .pde. endings I downloaded them several times with same bad result.

Hi Bioethical,

Firstly, delete whatever files you have put into C:\Program Files (x86)\Arduino\libraries\

Now download the following zip file.

https://code.google.com/p/arduino-pinchangeint/downloads/detail?name=pinchangeint-v2.19beta.zip&can=2&q=http:// (https://code.google.com/p/arduino-pinchangeint/downloads/detail?name=pinchangeint-v2.19beta.zip&can=2&q=http://)


Now extract the folders from the zip file and copy the folders (3 of them) into C:\Program Files (x86)\Arduino\libraries\

If asked to replace folders and files, replace all of them.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 21, 2015, 05:12:48 AM
Hello Mongrel,
Thank you much for your suggestion but it didn't work. These is what I got from PinChangeInt from Libraries:

Examples              (date)  file folder
gpl                        (date)  text doc
key words            (date)  text doc
PinChangeInt       (date)  H file
RELEASE NOTES   (date)  file

There is no .ino or .pde files in there. Same problem as before. I may be missing something. Could you try your link again please?

Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 21, 2015, 05:38:19 AM
Hello Mongrel,
Thank you much for your suggestion but it didn't work. These is what I got from PinChangeInt from Libraries:

Examples              (date)  file folder
gpl                        (date)  text doc
key words            (date)  text doc
PinChangeInt       (date)  H file
RELEASE NOTES   (date)  file

There is no .ino or .pde files in there. Same problem as before. I may be missing something. Could you try your link again please?

The above is all that you need.

Run the sketch and load it onto your arduino board.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 21, 2015, 05:46:24 AM
Should I run only the PinChangeInt H file, and loaded  into the card?
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 21, 2015, 11:11:05 AM
Should I run only the PinChangeInt H file, and loaded  into the card?

Just load the the sketch that's at the beginning of this post (page 1) onto your arduino board. The sketch will use the info in the libraries folder.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 21, 2015, 05:19:24 PM
Mongrel,
Sorry for my ignorance on this. So  the whole sketch on the first page  is to be copied and pasted on Arduino, right?

Yes the whole sketch and then follow the instructions in the first post.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 22, 2015, 03:56:47 AM
Hello Mongrel, now I can see a light at the end of the tunnel, thanks to you.  When I pasted the script made by Skull on the sketch of Arduino and opened it in Libraries, the other files disappeared and I can see only the little green circle and "file sketch_nov21a" , it seems that PincChangeInt and the other family files were absorbed by this sketch  that is now on Libraries.  Then I verified it with the Arduino card connected and uploaded it. What I finally got at the window at the bottom of Arduino is the following:

Binary sketch Size: 6,354 bytes of a 30720 byte maximum.

Dos this mean that I am ready to assemble the circuit for the servo?

Thank you for your generosity man.
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 22, 2015, 04:19:03 AM
Hello Mongrel, now I can see a light at the end of the tunnel, thanks to you.  When I pasted the script made by Skull on the sketch of Arduino and opened it in Libraries, the other files disappeared and I can see only the little green circle and "file sketch_nov21a" , it seems that PincChangeInt and the other family files were absorbed by this sketch  that is now on Libraries.  Then I verified it with the Arduino card connected and uploaded it. What I finally got at the window at the bottom of Arduino is the following:

Binary sketch Size: 6,354 bytes of a 30720 byte maximum.

Dos this mean that I am ready to assemble the circuit for the servo?

Thank you for your generosity man.

Yes, you're right to go. Just follow the wiring diagram in the first post.

For the wiring of the endstops: http://diyrc.co.uk/index.php?action=dlattach;topic=52.0;attach=457;image

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 23, 2015, 01:52:28 AM
Could You please check if my wiring plan is correct?  I don't want to fry anything more.
Title: Re: Inspire Clone Electronics
Post by: Ptimaicosto on November 23, 2015, 08:26:45 AM
I doesn't see anything wrong... except that there is no LED and your endstop won't fit in the clone.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 28, 2015, 04:18:11 AM
Hello friends, I am finishing the wiring of the arduino, micro switches and servo motor.  According to my motor housing printed parts I need to install four LEDs at front of the drone and four at rear? ( two for lifting and two for lowering both front and rear)  I have some questions: 1) four LEDs light up solid when lifting the legs and four LEDs blinking when lowering or viceversa, right?
2) What order of pins in arduino should I use for the 8 LEDs?  3) Can I take the Negative for the LEDs from the power board only temporarily for testing everything outside the Quad copter?  4) Can I connect  the LEDs positives and negatives legs on serial way?
5) should I modify my servo motor  to 360 degrees befor to do any test? This is all the information I need to do my electronics test and then proceed to finally assemble my Inspire.
Thank you very much,
Vic
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 28, 2015, 06:25:47 AM
Hello friends, I am finishing the wiring of the arduino, micro switches and servo motor.  According to my motor housing printed parts I need to install four LEDs at front of the drone and four at rear? ( two for lifting and two for lowering both front and rear)  I have some questions: 1) four LEDs light up solid when lifting the legs and four LEDs blinking when lowering or viceversa, right?
2) What order of pins in arduino should I use for the 8 LEDs?  3) Can I take the Negative for the LEDs from the power board only temporarily for testing everything outside the Quad copter?  4) Can I connect  the LEDs positives and negatives legs on serial way?
5) should I modify my servo motor  to 360 degrees befor to do any test? This is all the information I need to do my electronics test and then proceed to finally assemble my Inspire.
Thank you very much,
Vic

Vic,

You only need 4 LED's. The LED's will be solid light when the arms are not moving and blinking when they are in either the up or down transition. EACH LED will need a resister on the positive side between the Arduino board and the LED. The voltage of the LED will the determine the resister needed. The power from the Arduino will be 5v at the pin for the LED.

The setup will not work unless the servo is a 360 degree servo.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 29, 2015, 02:24:55 AM
Thank you Mongrel. My LEDs Specs are as follows: 

 3 Leds 5mm like this                                                Vf    2.6V Max
                                                                                 Vr    5V  Max
                                                                                  Pd  100mW Max
                                                                                  If    25mA Max
                                                                                  Iv    2500mcd Typ     

3 leds 5mm like this:                                                  Vf    2.4V Max
                                                                                 Vr    5V  Max
                                                                                  Pd  100mW Max
                                                                                  If    25mA Max
                                                                                  Iv    2500mcd Typ       

What resistors should I use?                                                           
Title: Re: Inspire Clone Electronics
Post by: Airmongrel on November 29, 2015, 03:18:33 AM
Thank you Mongrel. My LEDs Specs are as follows: 

 3 Leds 5mm like this                                                Vf    2.6V Max
                                                                                 Vr    5V  Max
                                                                                  Pd  100mW Max
                                                                                  If    25mA Max
                                                                                  Iv    2500mcd Typ     

3 leds 5mm like this:                                                  Vf    2.4V Max
                                                                                 Vr    5V  Max
                                                                                  Pd  100mW Max
                                                                                  If    25mA Max
                                                                                  Iv    2500mcd Typ       

What resistors should I use?                                                           

A 300 ohm resistor on each LED will work for you.

Mongrel.
Title: Re: Inspire Clone Electronics
Post by: Bioethical on November 29, 2015, 10:53:39 PM
I need More help please, It's good news that  the servo motor is rotating 360 degrees CW and CCW using the Gear Stick on my remote control, THANK YOU VERY MUCH.
 The only problem now is  that one of the end stops needs to be clicked on in order for the servo motor rotate to one side and the other end stop needs to be clicked on  for the servo to turn to the other side, alternating the position of the stick.   I'm  powering the radio receptor  through the Flight Controller and ESC. 
How can I solve to make the end stops to work without touching them? 
Your kind help will be appreciated.
Vic
Title: Re: Inspire Clone Electronics
Post by: ALE2759 on March 15, 2016, 03:26:03 PM


Hello, I went around to find a simple solution alternative to Arduino Nano. Just because I arduino programming I understand little.
I found this solution by removing the servo electronics and chart using only the engine and gearbox and perhaps using this small card works equally?
What do you think?
Alessandro


http://www.microbot.it/documents/mr001-003_datasheet_it.pdf


Excuse my horrible English by "google translator"
Title: Re: Inspire Clone Electronics
Post by: Bioethical on March 15, 2016, 04:00:07 PM
Yo lo veo buenisimo, practico y simple. Tenemos que probarlo. Gracias por la aportacion
Title: Re: Inspire Clone Electronics
Post by: enis1979 on May 24, 2016, 12:22:47 PM
hi...Have a complete wiring diagram of the project ?
Title: Re: Inspire Clone Electronics
Post by: indotronic on June 25, 2016, 07:42:00 AM
Hi, have the list electronic parts in excel file?
and,
what is the featured the this Inspire Clone?
Title: ARDUINO code part Deux
Post by: cghelobubba on January 16, 2017, 03:44:48 AM
A slight variation on SKULLs code.  It adds a SONAR sensor mounted to the diving board on the nose.  My gimbal and camera are mounted underneath the main body.  The SONAR does two things.  1) inhibits gear-up command when the aircraft is on the ground and 2) auto extends the gear when the aircraft is within 3 feet of the deck.  I used a HC-SR04 sensor, works great.  Sketch is fairly self-explanatory on what pins go where.  All the other wiring is basically the same as Skulls original design.  Also, this code eliminates the need to implement pinChangeInterrupt and replaces it with pulseIn.  I was worried that pulseIn would be inefficient, but it turned out to be negligible.  Thanks SKULL for your original posting.


...my next challenge is going to be figuring out terrain following with a LIDAR...  I love this hobby.




#include <Servo.h>


//SONAR Trigger & Echo
#define trigPin 12
#define echoPin 11


volatile long pwm_signal;
const int up_switch = 4;
const int dn_switch = 5;
const int flashtime = 200;
const int servoPin;
int up_switch_state = false;
int dn_switch_state = false;
int command = 0;
boolean ledon = false;
unsigned long time;
boolean in_air = false;
boolean takeoff_complete = false;
int distance = 0;


Servo gearServo;


int led1 = 6;
int led2 = 7;
int led3 = 8;
int led4 = 9;
int led13 = 13;


// LED Control
void turnledoff() {
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led13, LOW);
}
void turnledon() {
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led13, HIGH);
}
void flashled() {
   // LED Flash
   if (millis() - time > flashtime) {
      time = millis();


      if (ledon) {
         turnledoff();
         ledon = false;
      }
      else {
         turnledon();
         ledon = true;
      }


   }
}


int ping_distance() { //SONAR Sensor - I used a HC-SR04, it has a trigger and echo pin.  Works like a champ
   long duration, distance;
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
   duration = pulseIn(echoPin, HIGH);
   distance = (duration / 2) / 29.1; //distance in CM.
   delay(500); // this is a pretty big delay - make sure this function does not get exposed to the main loop when gear is transiting
   return distance;
}
void setup()
{
   Serial.begin(115200);
   gearServo.attach(3);
   pinMode(up_switch, INPUT);
   pinMode(dn_switch, INPUT);
   pinMode(led1, OUTPUT);         // Assign output mode to pin for LED 1
   pinMode(led2, OUTPUT);         // Assign output mode to pin for LED 2
   pinMode(led3, OUTPUT);         // Assign output mode to pin for LED 3
   pinMode(led4, OUTPUT);         // Assign output mode to pin for LED 4
   pinMode(led13, OUTPUT);         // Assign output mode to pin for LED 4
   turnledon();
   //SONAR Setup
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
}


void loop()
{
   up_switch_state = digitalRead(up_switch);
   dn_switch_state = digitalRead(dn_switch);
   pwm_signal = pulseIn(2, 2000); //pulseIn works fine, other versions I've seen use pin interrupts - not needed in this case
   gearServo.attach(3);
   if (pwm_signal > 900 && pwm_signal < 1200) { command = 1; } //gear down switch postion - you might have to adjust these ranges.
   else if (pwm_signal > 1800 && pwm_signal < 2000) { command = 2; } // gear up switch position - ditto
   else { command = 0; }
   switch (command) {
   case 1:
      if (dn_switch_state) { //gear not down =  switch state on.  this can get confusing when you are wiring your switches.
         gearServo.write(10); //send the drive screw clockwise, again - check your set up.  I burned through a couple of servos before I got this right.
         flashled(); // make a fancy flash for your lights while transiting
      }
      else { //once the gear are down, as indiacted by a !dn_switch state, stop the servo.  This keeps power on the servo to eliminate back drive.  Not sure how the servo will do over time.   I used an off the shelf continuous rotation
            //continuous rotation servo that was well behaved at 90.  If you modded a servo you might need to adjust this number to make the servo stop.
         turnledon();
         gearServo.write(90);
         distance = ping_distance(); //notice that this is called only when NOT writing to the servo.  That 500 msec delay would not play nice here
         //Serial.println(distance);  //debug
      }
      break;
   case 2:


      //gear up is a special case - this logic (in_air) inhibits raising the gear when the Inspire is on the ground -
      //saves some embarassement and possibly a good camera and gimbal.  Takeoff_complete was added to ensure that the gear do not
      //retract once the proximity sensor senses that your going to land and the gear switch on the transmitter is still in the
      //up postion.
      if (up_switch_state && in_air && takeoff_complete) {
         gearServo.write(170);
         flashled();
      }
      else {
         turnledon();
         gearServo.write(90);
         distance = ping_distance();
         Serial.println(distance);
      }
      break;
   default:
      turnledon();
      break;
   }
   if (distance < 20 && !takeoff_complete) { //this sets the logic variables for on ground gear-up inhibit and landing proximity gear down
      in_air = false;
   }
   else {
      in_air = true;
      takeoff_complete = true;
   }
   if (takeoff_complete && distance < 91 && command == 2) { //when you are below about 3 feet with the gear switch on the tranmitter still in gear-up position
      flashled();
      while (dn_switch_state) {
         dn_switch_state = digitalRead(dn_switch); //cycles the gear down
         gearServo.write(10);
      }
      takeoff_complete = false; //keeps the gear from recycling back up if the gear switch on transmitter is still up.
                          //I request a 10% cut on all $400 GO-PRO cameras that were NOT crushed by a gear up landing.
   }
}
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on January 20, 2017, 08:24:29 AM
very nice. Have you tested the sonar out yet at all ?
Title: Re: ARDUINO code part Deux
Post by: leraver on January 20, 2017, 01:25:00 PM
Fred c'est toi?


A slight variation on SKULLs code.  It adds a SONAR sensor mounted to the diving board on the nose.  My gimbal and camera are mounted underneath the main body.  The SONAR does two things.  1) inhibits gear-up command when the aircraft is on the ground and 2) auto extends the gear when the aircraft is within 3 feet of the deck.  I used a HC-SR04 sensor, works great.  Sketch is fairly self-explanatory on what pins go where.  All the other wiring is basically the same as Skulls original design.  Also, this code eliminates the need to implement pinChangeInterrupt and replaces it with pulseIn.  I was worried that pulseIn would be inefficient, but it turned out to be negligible.  Thanks SKULL for your original posting.


...my next challenge is going to be figuring out terrain following with a LIDAR...  I love this hobby.




#include <Servo.h>


//SONAR Trigger & Echo
#define trigPin 12
#define echoPin 11


volatile long pwm_signal;
const int up_switch = 4;
const int dn_switch = 5;
const int flashtime = 200;
const int servoPin;
int up_switch_state = false;
int dn_switch_state = false;
int command = 0;
boolean ledon = false;
unsigned long time;
boolean in_air = false;
boolean takeoff_complete = false;
int distance = 0;


Servo gearServo;


int led1 = 6;
int led2 = 7;
int led3 = 8;
int led4 = 9;
int led13 = 13;


// LED Control
void turnledoff() {
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   digitalWrite(led13, LOW);
}
void turnledon() {
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led13, HIGH);
}
void flashled() {
   // LED Flash
   if (millis() - time > flashtime) {
      time = millis();


      if (ledon) {
         turnledoff();
         ledon = false;
      }
      else {
         turnledon();
         ledon = true;
      }


   }
}


int ping_distance() { //SONAR Sensor - I used a HC-SR04, it has a trigger and echo pin.  Works like a champ
   long duration, distance;
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
   duration = pulseIn(echoPin, HIGH);
   distance = (duration / 2) / 29.1; //distance in CM.
   delay(500); // this is a pretty big delay - make sure this function does not get exposed to the main loop when gear is transiting
   return distance;
}
void setup()
{
   Serial.begin(115200);
   gearServo.attach(3);
   pinMode(up_switch, INPUT);
   pinMode(dn_switch, INPUT);
   pinMode(led1, OUTPUT);         // Assign output mode to pin for LED 1
   pinMode(led2, OUTPUT);         // Assign output mode to pin for LED 2
   pinMode(led3, OUTPUT);         // Assign output mode to pin for LED 3
   pinMode(led4, OUTPUT);         // Assign output mode to pin for LED 4
   pinMode(led13, OUTPUT);         // Assign output mode to pin for LED 4
   turnledon();
   //SONAR Setup
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
}


void loop()
{
   up_switch_state = digitalRead(up_switch);
   dn_switch_state = digitalRead(dn_switch);
   pwm_signal = pulseIn(2, 2000); //pulseIn works fine, other versions I've seen use pin interrupts - not needed in this case
   gearServo.attach(3);
   if (pwm_signal > 900 && pwm_signal < 1200) { command = 1; } //gear down switch postion - you might have to adjust these ranges.
   else if (pwm_signal > 1800 && pwm_signal < 2000) { command = 2; } // gear up switch position - ditto
   else { command = 0; }
   switch (command) {
   case 1:
      if (dn_switch_state) { //gear not down =  switch state on.  this can get confusing when you are wiring your switches.
         gearServo.write(10); //send the drive screw clockwise, again - check your set up.  I burned through a couple of servos before I got this right.
         flashled(); // make a fancy flash for your lights while transiting
      }
      else { //once the gear are down, as indiacted by a !dn_switch state, stop the servo.  This keeps power on the servo to eliminate back drive.  Not sure how the servo will do over time.   I used an off the shelf continuous rotation
            //continuous rotation servo that was well behaved at 90.  If you modded a servo you might need to adjust this number to make the servo stop.
         turnledon();
         gearServo.write(90);
         distance = ping_distance(); //notice that this is called only when NOT writing to the servo.  That 500 msec delay would not play nice here
         //Serial.println(distance);  //debug
      }
      break;
   case 2:


      //gear up is a special case - this logic (in_air) inhibits raising the gear when the Inspire is on the ground -
      //saves some embarassement and possibly a good camera and gimbal.  Takeoff_complete was added to ensure that the gear do not
      //retract once the proximity sensor senses that your going to land and the gear switch on the transmitter is still in the
      //up postion.
      if (up_switch_state && in_air && takeoff_complete) {
         gearServo.write(170);
         flashled();
      }
      else {
         turnledon();
         gearServo.write(90);
         distance = ping_distance();
         Serial.println(distance);
      }
      break;
   default:
      turnledon();
      break;
   }
   if (distance < 20 && !takeoff_complete) { //this sets the logic variables for on ground gear-up inhibit and landing proximity gear down
      in_air = false;
   }
   else {
      in_air = true;
      takeoff_complete = true;
   }
   if (takeoff_complete && distance < 91 && command == 2) { //when you are below about 3 feet with the gear switch on the tranmitter still in gear-up position
      flashled();
      while (dn_switch_state) {
         dn_switch_state = digitalRead(dn_switch); //cycles the gear down
         gearServo.write(10);
      }
      takeoff_complete = false; //keeps the gear from recycling back up if the gear switch on transmitter is still up.
                          //I request a 10% cut on all $400 GO-PRO cameras that were NOT crushed by a gear up landing.
   }
}
Title: Re: Inspire Clone Electronics
Post by: cghelobubba on January 22, 2017, 05:29:59 AM
very nice. Have you tested the sonar out yet at all ?


Yes.  Works like a champ.  There is a bug that cycles the gear up then down if I inadvertently power on the aircraft before the transmitter.  Should be an easy fix, just haven't gotten to it.
Title: Re: Inspire Clone Electronics
Post by: cghelobubba on January 22, 2017, 02:33:42 PM
very nice. Have you tested the sonar out yet at all ?


Yes.  Works like a champ.  There is a bug that cycles the gear if I inadvertently power up the aircraft before the transmitter.  Not a big deal but something I need to go after.
Title: Re: Inspire Clone Electronics
Post by: ehabibrahim on March 11, 2017, 04:08:30 PM
Hi All,

Im still making Inspire and here is the the Err from the Arduino any Help will be great. Thanks

/Users/ehabalmassrey/Documents/Arduino/Drone/Drone.ino:12:0: warning: "PIN1" redefined
 #define PIN1 2
 ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/io.h:627:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/pgmspace.h:90,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:28,
                 from sketch/Drone.ino.cpp:1:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/portpins.h:71:0: note: this is the location of the previous definition
 #define    PIN1         1
 ^
Sketch uses 5408 bytes (37%) of program storage space. Maximum is 14336 bytes.
Global variables use 295 bytes (28%) of dynamic memory, leaving 729 bytes for local variables. Maximum is 1024 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on March 11, 2017, 04:12:33 PM
You might need to set the correct board and port in the options..

Click tools then board and if you are using the nano.. then pick the Arduino Nano 328 most likely.. set the com port and try again.


Thanks,

Steve
Title: Re: Inspire Clone Electronics
Post by: primigen on May 06, 2017, 03:42:47 AM
are you guys using a pdb (power distribution boards) for your esc's? if so where are you mounting it?
Title: Re: Inspire Clone Electronics
Post by: Bioethical on May 06, 2017, 06:53:58 AM
Hi Primigen, I mounted it in the space between the battery and the arms, there is a vertical space there. Please watch my video, maybe you can get to see it.
Title: Re: Inspire Clone Electronics
Post by: primigen on May 08, 2017, 08:02:50 PM
ok thanks i'm going to have to figure out a different spot as i'm trying to fit the biggest battery set up possible. thanks for the reply
Title: Re: Inspire Clone Electronics
Post by: leraver on December 13, 2017, 03:38:33 PM
Hello everyone,
I have a problem I can not find a powerful 360 servo running with the arduino code of the first page of the forum. In addition servo TowerPro MG995 servo seems not to be 360, or so I can not find a good shop.
Can you help me?
Title: Re: Inspire Clone Electronics
Post by: Bioethical on December 14, 2017, 03:07:27 AM
Hi Friend,
check on youtube a tutorial about how to fix your servo motor so it can spin 360. It should be easy. I hacked my servo and it works like a charm.

Vic
Title: Re: Inspire Clone Electronics
Post by: Tempo_cz on January 29, 2018, 05:05:14 PM
please help instructions some instructions how to load the code into arduino nano
Title: Re: Inspire Clone Electronics
Post by: Bioethical on January 30, 2018, 01:21:42 AM
Tempo_cz

1. You will need to download the Arduino program from arduino.cc and install.
2. I have also used an extra interrupt library which you will also need to install from https://code.google.com/p/arduino-pinchangeint/downloads/list and unzip and copy it into C:\Program Files (x86)\Arduino\libraries\PinChangeInth
3. Open up the arduino software and plug in your arduino nano, you will now need to set the port / board type from the drop down menus. Paste the boards code in above and upload.

Check this page to get the main code for your nano card and all the instructions:

http://diyrc.co.uk/3d-printed-inspire-clone/inspire-clone-electronics/

Vic
Title: Re: Inspire Clone Electronics
Post by: Tempo_cz on February 08, 2018, 11:08:49 AM
good day is a blueprint for how to plug electronics please? detailed
Title: Re: Inspire Clone Electronics
Post by: Bioethical on February 08, 2018, 05:33:10 PM
Hi Tempo,
What parts exactly do you want to connect? I could find a drawing or picture for you. Check my picture, maybe it helps.

Vic
Title: Re: Inspire Clone Electronics
Post by: Bioethical on February 08, 2018, 05:44:29 PM
This horrible drawing helped me a lot. Please check it thoroughly and feel free to ask questions.
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 18, 2018, 06:47:59 PM
Hey bioethical could you post the other side of your build with the covers off I'm trying to see how people have all of the electronics set up
Title: Re: Inspire Clone Electronics
Post by: Bioethical on April 18, 2018, 10:28:59 PM
zhadden1989,
Maybe this can help. I put the GPS there before the canopy (covers) existed
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 18, 2018, 10:50:28 PM
yes that did thanks for that.


did you use the dji base plate or did you 3d print one?
Title: Re: Inspire Clone Electronics
Post by: Bioethical on April 19, 2018, 02:16:40 AM
If you mean the base plate for the GPS, I didn't. I affix it down there. Check the picture at the bottom.
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 21, 2018, 02:48:47 AM
No I mean the very bottom plate to the drone
Title: Re: Inspire Clone Electronics
Post by: Bioethical on April 21, 2018, 05:22:51 AM
Actually, I wrongfully bought this canopy that a guy put on sale here which is against the rules of this site because all the design work made by Steven is free of charge but voluntary donations are accepted.
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on April 21, 2018, 12:10:50 PM
Looking good :-)   I didn't mind you buying the canopy at all, looks good in fact. I just didn't really approve of the guy advertising it on here when all files should be free no matter who the author is. That was my original idea anyway. A lot of member including yourself have freely donated your time / designs and ideas which is what has made this forum a success and I'm very grateful for it :-)  I just wish I had some spare time to carry donating like. Hopefully, once my car is finished I can then crack on with a new design.
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 21, 2018, 01:18:00 PM
Steve have you heard of anyone making a printed base plate?
Title: Re: Inspire Clone Electronics
Post by: CdRsKuLL on April 21, 2018, 07:48:16 PM
As in the bottom bit?  Sadly not I'm afraid. I would of thought that part would be printable mind, just need someone to model it up.
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 21, 2018, 08:53:28 PM
If i had one i would model it for sure i might have to find wherebi can get one really cheap.
Title: Re: Inspire Clone Electronics
Post by: zhadden1989 on April 25, 2018, 01:51:30 AM
how do you guys have your leds powered and set up with the arduino.

i was thinking about placing 2 leds epistar leds on the bottom of my copter as a steady flash but have a different flash when the arms in motion as we as have a really fast flash when the battery get below a set point, and also have 4 red led on the front and 4 green led on the back (2 on each side)as a constant on...... do you guys think that this is possible?
Title: Re: Inspire Clone Electronics
Post by: Bioethical on April 25, 2018, 03:00:16 AM
Once again my ugly diagram to the rescue. Connect the positive wires from the legs of the leds to the arduino card on the pins 9, 10, 11, and 12, as in the diagram. The negative leg of the leds can be connected to the negative cables of the ESCs. The arduino is programed to make the leds blink when the arms of the inspire are moving.
Title: Re: Inspire Clone Electronics
Post by: svensoni08@gmail.com on May 31, 2018, 10:05:42 PM
I am programming my arduino nano with this code but it's showing me
Wprogram.h error
So how can i fix this
Please help
Title: Re: Inspire Clone Electronics
Post by: Bioethical on June 01, 2018, 02:47:24 AM
Hello Svenson,
Welcome to the forum.
Your problem may be an error of procedure. Remember that you need to copy the code as it is in the gray area and then paste it on the sketch of the arduino platform. Then proceed to check "tools" before to upload it to your card.
Please read all the posts possible in the Electronics section.
Also, be patient. It'll work.

Vic
Title: Re: Inspire Clone Electronics
Post by: patrick57 on August 27, 2018, 10:04:10 AM
Hello
Wonderful job, what is the final weight of the Inspire clone.
Patrick
Title: Re: Inspire Clone Electronics
Post by: Bioethical on August 28, 2018, 01:24:50 AM
The weight of Inspire including everything and ready to fly is around five pounds (2.7KG)
Title: Re: Inspire Clone Electronics
Post by: jimsford on May 22, 2019, 07:37:58 PM
Is there a wiring drawing of using a NAZA M V2?
Title: Re: Inspire Clone Electronics
Post by: Bioethical on May 22, 2019, 09:55:32 PM
Welcome Friend,

Please Check here:http://diyrc.co.uk/3d-printed-inspire-clone/inspire-clone-electronics/45/
or check my building posts. There should be an unfinished electronics assembly that shows that wiring.
Right now, I'm away from my computer.
Title: Re: Inspire Clone Electronics
Post by: DVA on June 05, 2019, 04:08:11 PM
Bonsoir à tous...je suis en pleine contructions de l'Inspire auquel j'ai modifié la canopy pour un cadre en Lipo 6S, + un support pour gimbal + des pieds amortissables + supports moteurs pour des 5008 340kv...par contre malgré le schéma pour l'arduino ( CdSrKull ) j 'ai une demande de mise à jour de bibliotheques permanente par l'IDE a chaque fois que je met en route l'arduino et je ne retrouve plus le fichier PinChangeInt-Master...
Merci pour votre aide que je puisse avancer et terminer mon projet et creer les videos de partage....
Bons vols à tous.Philippe
Title: Re: Inspire Clone Electronics
Post by: PolitePeople on January 13, 2020, 06:11:56 PM
Hello! Where can I find the connection diagram of the ultrasonic distance sensor?
Title: Re: Inspire Clone Electronics
Post by: Rasta on January 13, 2020, 07:11:55 PM
Look here

https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
Title: Re: Inspire Clone Electronics
Post by: PolitePeople on January 14, 2020, 06:01:37 AM
Thanks for the information! But I meant connecting the ultrasonic sensor precisely in the clone of the Inspire 1 project!
Title: Re: Inspire Clone Electronics
Post by: yang6991906 on March 01, 2020, 05:03:01 AM
Hello, all my wires are connected according to your design! Why doesn't it react when the steering gear is remotely controlled