Hi, I have been using Arduino Mega for a while. Days ago in order to have 64-bit double, I switched to Due. But I found that my old code which works on Mega has error when compiling on Due.
Here's the code:
struct{
byte len; //ength of message
byte id; //meassge identification
unsigned int type; //data type, here type == 2030
byte data_len; //length of data
float f_roll; //value of roll In arduino, float is store in little endian using 4 bytes
float f_pitch;
float f_yaw;
byte cs; //check sum
} msg; //msg struct for the data stream
int data[22]; //array used to store the data, including, msg length, id, type, data length, roll, pitch, yaw and cs
byte * b_roll = (byte *) &msg.f_roll; // pointer for the float value
byte * b_pitch = (byte *) &msg.f_pitch;
byte * b_yaw = (byte *) &msg.f_yaw;
byte old_byte = 0;
byte new_byte = 0;
int index = 2;
int flag = 0;
void serialEvent2(){
}
void setup(){
Serial.begin(115200);
Serial2.begin(115200);
data[0] = 0xFA;
data[1] = 0xFF;
}
void loop(){
if(Serial2.available()){
new_byte = Serial2.read();
if(old_byte == 0xFA && new_byte == 0xFF){
index = 2;
flag = 0;
}
else{
data[index] = new_byte;
index++;
}
if(index > 19){
flag = 1;
}
old_byte = new_byte;
}
if(flag == 1){
b_roll[3] = data[7];
b_roll[2] = data[8];
b_roll[1] = data[9];
b_roll[0] = data[10];
b_pitch[3] = data[11];
b_pitch[2] = data[12];
b_pitch[1] = data[13];
b_pitch[0] = data[14];
b_yaw[3] = data[15];
b_yaw[2] = data[16];
b_yaw[1] = data[17];
b_yaw[0] = data[18];
Serial.print(msg.f_roll);
Serial.print(",");
Serial.print(msg.f_pitch);
Serial.print(",");
Serial.print(msg.f_yaw);
Serial.print("\n");
}
}
It works well on Mega. Basically, it just read data from serial port.
Here's the error message when compiling on Due:
ahars_reading3.ino: In function 'void loop()':
ahars_reading3.ino:37:11: error: assignment of function 'char* index(const char*, int)'
ahars_reading3.ino:37:11: error: cannot convert 'int' to 'char*(const char*, int)' in assignment
ahars_reading3.ino:41:15: error: invalid types 'int [22][char*(const char*, int)]' for array subscript
ahars_reading3.ino:43:10: error: ISO C++ forbids incrementing a pointer of type 'char* (*)(const char*, int)' [-fpermissive]
ahars_reading3.ino:43:10: error: lvalue required as increment operand
ahars_reading3.ino:45:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
Error compiling.
So what's wrong with my code? Is there any other difference when program for Mega and Due?
Thanks in advance.