Attempt to Integrate Relay Switch

Post Reply
purplecow265
Posts: 3
Joined: Thu Apr 09, 2015 4:49 pm

Attempt to Integrate Relay Switch

Post by purplecow265 »

Hi all,

GOAL: I am trying to integrate a relay switch on my quadcopter. I have the RC Crius Pro V1 board.

WHAT I'VE DONE: I want to read the PPM signal from channel 5 on my receiver by dedicating the A33 pin on the board to a digital input. I then added code to the main loop that will turn pin D8 high if the signal read into A33 is low (1080 micro seconds) and low if A33 is high (1800 micro seconds).

PROBLEM: Basically my problem is after I added the "pulseln" function into the code, it interrupts the serial tx when I use the MultiWii Conf ie. I can't get any sensor readings.

Do you think it would still be safe to fly? Or is there some danger in adding the "pulseln" function to the main loop.

Thanks!

Here's all the code I added to MultiWii.cpp, everything else is the same.

Code: Select all

  
// Declare global variable
int servoValue;

// This code inserted at the end of void setup()
pinMode(33,INPUT); //Receiver
pinMode(8,OUTPUT); //Relay

// This code inserted at the end of void loop()
servoValue = pulseIn(33, HIGH);
if ((servoValue > 500) && (servoValue < 1200))
  {
     digitalWrite(8,HIGH);
  }
  else
  {
     digitalWrite(8,LOW);
  }


Cereal_Killer
Posts: 221
Joined: Fri Mar 06, 2015 5:44 am

Re: Attempt to Integrate Relay Switch

Post by Cereal_Killer »

Saw this yesterday but it didn't hit me, I had to read back threw your post...

How are you reading normal rx data? Each channel standard or serial sum (one wire)? If you're reading PPM sum data out of ch1 I don't think you'll be able to get a second output (serial or otherwise) out of ch5, I think the issue isn't in the code but is the result of wanting 2 data streams out of 1 PPM SUM receiver.

I'd suggest either using a standard receiver with individual channel connections or, if you're stuck with serial for whatever reason you'll have to read ch5 out of it.

One final tidbit- I've NEVER been able to get any 328P based FC to work 100% with any PPM receiver. I've gotten them to fly, but not behave correctly when connected to the GUI, the little 328P just doesn't have the capabilities. On my super budget builds (in which I use an Arduino nano) I just use standard receivers...


Could you give us a parts list? At lease your RX and maybe a pic or wiring diagram?

purplecow265
Posts: 3
Joined: Thu Apr 09, 2015 4:49 pm

Re: Attempt to Integrate Relay Switch

Post by purplecow265 »

Receiver is Turnigy 2.4GHz 8 ch receiver. I'm reading from one channel (channel 5) into pin 33 on my board (MultiWii MegaPirate AIO FC). I believe it's a standard receiver set to PPM.

I did get it to work, but the cycle time goes to almost 20000 micro seconds, which seems a bit high.

Here's my setup:
Image

RED WIRE: Gives power from the board to the receiver (board is connected to usb)
BLACK WIRE: Ground to the board
GREEN/BLUE WIRE: GREEN wire goes from signal pin on D8 to the LED back down to ground (BLUE WIRE) on the board.

Flicking the channel 5 switch on my transmitter turns the LED on/off.

purplecow265
Posts: 3
Joined: Thu Apr 09, 2015 4:49 pm

Re: Attempt to Integrate Relay Switch

Post by purplecow265 »

Hey, I wanted to post an update.

Here's the new code

Code: Select all

// Relay Code pasted at end of void loop()
    int16_t servoValue = 0;
    servoValue = readRawRC(AUX1);    // Using the auxiliary pin now
 
    if ((servoValue > 500) && (servoValue < 1400))
    {
       digitalWrite(8,HIGH);
    }
    else
    {
       digitalWrite(8,LOW);
    }


Cycle times are back down to 3000 micro seconds and lower so I think it's safe to say that my method is OK. If anybody see's anything glaringly wrong with what I did please let me know!

That being said, I'm not an avid C programmer, but I feel a little better about tweaking code. That was fun! Go MultiWii!!!

Post Reply