Go Down

Topic: BlueCopter - Arduino Quadcopter (Read 157403 times) previous topic - next topic


Thanks all of you, i met a big problem with my receiver, it blew up ( wrong connection ) :'( , i try to fix or buy another one.


I've ported the receiver code to the arduino UNO which handles pin change interrupts and ISR's a little bit differently if anybody is interested.  This works with the six analog pins, but it can work with other pins if you modify the ISR and the pin assignments.  There are also some comments explaining how it all works.

More importantly, it has a method to detect if the remote is out of range.  This works with my 6 channel hobbyking HK-T6A V2 remote very nicely.  If you put "checkForDeath" in your loop() method, the code inside will run when you go out of range or run out of controller batteries.

Code: [Select]

//format for all the pin arrays
//stores if each of the pins was high or low last time
volatile byte rxPrevState[6] = {0, 0, 0, 0, 0, 0};
//stores the system time when the pin last went high
volatile long rxPrevTime[6] = {0, 0, 0, 0, 0, 0};

//method to configure a pin for PCICR. 
void setupPin(byte pin){
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group

ISR (PCINT1_vect){
  //an analog pin changed state
  //iterate through all the possible pins it could have been
  for(int i = 0; i < 6; i++){
    //store the state of the pin we're checking
    byte rxCurrentState = digitalRead(rxPins[i]);
    //if it currently is high, but was low last time...
    if(rxCurrentState == 1 && rxPrevState[i] == 0){
      //the pin just went high, so we store the time at which it went high
      rxPrevTime[i] = micros();
    //if it currently is low, but was high last time
    if(rxCurrentState == 0 && rxPrevState[i] == 1){
      //the pin just went low, so we subtract
      //the current time from the time it went high
      //to find the pulse length
      //store the pulse length in the rx values array
      rxVal[i] = micros() - rxPrevTime[i];
    //store the state (high/low) for next itme
    rxPrevState[i] = rxCurrentState;

void initReceiver(){
  //setup interrupts on the analog pins
  for(int i = 0; i < 6; i++){
    pinMode(rxPins[i], INPUT);
    digitalWrite(rxPins[i], HIGH);

//call this method from loop().
//you can handle losing connection however you want.
void checkForDeath(){
  if((micros() - rxPrevTime[5]) > 100000){
    //code in here runs if we lose connection



You know what, I've done that same exact thing, but with the PinChangeInterrupt library. Here's my receiver code:
Code: [Select]

PROGMEM const byte rxPins[6]={
volatile byte rxState[4]={
volatile int rxPrev[6]={

void rxInit(){
  for(byte i=0;i<6;i++){
void rxGoesHigh1(){
void rxGoesLow1(){
void rxGoesHigh2(){
void rxGoesLow2(){
void rxGoesHigh3(){
void rxGoesLow3(){
/*void rxGoesHigh4(){
void rxGoesLow4(){
void rxGoesHigh5(){
void rxGoesLow5(){

void rxGoesHigh6(){
void rxGoesLow6(){

 8)  8)  :P
I love Arduino
When is the ZERO coming out?
Why RPi?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131