Data transfer from ARDUINO to PIXHAWK through serial or I2C

Dear all

I need your help in the following simple(?) issue: I have connected through I2C two ARDUINOs (a master MEGA and a slave NANO). Using the following code they communicate correctly:
For the master:

#include <Wire.h>
String msg = String("");
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(10, 27); // request n=27 bytes from slave device #10
while (Wire.available())
{
char c = Wire.read(); // receive a byte as character
Serial.print©; // print the character
}
delay(1000);
Wire.end();
}

And for the slave:
#include <Wire.h>
void setup()
{
Wire.begin(10); // join i2c bus with address #10
Wire.onRequest(requestEvent); // register event
}
void loop()
{
delay(1000);
}
// function that executes whenever data is requested by master
void requestEvent() // this function is registered as an even
{
Wire.write("41.439234,24.712345,67.25; "); // respond with message of n bytes
}

I must replace the master ARDUINO MEGA with the PIXHAWK flight controller of a hexa and read the above message "41.139234,24.912345,67.25;” through one of its serial ports (UART or I2C).

Could you please suggest me which is the easier solution:

  1. to use MAVLINK lib in ARDUINO NANO and to communicate through Telem2 for example to Pixhawk, or
  2. Is it possible to write a Python code through MP in order to communicate through I2C from Pixhawk to ARDUINO?
    In this case must I modify the above C++ code for slave or not? I use python scripting through Mission Planner to control the hexa.

Thanking you in advance.

Are you trying to send gps coordinates to the FC?

Yes, but those GPS data are not coming from a GPS onboard, but from a remote GPS of another moving object. Actually the configuration is as follows:
(GPS1+ArduinoLeonardo+RF link) —> (RF Link+ArduinoNANO) —> (Pixhawk+GPS2+UAV) —> GroundControlStation
In the moving object the ArduinoLeonardo receives data from GPS1 and after parsing them transmits the useful data via RF link to the UAV in the form: (ID,Lat,Long,Alt,TimeData, e.t.c.); (about 60 Bytes)
The onboard ArduinoNANO receives the above sentence and it can parse it or not. Our problem is to “Read” the above sentence (as a string, or as separate values) from the Ground Control Station computer (PC+Windows7+MP). We are using Python scripting code inside the MP to achieve fully autonomous flight of the UAV and the problem is to read the above sentence througth the Python code controlling the UAV.

Maybe you could consider using drone kit http://python.dronekit.io/examples/follow_me.html.

That would require a Raspberry Pi Zero onboard (Instead of the Arduino Nano) in order to process the remote GPS via Mavlink

Dear ppoirier
thank you very much for your prompt response! Indeed, this would be a great idea, if we were using dronekit from the beginning and the total system was build around it. However, we have already now build our system based on the architecture described in my previous post (MP python scripting in a Windows Computer) and since I haven’t used dronekit yet I don’t know its requirements and capabilities. I am afraid that we must re-design the control system from the beginning. It is very difficult to change it now, since it is depended and from other subsystems not described in the above.
So my first question is: is it possible to use it (dronekit) through Python scripting in MP with our configuration) and to access the data transmitted by the remote GPS, using the proposed RPi Zero onboard?
Since, to my understanding the problem is in the communication of the Arduino to Pixhawk, should it be bypassed using the #include “mavlink.h” library in the arduino code and using Mavlink commands to communicate with the Pixhawk? In this case is it possible to access the data from the Pixhawk through our code or not?
Thank you again

I have used with success MavLink on Arduino here:
https://discuss.ardupilot.org/t/avoidance-experiments-with-the-poc-and-benewake-tfmini/25277

You should read this good informative blog here as well:
https://discuss.ardupilot.org/t/mavlink-and-arduino-step-by-step/25566
and ask questions to the autor.

Dear ppoirier
thank you so much for your response. I will exlore it and let you know
Best regards

Hi,
Can I transfer data from flight controller to another mcu using serial port but did not using mavlink?
For example, I’d like to transfer rpm from flight controller to another mcu,
hal.uartE->printf(rpm);
is it right? Thanks
Sincerely

It could be possible but it is not recommended because this could break the timing of control loop if it is not implemented properly.

Hi, is there a tutorial about how to implement it? I found that I changed the serial_protocol and using hal.uartE->printf(), but I did not get any date in the serial debug assistant! Thanks

You can refer to the developers wiki or ask for guidance on ardupilot gitter

I found this tutorial
http://ardupilot.org/dev/docs/learning-ardupilot-uarts-and-the-console.html

Hi,
hal.uartB->begin(57600); and
hal.uartB->write(10);
worked, thanks

1 Like

Hey, can you help me? I try to make a Telemetry with Lora and STM32

Hello,

LORA can be interfaced as a regular serial radio so it is directly configurable with the existing hardware.

Hey ppoirier, thanks for answers !

But I didn’t understand, do you know an Example? I think to make this telemetry with a STM32 and a Lora or a Heltec Esp32 Lora

I suggest you look at what is already available and if you require traditional support , open a new discussion as this one is not related to your question.

Regrds

Hi,
I am currently working on connecting an arduino uno with several magnetometers to a pixhawk 2.1 as an external magnetometer through I2C. Is this possible? I am greatful for all tips I can get.