Following up on the success of my relay low battery warning leds I have expanded that code to include a complete lightshow and to be compatible with the newest ACM codes (2.1.1) and the APM1 hardware. APM2 hardware MAY work, but I don't have APM2 at this time, so no guarantees.
Credits to Bill Sanford and Max Levine whose work has been an inspiration and a basis for these leds.
1) Software side :
By using the agmatthews userhooks it is now much simpler to upgrade to a new firmware without having to change the code each time. You just have to copy 2 files and change setting in the APM_config.h. The needed files AND my config.h file (for version 2.1.1r5) are in the following file : U4eake_showleds.zip
Updated files for ArduCopter 2.5 (compile with arduino1.0 relax patch) : u4-showleds.zip These still work for ArduCopter 2.5.3.
Update files for ArduCopter 2.6 : Showleds_ACM2.6.zip Because motors were put in a library, every motor_armed in the showleds code had to be modified to motors.armed(). Also you have to put
#define COPTER_LEDS 0
into your APM_Config.h file to disable the new copterleds, which are enabled by default.
You need to copy the usercode.pde and the usercode.h files into your arducopter directory (overwriting the files already there) and add the settings below to your APM_config.h. DO NOT just copy my APM_config.h, it is only included as an example to clarify the settings.
#define MOTOR_LEDS 0 // 0 = off, 1 = on
#define SHOW_LEDS 1 // set to 1 to enable AN7-AN15 controlled led lightshow
#define RELAY_LEDS 0 // set to 1 to use the old relay led low battery warning#define COPTER_LEDS 0
#define BATTERY_EVENT ENABLED
#define LOW_VOLTAGE 9.9
#define MID_VOLTAGE 10.6
#define VOLT_DIV_RATIO 3.33#define INPUT_VOLTAGE 5.26
Also uncomment the 50hz agmatthews userhook and the mediumloop userhook (remove the // in front of it) so it looks like this :
#define USERHOOK_50HZLOOP userhook_50Hz();
#define USERHOOK_MEDIUMLOOP userhook_MediumLoop();
The voltages can be adjusted to match your desires. If you have a 4S battery for example, you should put higher values, like 13.2V for the LOW_VOLTAGE. INPUT_VOLTAGE is the voltage that goes into the APM (usually the voltage from you ubec). VOLT_DIV_RATIO is an calibration value that you can adjust so that your reported battery voltage corresponds to the real battery voltage.
After compiling the code with arduino and uploading it to the APM board, you also need to set battery monitoring to option 3 : battery volts
That's it for the software modifications if you have a hexa or are happy with the patterns as they are ! On a quad or octo you may want to adjust the patterns a bit, but I'll explain that further down this blog (see Adjusting Patterns).
The code and blink patterns are optimised for use on my hexa (6 leds strips on the arms + 2 spare ones).
The leds will go on when motors are armed and out when disarmed. During flight, different flashing patterns can be selected with Ch7. The other use of Ch7 is not affected, so you can still use it for simple or recording waypoints. The leds will flash with the last pattern in this file when ch7 is high (recording waypoint or simple)
When battery gets below the first threshold (MID_VOLTAGE = 10.6V), the ledshow is overridden and the leds will flash with following pattern : led 1,3,5 on/off and led 2,4,6 off/on. So if the first ones are off, the others are on and vice versa.
When second threshold (LOW_VOLTAGE)is reached (9.9V) the leds will flash quicker.
2) Hardware :
The code uses the AN8 tot AN15 analog ports (portK) on the oilpan of APM1. In the picture you can see them labelled AN0-AN15. AN8 to AN15 are the ones on the right (4x2 pins)
You can either connect 1 led directly to each port (the ports can supply 40mA current) or you can use a ULN2803 darlington transistor chip to drive the leds according to the following shedule (thx to Max Levine for this schematic) :
This shedule is for a quad and uses a ULN2003. The ULN2803 has 8 ports instead of 7 and if I remember correctly it can supply a little more currrent (500mA per port). A typical hobbyking 12V ledstrip of 1m (60 leds) consumes about 300mA, so normally you should be able to hang 1m of ledstrip on each of the 8 ports. That should be plenty !!
You can get the ULN2803 in your local electronics shop or online here : Canadadrones - ULN2803
The darlington chip lets each input control the output directly across on the other side of the chip. So nr1 in the picture above, controls output 16, Nr 2 controls output 15 and so on. If you look at the pinout picture of the oilpan, you'll see that nr 1 is connected to AN8 and nr2 is connected to AN10, so AN8 in the pictures above controls the red leds, and AN10 controls the green leds. Get it ? ;-)
After the brainsurgery it will look something like this :
Now you just have to put a heatshrink over the ULN2803 chip and tuck all the wires away nicely.
CAREFULL : in the picture above I had soldered the wires to the wrong ports (side of the compass). That's what you get when working on your copter till 4 in the morning... It took me a day to figure out why my leds didn't work as expected. So you have to solder your wires on the OTHER SIDE (side of the usb connector). I didn't have a picture of when I soldered it right.
Finally you'll also have to set up your board for battery monitoring (option 3 : total voltage) by soldering the voltage dividers and connecting battery voltage to AN0, which is explained in the wiki here : Voltage sensors on APM1
3) Adjusting the blinking patterns
First you'll have to understand a little about bitmath in arduino : http://www.arduino.cc/playground/Code/BitMath
To save processor cycles I've opted to drive the portK of the atmega1280 using direct portmanipulation.
If the above all sounds too complicated : here's the simple explanation.
In the usercode you'll often find something like PORTK = B00101010; This instruction actually turns leds on and off. 0 means off and 1 means on. Each number turns 1 port off or on, and the first number after B turns port AN15 on. So the ports are B-AN15-AN14-AN13-AN12-AN11-AN10-AN9-AN8 of shorter written : BAN15...AN8
If you would now like to turn the red leds on and the others off in the picture above, this would be PORTK = B00000001; (turns AN8 on, and AN8 is connect to nr1 on the darlington, which turns on red leds)
If you wanna turn the 2 blue ledstrips on and the others off it would be PORTK = B01010000; (ports AN12 and AN14 on, which are connect through the darlington to blue leds)
All 4 strips on would be PortK = B01010101;
Ofcourse for hexa's and octo's this depends on which AN port you have soldered to which nr on the ULN2803.
Now we can turn leds on and off, but they still don't blink or "rotate". For the blinking a counter is used and depending on the counter, leds are switched on and off. The counter runs in the 10hz or 50hz loop, so you can time the blinking. If counter =5 when in the 10hz loop will correspond to half a second.
For "rotating" arms I use the bitmath again, more precisely the bitshift operators << and >>. These simple shift all bit a few places. so 00000001 << 1 becomes 00000010. The 1 shifts 1 place. By now you understood that this is an easy way to make the leds "rotate". Just shift the B00000001 1 place each loop cycle and your 'on' leds will shift an arm each cycle, making them look asif they rotate.
4) TO DO
On the 8 port ULN2803 there are still 2 ports left unused on my hexa. I'm planning to use those to replicate the gps status light and maybe a failsafe warning light. I've also thought about using them to drive leds in the form of a smiley :-) Other ideas are always welcome !
I'm using the relay now to ignite fireworks on the hexa. But that's a story for another blog ;-)
That's about all I can think of telling you, and by now my fingers are tired and my brain is mushy.
I hope you enjoy these leds and don't scare too many people with your new UFO ;-) Feel free to ask questions in the comments below if something is not clear.
Ow, and ofcourse I assume that you know what you're doing if you solder on your board. I take NO responsability if something goes wrong and you break it ! Do this at your own risk !
Regards,
U4

Comments
Hi U4eake,
I followed correctly, the led was blinking, but it did not do as code.
For example: code:digitalWrite(COPTER_LED_4, COPTER_LED_ON); and led 4 and led 5 was on.
I tested with led only, this worked correctly. I tested the ULN2803, it also worked correctly but the combination of them did not work exactly.
This is really weird.
I am using the latest code for it not yours. Maybe this causes the problem here.
Thanks,
Duy
I must add that it's really motivating for me to see that there is still interest in this showleds code. Even after so many arducopter updates !
Thanks for your interest in my work !
Duy, for the ULN2803 you must let it connect the negative wires as shown in the schematic on first page. It sinks current, so it can't connect positive wires. Positive of your leds should go directly to + of the battery. Negative should be routed through the ULN2803. Without more info, I can't see what else could be wrong, apart from a faulty ULN2803.
Jonathan, wow, that's a very generous offer. Though an apm2 would be nice to have, I think it is really too much to ask from you. If you give me some more details about the roadblock you run into, I'll do my best to help you anyway I can.
For APM1 I had to study the eagle files, follow traces on the board, look at the atmega1280 spec sheet and do a little gambling, to find out which processor port (PortK in case of APM1) was connected to the AN8-AN15 pins. Took me a few days. I suspect for APM2 the same will have to be done.
There is also the option of using CopterLEDS though. It was made by Robert Lefebre and is based on my showleds, but kinda without the show, just indicating motorarming, gpslock and such. It should work fine on APM2. Put #define COPTER_LEDS 1 in your apm_config file.
I have my apm_config file like this :
#define MOTOR_LEDS 0 // 0 = off, 1 = on
#define COPTER_LEDS 0
#define SHOW_LEDS 1
#define RELAY_LEDS 0
which enable me to choose any leds I want (and have the hardware setup for) by changing the 0 to 1. Not that you should only have 1 of them active (1) at the same time, else you may get conflicts or strange led behaviour.
I followed the instruction but the led does not blink as code, the ULN2803 seems does not work correctly. Example: I turned led3 on in code but both led_arm3 and led_arm4 on. I took it out and connect leds directly to pin AN8-AN15 and it showed well. Does it need to connect pin10 to VCC? it there any tip for this?
Thanks,
Duy
I don't have an APM2, so no idea, sorry
I have a quad and will use green, red, white and blue. I'm using APM2. Do I just connect to AN4 AN5 AN6 AN7 and to what pin? The signal pin?
I'm using the ULN2803.
http://code.google.com/p/arducopter/wiki/APM2RC
I want to add also an external indicator for GPS. Can I use the next pin for that? I'm using APM2 so would I hook to A4, A5, A6, A7 and can I use A8 for GPS indicator?
I just got my ULN2803 and want to do this mod on an APM2 quad with 2.6. Can the directions be followed for the APM2 also or is there some difference? I'm also using 4S to power the LEDs. Is that ok? My strips will take 12-24 volts.
Yes there is, the new arducopter 2.6 will hopefully contain copterleds, which are somewhat based on my showleds and should work with APM2
Is there any way to use leds on APM2.0? I just want an external led for gps and one for motors armed? I tried led mode from mission planner but could only get A6 sending a signal for arming the motors?
-
1
-
2
-
3
-
4
-
5
of 6 Next