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(c); // 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.
Replies