Arduino Newbie: Help With ArduCopter 3x Serial

Hi There, I am an Arduino beginner having a tough time porting a serial command from ArduCopter 2x to the new ArduCopter 3x. I am trying to send serial data out on pins 16 and 17 of my ArduPilot Mega APM2.

Any help would be greatly appreciated! In ArduCopter 2x I was able to add a FastSerialPort2(Serial2) in ArduCopter.ino then do the following in my UserCode.ino file:

void userhook_init()
{
// setup serial port
Serial2.begin(9600);
}

void userhook_50Hz()
{
// Begin sending out data
Serial2.print("DATA: ");
Serial2.print(current_loc.lat);
Serial2.print(" ");
Serial2.print(current_loc.lng);
Serial2.print(" ");
Serial2.print(ahrs.roll_sensor);
Serial2.print(" ");
Serial2.print(ahrs.pitch_sensor);
Serial2.print(" ");
Serial2.print(ahrs.yaw_sensor);
Serial2.print("\n");

}

But I'm not sure how sending serial data works in the new version, as no FastSerialPorts are defined. Any pointers on how I may get that above code to work in the new UserCode.ino, which is:

#ifdef USERHOOK_INIT
void userhook_init()
{

// put your initialisation code here
// this will be called once at start-up

}
#endif

#ifdef USERHOOK_FASTLOOP
void userhook_FastLoop()
{
// put your 100Hz code here
}
#endif

#ifdef USERHOOK_50HZLOOP
void userhook_50Hz()
{
// put your 50Hz code here
}
#endif

#ifdef USERHOOK_MEDIUMLOOP
void userhook_MediumLoop()
{

// put your 10Hz code here
}
#endif

#ifdef USERHOOK_SLOWLOOP
void userhook_SlowLoop()
{
// put your 3.3Hz code here
}
#endif

#ifdef USERHOOK_SUPERSLOWLOOP
void userhook_SuperSlowLoop()
{
// put your 1Hz code here
}
#endif

Any help or pointers would be greatly appreciated. Thank you. -John

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Developer

    John you cannot use Serial prints in AC3 and not so much even on AC2 as all running level communication goes trough MAVLink protocol. Also if you use Serial prints, they take too much memory and CPU power. Only time when serial prints are allowed is in CLI command mode.

    You can download modified arduino from ardupilot repository.  Also development firmwares are all ready compiled and you can download them from firmware.diydrones.com but BEWARE!! they are development branches and there is NO ANY GUARANTEE that they work. Our development teams are updating development branches several times per day. So be careful with those. 

  • I also noticed that while I can compile the ArduCopter 3.x software just fine using the modified IDE (if I don't change anything), none of the default examples compile anymore (such as File->Examples->01.Basics->AnalogReadSerial) using the modified IDE. Has support for basic things such as Serial been removed? Where can I read about this?!

This reply was deleted.