I am creating a custom flight mode on the Pixhawk for a quadcopter, and I need to read in a value from Telem2 (UART D). I’m not a great C++ programmer, so much of my work is based on existing code (mostly Loiter). My problem is that I cannot find any example of reading in values from the Telem pins using UART. According to dev.ardupilot, there should be a ‘read byte from UART’ function, but I can’t find it in any libraries like AP_HAL. I’ve googled stuff like ‘reading UART c++’, but it seems like most people are using functions from libraries on whatever device they are using.
If anyone has any input about how I can read in UART bytes, I would really appreciate it.
Just for reference; what I’m doing so far is based off of the UART test example
// setup the UART
static void setup_uart(AP_HAL::UARTDriver *uart, const char *name)
{
if (uart == NULL) {
// that UART doesn't exist on this platform
return;
}
uart->begin(57600);
}
setup_uart(hal.uartD, "uartD"); // telemetry 2 at 57600 with default buffer sizes
int read_uart(AP_HAL::UARTDriver *uart, const char *name)
{
if (uart == NULL) {
// that UART doesn't exist on this platform
return;
}
uart->read();//Here is where I need to figure out how to read from this uart object
}
[b]Hi,
i’m working on a serial wireless connection between copters and my programming skills are not deep.
But i found out that yout can use the uart read function like this…
the read() function reads only 1 character!!!
so you make like this(here in a 50hz user hook)[/b]
static int pos;
static char buf[8];
char ch = 1; // here i had to give him a start value, don’t know exactly why
/* maybe it works with: char ch[1]; */
ch = hal.uartC->read(); // reads a character coming from uart…
buf[pos++] = ch;
if(pos >= 7)
pos = 0;
[quote=“mondare”][b]Hi,
i’m working on a serial wireless connection between copters and my programming skills are not deep.
But i found out that yout can use the uart read function like this…
the read() function reads only 1 character!!!
so you make like this(here in a 50hz user hook)[/b]
static int pos;
static char buf[8];
char ch = 1; // here i had to give him a start value, don’t know exactly why
/* maybe it works with: char ch[1]; */
ch = hal.uartC->read(); // reads a character coming from uart…
buf[pos++] = ch;
if(pos >= 7)
pos = 0;[/quote
I’d love to hear an update on linking.