Servers by jDrones

Data transfer from ARDUINO to PIXHAWK through serial or I2C


(Xenopoulos) #1

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.


How to connect Arduino and Pixhawk together?
(ppoirier) #2

Are you trying to send gps coordinates to the FC?


(Xenopoulos) #3

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.


(ppoirier) #4

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


(Xenopoulos) #5

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


(ppoirier) #6

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.


(Xenopoulos) #7

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