Simple Remote LED Control Hack

Post Reply
mr.rc-cam
Posts: 457
Joined: Wed Jul 27, 2011 11:36 pm

Simple Remote LED Control Hack

Post by mr.rc-cam »

Adding a remote LED control feature to the MWC is not a difficult task. There are an endless number of ways to do it; here's one method that does not take long and is very low cost. Besides the LED's, all you need is one transistor, one resistor, and some minor MWC sketch edits. It uses the CAMTRIG servo port to control the LED's (a rarely used port so it is often available for custom hacks).

Edit Feb-06-2012: There are now two different software patches you can use to control the LED's. Details on the two coding methods is discussed further below. The one you choose to use is up to you.

Here's a short demo video of the remote LED control:
http://www.youtube.com/watch?v=es-VbmfQiew

The LED's used in this project are the popular 12V LED strip's that are sold by the foot. Like these:
http://www.hobbypartz.com/ledlights.html

The LED strips are convenient because they already have the current limiting resistors in them and are directly compatible with 3S LiPO batteries. You cut the length you need, solder wires to the power pads, peel off some adhesive backing, and apply them to your multicopter's arms. If you are using a different pack voltage you will need to create your own LED strip's with the proper current limit resistors to match your battery voltage.

The first thing to do is to assemble the transistor switch. You'll need a PN2222A transistor. These are *VERY* common, but if you can't find one then any general purpose NPN should work (must be rated for at least 500mA). The resistor is not critical and anything from 1K to 2.2K will work (any wattage is fine). I used a 1.5K ohm 1/8W in mine.

So solder the two parts together on a small (~1 inch square) piece of hobby perfboard:

Transistor Switch details.
Transistor Switch details.
Last edited by mr.rc-cam on Tue Feb 07, 2012 4:56 am, edited 7 times in total.

mr.rc-cam
Posts: 457
Joined: Wed Jul 27, 2011 11:36 pm

Re: Simple Remote LED Control Hack

Post by mr.rc-cam »

Once you have the two parts soldered together you will need to connect it to the LED's. As follows:
1. Ensure your LED strips have the correct voltage rating for your battery pack.
2. Connect the plus (+) end of ALL the LED's to battery positive (+).
3. Connect the negative (-) end of ALL the LED's to the transistor's collector leg (see drawing above).
4. Connect the transistor's emitter leg to battery negative (-). This is also the same as ground.

The LED wiring is nearly complete. The last thing to connect is the free end of the transistor's base resistor. Where you connect it will depend on the software patch you choose. It will go either to the CAMTRIG servo port or the POWERPIN (promini D12). Don't worry, the code edits will come soon.

First thing to do is to connect your model to the GUI application and setup the R/C channel that will control the LED. The CAMTRIG channel box is the only choice for this function. I used the "High" setting, as shown in the screenshot below:

Configure the Control Channel.
Configure the Control Channel.
Last edited by mr.rc-cam on Tue Feb 07, 2012 5:06 am, edited 6 times in total.

mr.rc-cam
Posts: 457
Joined: Wed Jul 27, 2011 11:36 pm

Re: Simple Remote LED Control Hack

Post by mr.rc-cam »

SOFTWARE METHOD #1: CAMTRIG PORT

Note: This is the original method that uses the CAMTRIG servo port.

Begin by connecting the free end of the transistor's base resistor to the MWC's "CAMTRIG" servo connector. This pin is the one defined by DIGITAL_CAM_PINMODE. For the Promini it is Arduino Pin A2. For the Mega it is Pin-33 or Pin-46. My shield has a 3-pin header for this port so I used a Futaba servo plug connector for the task.

At this point the wiring is done. BEFORE you add the new LED control code to the sketch you should test out your LED wiring. As follows:

1. Open the config.h file and enable the CAMTRIG define and upload the modified sketch to the MWC. Your edit should look like this:

Code: Select all

#define CAMTRIG

2. Apply power to the model. The LED's will be dim so you will need to do this indoors in low light. If they are on full brightness or are totally off then something is wrong.

3. In the previous post you were instructed to configure the Tx's remote LED channel. Now its time to test it from the Tx by switching the channel On/Off. You should notice a small brightness change as you switch it on and off. It is subtle, so do this in a room with low light levels. If the LED brightness remains the same then your control channel is not setup correctly.

If things are working then it's time to add the LED control code. The required edits are based on MWC V1.9. Other versions may require additional edits so if you are not a programmer then stick with V1.9 for now. Or check out the alternate patch method discussed further below.

Open config.h, find these defines and make the indicated edits:

Code: Select all

#define CAMTRIG              // Enabled, required for LED control.
#define CAM_TIME_HIGH 2000   // LED On Time, milliseconds
#define CAM_TIME_LOW 50      // LED Wink Off Time, milliseconds

Add this new define below the CAMTRIG define that was previously edited:

Code: Select all

#define CAM_TIME_ALERT 250   // New define, needed for LED (voltage alert flash, milliseconds)


Open Output.pde. Make these edits:

1. Find the ISR(TIMER0_COMPA_vect) function. Towards the bottom of it is this:

Code: Select all

  } else if (state == 8) {
    #if defined(CAMTRIG)
     DIGITAL_CAM_LOW;
    #endif

Replace it with:

Code: Select all

  } else if (state == 8) {
    #if defined(CAMTRIG)
      if(servo[3] <= CAM_SERVO_LOW) {  // Patch for remote LED control.
        DIGITAL_CAM_LOW;
      }         
    #endif


2. Find the void mixTable() function. Near the top are some data declarations. Change as shown:

Code: Select all

  static uint8_t camCycle = 1;  // Patch for LED's
  static uint8_t camState = 1;  // Patch for LED's

3. Further down the mixTable() function is the CAMTRIG code. Find the beginning of it, which is marked as

Code: Select all

  #if defined(CAMTRIG)

Then find the end of the CAMTRIG code about 20 text lines down, and is indicated as:

Code: Select all

  #endif


Replace EVERYTHING in between with:

Code: Select all

  #if defined(CAMTRIG)                     // Modified, now used for remote LED control.
    if (!(rcOptions & activate[BOXCAMTRIG])) {
          camCycle = 0;
          camState = 0;
          servo[3] = CAM_SERVO_LOW;
    }
    else if (camCycle==1) {
      if (camState == 0) {
        servo[3] = CAM_SERVO_HIGH;
        camState = 1;
        camTime = millis();
      } else if (camState == 1) {
       if ((vbat>NO_VBAT && vbat<VBATLEVEL1_3S && ((millis() - camTime) > CAM_TIME_ALERT)) ||
        ((millis() - camTime) > CAM_TIME_HIGH )) {
         servo[3] = CAM_SERVO_LOW;
         camState = 2;
         camTime = millis();
       }
      } else { //camState ==2
       if ((vbat>NO_VBAT && vbat<VBATLEVEL1_3S && ((millis() - camTime) > CAM_TIME_ALERT)) ||
        ((millis() - camTime) > CAM_TIME_LOW )) {
         camState = 0;
         camCycle = 0;
       }
      }
    }
    if (rcOptions & activate[BOXCAMTRIG]) camCycle=1;
  #endif


Upload to the MWC and try it out. That's it!

You can change the LED characteristics by altering the defines as follows:
CAM_TIME_HIGH: LED On time before wink, in milliseconds. Default is 2000mS (2 secs)
CAM_TIME_LOW: LED wink-Off time, in milliseconds. Default is 50mS
CAM_TIME_ALERT: Flash rate for low battery. Default is 250mS (2Hz blink).
Note: low battery flash only occurs if LED's are turned on.
Last edited by mr.rc-cam on Tue Feb 07, 2012 5:44 am, edited 1 time in total.

mr.rc-cam
Posts: 457
Joined: Wed Jul 27, 2011 11:36 pm

Re: Simple Remote LED Control Hack

Post by mr.rc-cam »

ALTERNATE PATCH, SOFTWARE METHOD #2: POWERPIN control

This is a new patch that is less dependent on existing code. This makes the edits much simpler on releases using V1.9 and higher. It cannot be used on earlier versions because it requires the POWERPIN that is used on all versions before V1.9. Regardless of the version, if your installation is using the POWERPIN to power the sensors then you can NOT use it to operate the LED.

Note: Unlike the original LED control patch, this version does not provide the dim light feature when the remote LED's are turned off. That is to say, when they are remotely turned off they WILL BE OFF!

Begin by connecting the free end of the transistor's base resistor to the MWC's "POWERPIN." This pin is the one defined by POWERPIN_PINMODE. For the Promini it is Arduino Pin D12. For the Mega it is Pin-37. If you are using this pin to provide power to your sensors then you CANNOT use it to control the LEDs (use the original LED patch code instead).

Now it's time to edit the code and add the LED control feature.

1. Open config.h and add these new lines at any free area near the CAMTRIG defines.

Code: Select all

#define LED_D12                     // Comment-out this define to disable ALL of the remote LED code.
#define LED_FLASH 10                // LED flash rate for low battery. Increase for slower flash rate. Max 100.
#define LED_WINK  80                // LED flash period before wink. Increase value for longer flash period. Max 200, 0=Off.


2. Open the main pde file (multiwii_1_9.pde). Find

Code: Select all

mixTable();

And change to:

Code: Select all

  #if defined(LED_D12)
      led_cntrl();
  #endif
  mixTable();


3. Open output.pde and go to the bottom of the file. After all the existing text add this new function:

Code: Select all

// *****************************
// * REMOTE LED ON/OFF CONTROL *
// *     T.Black (rc-cam)      *
// *       02-06-2012          *
// *****************************
//
#if defined (LED_D12)               // Be sure to define LED_D12 in define.h!
 void led_cntrl(void) {
    static uint8_t port_init = 0;   // Init Flag (boolean).
    static uint8_t led_cam   = 0;   // Blink Cam
    static uint8_t led_blink = 0;   // Blink Rate

    if(!port_init) {                // D12 Port Pin needs initialization.
        port_init = 1;              // Ensure Non-reentrant.
        POWERPIN_PINMODE;
        POWERPIN_OFF;
    }

   if (!(rcOptions & activate[BOXCAMTRIG])) { // LED Control: OFF.
        led_cam   = 0;              // Reset delay cam.
        led_blink = 0;              // Reset Blink delay.
        POWERPIN_OFF;
    }
    else if (rcOptions & activate[BOXCAMTRIG]) { // LED Control: ON.
       if(led_cam++ > 8) {          // Roughly 25mS, but will vary depending on cycle times.
          led_cam = 0;
          led_blink++;
       }
       if (vbat>NO_VBAT && vbat<=VBATLEVEL1_3S) { // Low Battery. Alert!
          if(led_blink < LED_FLASH) {
              POWERPIN_ON;
          }
          else if(led_blink < LED_FLASH*2) {
              POWERPIN_OFF;
          }
          else {
              led_blink = 0;
          }
       }
       else {                       // Normal remote on operation.
          if(LED_WINK == 0) {
              POWERPIN_ON;
          }
          else if(led_blink < LED_WINK) {
              POWERPIN_ON;
          }
          else if(led_blink < LED_WINK+3) { // Time for periodic wink.
              POWERPIN_OFF;
          }
          else {
              led_blink = 0;        // Reset wink time.
          }
       }
    }
    else {
        POWERPIN_OFF;               // User has not configured R/C channel, LED's remain off.
    }

    return;
 }
#endif


Now go and test it!

You can customize the LED characteristics from the config.h as follows:
LED_FLASH : Default 10 (about 2Hz). LED flash rate for low battery alert. Increase for slower flash rate. Max 100.
LED_WINK : Default 80 (about 2 secs). LED flash period before wink. Increase value for longer flash period. 0=Off, Max 200.
Note: low battery flash only occurs if LED's are turned on.

- Thomas
Last edited by mr.rc-cam on Tue Feb 07, 2012 5:23 pm, edited 1 time in total.

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Simple Remote LED Control Hack

Post by Noctaro »

nice mod! as soon as my quad is reassembled i will try it!

edit:
May we use a shift register to do some fancy things with some leds connected to it?


f.e. load 8bit and burst states to the leds to get some visuals.

greetz
noc

(sorry my eletric and programming knowledge is kind of basic)

mr.rc-cam
Posts: 457
Joined: Wed Jul 27, 2011 11:36 pm

Re: Simple Remote LED Control Hack

Post by mr.rc-cam »

May we use a shift register to do some fancy things with some leds connected to it?

Things like that are certainly possible. For example, I have another MWC Quad with strings of animated LED's that uses a custom made I2C LED controller. But the goal of this hack was to keep things simple.

BTW, this is a good project for beginners. Besides showing how to use a transistor as a switch, it also introduces them to some code editing. It's my way to get them interested in trying to do some more mods by themselves.
Last edited by mr.rc-cam on Tue Feb 07, 2012 6:00 pm, edited 1 time in total.

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Simple Remote LED Control Hack

Post by Noctaro »

got me :D

User avatar
Hamburger
Posts: 2557
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Simple Remote LED Control Hack

Post by Hamburger »

might be worthy to note:
the same combo of transistor+resistor+LEDstrips can be attached to the buzzer pin (pin 8?) and the LED pin (pin 13) for real visual feedback.

flyman777
Posts: 55
Joined: Mon Sep 19, 2011 1:44 pm

Re: Simple Remote LED Control Hack

Post by flyman777 »

Hi,

You'r right.
I did that with POWERPIN D12 changed in BUZZERPIN in def.h because I'm using D8 as input for AUX2 on my proMini board + AllinOne.
Just swap D8 and D12 and comment all occurences of POWERPIN in the sketch:
See : http://www.multiwii.com/forum/viewtopic.php?f=8&t=1117

Regards
flyman777

User avatar
wareck
Posts: 36
Joined: Tue May 22, 2012 10:14 pm
Location: Charleville-Mezieres
Contact:

Re: Simple Remote LED Control Hack

Post by wareck »

Hi is this patch work for multiwii 2.1 or there is another way?
cheers

Olivier

flyman777
Posts: 55
Joined: Mon Sep 19, 2011 1:44 pm

Re: Simple Remote LED Control Hack

Post by flyman777 »

Hi,

I make my boards myself and it was more convenient to take D8 as input for a Promini.
The Buzzerpin has then been moved on D12 , useless if you have other gyro+acc then WMP+NHK.
So I modified the def.h accordingly.
It works with MutiWii 2.0, 2.1
RCAUXPIN8 + BUZZER must be defined in config.h
Attached a zip with my config.h and def.h

regards
Claude
Attachments
Config TriWii_2.zip
(1.74 KiB) Downloaded 392 times

AshleySoares
Posts: 1
Joined: Sun Aug 04, 2013 1:23 pm

Re: Simple Remote LED Control Hack

Post by AshleySoares »

Hamburger wrote:might be worthy to note:
the same combo of transistor+resistor+LEDstrips can be attached to the buzzer pin (pin 8?) and the LED pin (pin 13) for real visual feedback.

I think you are tottaly right.. let's know how say the experts........................

User avatar
Hamburger
Posts: 2557
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Simple Remote LED Control Hack

Post by Hamburger »

?? It just works (no surprise, simple tech). I use it all the time. What do you need to know?

debay777
Posts: 12
Joined: Tue Aug 19, 2014 11:32 pm

Post by debay777 »

I know this is a dead thread, but aim building a tricopter with the whitespy EZ pro3 board. I want to add LED's to the arms for orientation. I would rather them not be stuck on all the time but rather to switch on and off with the arm/disarm. Is there a way to do that without using up an aux channel?

handsomejackuk
Posts: 97
Joined: Mon Sep 08, 2014 12:25 am

Re: Simple Remote LED Control Hack

Post by handsomejackuk »

bump for reference

Post Reply