Author Topic: Inspire Clone Electronics  (Read 66027 times)

Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Inspire Clone Electronics
« 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 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.



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.
« Last Edit: July 10, 2015, 10:42:02 PM by CdRsKuLL »
If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Re: Inspire Clone Electronics
« Reply #1 on: July 10, 2015, 10:53:56 PM »
Little photo of on board arduino programming..

If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline huy507

  • Drinks Maker
  • *
  • Posts: 22
  • Karma: +3/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #2 on: July 18, 2015, 04:36:14 AM »
how can stop servo at middle limit like this

photo as_zpsbdvblhcu.jpg

Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Re: Inspire Clone Electronics
« Reply #3 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
If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline Eltrocha

  • Junior Designer
  • **
  • Posts: 58
  • Karma: +1/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #4 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

Offline huy507

  • Drinks Maker
  • *
  • Posts: 22
  • Karma: +3/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #5 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"
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

photo Capture_zpsvpp11qdm.jpg

Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Re: Inspire Clone Electronics
« Reply #6 on: July 20, 2015, 09:43:35 AM »
Let me know if you need anything from me, good luck with the development. Interesting idea.
If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline rcfiddy1

  • Designer
  • ***
  • Posts: 161
  • Karma: +5/-1
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #7 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

Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Re: Inspire Clone Electronics
« Reply #8 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
If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline rcfiddy1

  • Designer
  • ***
  • Posts: 161
  • Karma: +5/-1
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #9 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.

Offline Eltrocha

  • Junior Designer
  • **
  • Posts: 58
  • Karma: +1/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #10 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
« Last Edit: August 11, 2015, 01:21:00 AM by Eltrocha »

Offline jkralinddd

  • Drinks Maker
  • *
  • Posts: 8
  • Karma: +1/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #11 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.

Offline rcfiddy1

  • Designer
  • ***
  • Posts: 161
  • Karma: +5/-1
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #12 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.
« Last Edit: August 11, 2015, 09:20:06 PM by rcfiddy1 »

Offline CdRsKuLL

  • Administrator
  • Master Builder
  • *****
  • Posts: 835
  • Karma: +51/-3
  • The fat dude
    • View Profile
Re: Inspire Clone Electronics
« Reply #13 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.
If you use any of my designs and can afford to donate to help pay for this site and the filament, or just buy me a beer then please click on the link below, enter an amount and donate what you want.


Offline Eltrocha

  • Junior Designer
  • **
  • Posts: 58
  • Karma: +1/-0
  • rookie
    • View Profile
Re: Inspire Clone Electronics
« Reply #14 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?