3 channels 6 outputs MrRCSound

Hi everyone I´m new to Arduino but not to Spektrum RCtransmitters and receivers and MrRCSound V4.1 soundboards for RCaireoplanes that has 4 inputs and 4 sounds out.

1 Throttle

2 MachineGuns with synchronous LEDs

3 Whistle

4 Guns

The transmitter has levers (turn knobs)on left and right side of the Tx, Llv and Rlv

Nick Poole wrote this code that should work just fine but would need more channels than I have!

/*
 RC PulseIn Joystick
 By: Nick Poole
 SparkFun Electronics
 Date: 5
 License: CC-BY SA 3.0 - Creative commons share-alike 3.0
 use this code however you'd like, just keep this license and
 attribute. Let me know if you make hugely, awesome, great changes.
 */

int THR; // Here's where we'll keep our channel values from RX
int AUX2;
int AUX4;

int Whistle;// P-51 Whistle Servo 3 V4.1
int MG;// Machineguns connected to LEDout Servo 2 V4.1
int Guns;// Guns no LED Servo 4 V4.1
int Canopy;// Canopyservo



int Whistle = 3;  //Throttle near max to activate P-51 whistle Servo 3
int MG = 11;  //Machine guns on Servo 2 activates synchronous LED (outer pins)
int Guns = 12;  //Gunsound without LED Servo 4
int Canopy = 13;  //Turnknob opening (if avaiable) of canopy

void setup() {

  pinMode(5, INPUT); // Set our input pins as such
  pinMode(6, INPUT);
  pinMode(7, INPUT);

  Serial.begin(9600); // Pour a bowl of Serial

  pinMode(Whistle, OUTPUT);  //Set control pins to be outputs
  pinMode(MG, OUTPUT);
  pinMode(Guns, OUTPUT);
  pinMode(Canopy, OUTPUT);


}

void loop() {

  THR = pulseIn(5, HIGH, 25000); // Read the pulse width of
  AUX2 = pulseIn(6, HIGH, 25000); // each channel
  AUX4 = pulseIn(7, HIGH, 25000);

  if (THR > 1500) {
    Serial.println("Whistle: Engaged");
  }
  if (THR < 1500) {
    Serial.println("Whistle: Disengaged");
  }
  /* I found that Ch1 was my left switch and that it
  floats around 900 in the off position and jumps to
  around 1100 in the on position */

  Serial.print("LLv:"); // AUX2 was LLv
  Serial.println(map(AUX2, 1000, 2000, -500, 500)); // center at 0

  Serial.print("RLv:"); // AUX4 was RLv
  Serial.println(map(AUX4, 1000, 2000, -500, 500)); // center at 0

  Serial.println(); //make some room

  delay(100);// I put this here just to make the terminal
  // window happier
}

My goal is

1 Throttle high should activate Whistlepinout as in code, but propably closer to endpoint, aprox 1800-1900, throttle near max.

2 Aux channel 1 on Llv midpostition everything inactivated

Counterclockwise turn (<1500) sets MGoutpin HIGH with LEDs flashing

Clockwise turn (>1500)sets Gunpin HIGH, also would like to have a synchronous LED flashing on this channel, I have used this code that works, but need it to be activated for ca 2 sek as the Gunsound bursts aprox 2 sek See code at the end.

3 Aux channel 2 on Rlv midpostition everything inactivated

Counterclockwise turn (<1500) sets Whistlepinout HIGH with LEDs flashing (sometimes I want Whistle with lower throttle manually activated)

Clockwise turn (>1500) turns a canopy servo from closed to open position.

Gun LED flash

/*
  Blink
  Turns on an LED on for 30ms, then off for 50ms, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(30);              // wait for 30ms
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(50);  // wait for 50ms
}

These are my first struggling steps towards writing code myself, I understand the syntax theoretically, but to write it seems a bit harder.

Best regards and hoping for the best.

Merry X-mas

Lasse Hellsten

Is there a question in the above ? I’m not familiar w/the systems involved but from the above and looking at the code I’ll GUESS that there’s an Arduino of some sort that is also tied onto the servo/XXX control lines. That the Arduino measures the various pulsewidths and based on the PWs, sends a set of logic signals to the soundcard, which then turns on/off various sounds (in the RC plane). The code posted above is some snippet of code you found for the Arduino and you want to change it ?

Perhaps you could share the parts you know (that “we” don’t) to get “us” up to speed on the system. Links are always good too.

Hi and Thanx for the respons!

Yes this is a question and it´s about Arduino. The snippets is what I want to use modified to control a soundboard (http://test.mrrcsound.com/purchase)via a radio controlled receiver.

If I can flash the code to a ATTiny 85V it would be nice as I have little space and 3.1 volts is available directly from the board. Max current over 1 of the pins should not exceed 80 mA

RC receivers typically generate a PWM in the 1000 - 2000 micro sec interval. 1500 micro sec is centered servo pos.

The sound board has 4 normal 3 pin servo inputs (neg/pos/signal) 3 to 9 volts ca. Channel 1 is connected to throttle out från receiver to have engine sound to follow throttle from low to high rpm.

In addition one of the 3 aux sounds can be activated one at a time in this case.

Aux 1 machine guns with synchronous flashing LEDs, activated as long as signal pin is above 1150 micro sec.

Aux 2 P-51 whistle sound to be activated at high throttle, corresponds to a high value in micro sec, 1700-1800.Sound activated once when signal pin in on board is above 1150 micro sec. Needs to be set <1100 micro sec to be in state for new activation

Aux 3 deepsounding guns with ca 2 sec bursts. Sound activated once when signal pin in on board is above 1150 micro sec. Needs to be set <1100 micro sec to be in state for new activation, I want to add a blink signal to LEDs, to flash 30 micro sec on 50 microsec off for 2 sec synchronous with the bursts.

Aux 2 gets its signal from throttle channel.

Aux 1 and aux 3 (with flash bursts) to be inactive when a turn knob is in mid position = 1500 micro sec. Turning the knob clockwise should activate aux 3 with the 30/50 ms flash and counterclockwise should activate aux 1 with the built in LED flash.

Anyone how knows how to do this? I think the 2 snippets in original post could be a good start.

Best regards and Merry X-mas

In your first post, you state that you don’t have any channels. So are you trying to use code to get more channels? That’s probably not going to work. Have you tried to first code? Does it work? The second code is just a blink sketch… Not sure what you want to do with that.

It seems like you want someone else to write the code for you. I am afraid that the members here won’t do that, for free anyways… Now if you tried to write or modify the first sketch, then that’s a different story. You would need to post the code that you tried to modify and specify in detail why it’s not working or any errors you have received.

I will tell you that trying to write code for everything on the first try isn’t going to work. You need to break it up. Start with one task, like getting a sound to play from the Arduino. Then go to the next task and so on. Once you have different parts of the project working, then you can start on combining them.

So, a few questions:

  1. Is this going into a RC airplane?

  2. Where is the Arduino (on the transmitter or on the plane)?

  3. If the Arduino is on the transmitter or even the plane, how is that signal going to get to the plane/transmitter?

From what I gather he’s got 3 control channels to be used; throttle and 2 Aux channels which are tied to knobs, left and right, to control 5 soundcard functions. One sound (engine) requires no Arduino code. There are to be some shared soundcard functions on the Aux control channels, that is 2 functions controlled by single channel. Also the soundcard whistle function has 2 control inputs, the throttle and Aux2 channels. The OP gives some conflicting requirements re: PWs but maybe he was explaining N Poole code vs what he wants. Here’s my best guess as to his reqs.

Throttle PWM-> soundcard (engine sounds) proportional to PW (no Arduino involved)

Throttle PWM-> Arduino pin 5 → Arduino pin 3 to control soundcard whistle sound ;

  • logic 1 when PW > 1800, logic 0 when PW < ???

Aux1 PWM → Arduino pin 6 → Arduino pin 11 to control soundcard MG sound (?w/LEDs?) ;

  • logic 1 (MG on) when PW < 1500, logic 0 when PW > ???

Aux1 PWM → Arduino pin 6 → Arduino pin 12 to control soundcard deepsounding guns ;

  • “activated” (guns on) when PW > 1500, logic 0 when PW < ???

  • “activated” = the pin to be pulsed on/off, 2 sec period, duty cycle = ???

Aux2 PWM → Arduino pin 7 → Arduino pin 13 to control soundcard canopy ;

  • open canopy (? = what for output ?) > 1500

  • how does canopy close ?

Aux2 PWM → Arduino pin 7 → Arduino pin 3 to control soundcard whistle ; (2’ndary control)

  • logic 1 (whistle on) when < 1500, logic 0 when > ???

  • ? explain what LEDs ?

I have a few questions …

  1. You need to have some hysteresis in the on/off thresholds, otherwise noise may cause the function to chatter on, off, on, off …

  2. You should have a deadband about 1500 us PW, not a threshold @ 1500. You’ll never see EXACTLY 1500, so the shared functions will chatter. I suggest a deadband of at least 1400-1600 = no activation, < 1300 or > 1700 = on, otherwise off.

  3. I don’t understand what LEDs are to be flashed ? What Arduino pins control them ? Are they some other soundcard input ? I thought it only had 4 digital inputs.

  4. Answer the ??? in my guess for your requirements

codlink:
So, a few questions:

  1. Is this going into a RC airplane?

  2. Where is the Arduino (on the transmitter or on the plane)?

  3. If the Arduino is on the transmitter or even the plane, how is that signal going to get to the plane/transmitter?

I believe the soundcard (and speakers) and Arduino sit in the RC plane, w/the Arduino sniffing the receiver outputs to activate certain digital functions of the soundcard. This gives the plane "realistic", full size plane sounds.

The OP is like many, he can’t see how to meld differing snippets together. Also he needs each function to be non-blocking.

After reading the manual for the soundcard I’m more confused than before. There’s very little functional info on how the soundcard works at the website but from the little I can find it seems the soundcard accepts only 4 servo type (20 Hz, 1-2 msec PW) signals, not “auxiliary” digital inputs (as I thought above). If that’s true then the OP must intend for the Arduino to generate a servo signal instead of the digital outputs I described. That’s OK so far as it goes, I believe there’s a library that will generate PWM signals of that type on any pin but now I don’t know how to map the PW’s of the receiver servo signals into the PW’s the Arduino must generate.

For example the OP stated he wanted the whistle sound to be activated when the throttle PW > 1800. But the whistle is controlled by the servo #3 input on the soundcard. What value of PW is needed to turn the whistle on ? Off ?? The manual doesn’t say. Perhaps the OP tried to explain that but, English not being his primary language, something got lost in the translation.

Perhaps the OP could make a table of inputs and their corresponding outputs and define the relationship between the input PWs and output PWs.

I’d also like to know what type of Arduino is going into the plane.

Because it’s Christmas, here’s my guess at the bones of a program, implementing my suggestions for hysteresis and deadbands.

void loop() {
  // measure the pulsewidths of each input channel
  ThrottlePW = pulseIn(ThrottleInPin, HIGH, 25000);
  Aux1PW = pulseIn(Aux1InPin, HIGH, 25000);
  Aux2PW = pulseIn(Aux2InPin, HIGH, 25000);
  // Now deterime the desired state (on/off) of each function
  // The whistle depends on both throttle PW and Aux2 PW
  if (throttlePW > ThrottleThreshOn) {
    // this is high throttle path
    // turn on whistle sound
    ?? some servo command ??
  } else if (Aux2PW < WhistleThreshOn) {
    // this secondary manual-on path
    // turn on whistle sound
    ?? some servo command ??
  } else if (Aux2PW > WhistleThreshOff) {
    if (throttlePW < ThrottleThreshOff) {
    // turn off whistle only when both control inputs say off
    ?? some servo command ??
    }
  }
  // Now do canopy logic
  if (Aux2PW > CanopyOpen) {
    // open canopy
    ?? some servo command ??
  } else if (Aux2PW < CanopyClose) {
    // close canopy
    ?? some servo command ??
  }
  // Now do MG logic
  if (Aux1PW < MGThreshOn) {
    // turn on MG sound
    ?? some servo command ??
  } else if (Aux1PW > MGThreshOff) {
    // turn off MG sound
    ?? some servo command ??
  }
  // Now do guns logic
  if (Aux1PW > GunsThreshOn) {
    // enable guns sound timing
    ?? set a boolean ??
  } else if (Aux1PW < GunsThreshOff) {
    // disable guns sound timing
    ?? reset a boolean ??
  }
  // guns require separate logic to do burst timing ?
    ?? some timing logic ??
    ?? some servo command ??
}

My humble thanx to U!

I will, according to your suggestions, try to write functional sketches. As I will be on vacation the next week(s), I wont be able to do this until the beginning of 2015. From what I can see, your draft is a leap forward. Will be in touch!

Best regards

Lasse