I have been playing with my Arducopter for a while now. Really cool stuff! It's time for a little contribution myself.
But first a really a big thank you to everybody working on this project and especially Jason for all the cool (and very stable) code he has been contributing!
I had hooked up the Battery Monitoring as described in the WIKI. Works like a charm, however beyond a message in the GCS it was hard to notice when the Voltage (or current, if that is hooked up) reached a critical level.
RTL sounds great, but in most cases it'll be good to get an audible signal when the batteries run low. In fact, I killed one LiPO just having my copter sitting on the desk and forgetting to disconnect the battery. The ACM draws quite a bit of current and low-discharged the LiPO... 20 more bucks down the drain.
So I had a look around in my electronic shop and found a little Piezo buzzer. It runs on 3-6V and only draws about 30mA which is not too much to be driven straight from one of the ACM port pins. It's a YMD1205. It only costs 30 cents - much cheaper than a new LiPO :)
After looking at the schematics of the IMU a usable port was quickly found. The IMU has two "Expansion Ports". As I did not plan to use either for other stuff, they are perfect as the buzzer fits neatly between one of the "gnd" pins and the hole marked "AN6". It looks like it actually belongs there, doesn't it :)
Code was written very quickly as well in case you would like to integrate that into your project.
I wanted it to be configurable via the APM_Config.h file. Also I integrated a quickly audible beep on start-up to know if the Piezo Buzzer is working.
I tested the whole thing and it works like a charm. The nice side effect is, that the buzzer can be used from anywhere in the code for other audible signals via the piezo_on() and piezo_off() functions.
Let's see maybe I can get it to play a song before it takes off :)
APM_Config.h:
// Enables the Piezo buzzer code
#define PIEZO ENABLED
// Required if PIEZO is "ENABLED"
#define PIEZO_PIN AN6
// Optional to enable low Voltage alarm
#define PIEZO_LOW_VOLTAGE ENABLED
system.pde:void init_ardupilot():
#if PIEZO == 1
pinMode(PIEZO_PIN,OUTPUT);
piezo_beep();
#endif
sensors.pde:
#if BATTERY_EVENT == 1
if ( (battery_voltage < LOW_VOLTAGE) || (g.battery_monitoring == 4 && current_total > g.pack_capacity) ) {
low_battery_event();
#if PIEZO_LOW_VOLTAGE == 1
// Only Activate if a battery is connected to avoid alarm on USB only
if (battery_voltage1 > 1){
piezo_on();
}
else {
piezo_off();
}
#endif
}
else {
#if PIEZO_LOW_VOLTAGE == 1
piezo_off();
#endif
}
#endif
events.pde:
#if PIEZO == 1
void piezo_on()
{
digitalWrite(PIEZO_PIN,HIGH);
}
void piezo_off()
{
digitalWrite(PIEZO_PIN,LOW);
}
void piezo_beep()
{
// Note: This command should not be used in time sensitive loops
piezo_on();
delay(100);
piezo_off();
}
#endif
Only one small annoyance. It does beep if the ACM is powered by USB cable only. I am wondering if there is a way to detect the presence of the USB cable plugged in, in code, which would allow me to disable the buzzer in that condition. Any hints would be appreciated.
Have fun !
Ollie.