Communicating through UART serial port

Hello, I trying to communicate with PIXHAWK <----> COMPUTER Serial port.

My code is very simple, first I uncommented in APM_Config.h lines:

#define USERHOOK_INIT userhook_init();                      // for code to be run once at startup
#define USERHOOK_SUPERSLOWLOOP userhook_SuperSlowLoop();  // for code to be run at 1hz

Then I wrote very simple example in UserCode.cpp:

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-

#include "Copter.h"
static void setup_uart(AP_HAL::UARTDriver *uart, const char *name);

#ifdef USERHOOK_INIT
void Copter::userhook_init()
{
    setup_uart(hal.uartE, "uartE");
    setup_uart(hal.uartD, "uartD");

}
#endif

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

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

#ifdef USERHOOK_MEDIUMLOOP
void Copter::userhook_MediumLoop()
{
    // put your 10Hz code here
}
#endif

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

#ifdef USERHOOK_SUPERSLOWLOOP

void Copter::userhook_SuperSlowLoop()
{
    hal.uartE->printf("test");
    hal.uartD->printf("test");

}
#endif

/* setup UART at 57600 ---------------------------------------- */
static void setup_uart(AP_HAL::UARTDriver *uart, const char *name)
{
    if (uart == NULL)
    {
        // that UART doesn't exist on this platform
        return;
    }
    ///begin(baudrate,Rx,Tx)
    uart->begin(57600, 256, 256);
}

But on computer side I cannot see anything. Can anyone help me, is it the correct way? Thank You!

I’d suggested looking at adding some printf to the console to see where you code is getting too

http://ardupilot.org/dev/docs/learning-ardupilot-uarts-and-the-console.html

And review how the board is setup, as you amy have conflict with an already open port

https://github.com/ardupilot/ardupilot/blob/master/libraries/AP_BoardConfig/AP_BoardConfig.cpp#L110

Hope that helps :slight_smile:

Thank You!

Problem SOLVED. It was 3.4 dev version, downloaded 3.3 and it now going fine (I lost 5 hours :frowning: )

I think in 3.4 dev any functions in UserCode.cpp where not called. I dont know why, maybe its a bug?