Hey guys,
I'm working on a senior design project with a group of mechanical engineers. Little bit of unnecessary backstory so you understand. Its a solar panel system mounted onto a bicycle, and it has to turn towards the sun so it has optimum radiation all the time, while riding around also. We're using an IMU and a GPS to orient the system and direct it towards the sun. None of us have much programming knowledge unfortunately. I'm able to get both the IMU and the GPS to send data to the Mega, and can serial print it out to the monitor no problem. The problem arises with the second Mega. We have two, one for a UserInterface system at the base, and the second at the top of the tracker, where it controls the motors and such. The base Mega gets the data from the IMU, and we need to use the serial to send to the second Mega up top. I've got some different codes I've been toying with, from surfing through the different forums.
This is the send code, which takes in the IMU data, prints it out the to the first Mega Serial monitor, and send its through serial to the second Mega.
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
Adafruit_BNO055 bno = Adafruit_BNO055(55);
float x,y,z;
void setup(void)
{
Serial.begin(2400);
Serial2.begin(2400);
Serial.println("Orientation Sensor Test"); Serial.println("");
/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
bno.setExtCrystalUse(true);
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);
x=event.orientation.x;
y=event.orientation.y;
z=event.orientation.z;
Serial.print(x,4);
Serial.print(" ");
Serial.print(y,4);
Serial.print(" ");
Serial.println(z,4);
Serial2.print(x,4);
Serial2.print(y,4);
Serial2.print(z,4);
}
This is the code for the second Mega, which is just supposed to read in the data, and then print it out to a separate Serial monitor.
int i = 0;
float x = 0;
void setup() {
Serial.begin(2400); //Initializes serial monitor
Serial1.begin(2400); //Initializes transfer serial. Include # of serial (Rx Tx) port used
Serial.println("Is this on?..."); //Prints out on serial monitor
}
void loop() {
for(i;i<3;i++){
if (Serial1.available()){
x= Serial1.parseFloat();
Serial.print(x,4);
}
Serial.print(" ");
}
Serial.println("");
i=0;
}
The ultimate desire would be to save it and and be able to use it in calculations to direct the motors. Currently im just trying to prove that I can send it over in real time and get it to print out the same data appropriately.
This mostly works. I can send the data through to the second Mega. However, it seems to me that the processing of all this takes a bit too much time. Sometimes, what was the X data in the first Mega is printed out to the Y data of the second Mega, and Y to Z, and so on. I think its just because of the loop that I'm using to take it in and print it out, but I'm not positive.
Also, it cuts off parts of the data sometimes. It will be 356.1458 in the first Mega, but it prints out 0.1458 in the second Mega. I'm not sure why. I can post some of the data in the second comment to show that I mean.