Hello all, I am having trouble with a hardware change from a H5883 to a 9 axis Arduino motion shield.There is a notation error in the code, but I have looked so long it could be bracketed in neon I don't know if I would see it. Any help is appreciated. Thanks, Quince
#include <Servo.h> #include <Wire.h> #include <I2Cdev.h> #include "Arduino_NineAxesMotion.h" /* Assign a unique ID to this sensor at the same time */ NineAxesMotion mySensor; //Object that for the sensor unsigned long lastStreamTime = 0; //To store the last streamed time stamp const int streamPeriod = 20; Servo servo0; Servo servo1; Servo servo2; int servoValues[3]; int servoPos = 0; // int compassCorrection = 0; // set to 0 (not used) float ypr[3];// [yaw, pitch, roll] yaw/pitch/roll containerint heading= mySensor.readEulerHeading void setup(void) { //Peripheral Initialization Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. //Sensor Initialization mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired mySensor.setUpdateMode(AUTO); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions //Setting to MANUAL requires fewer reads to the sensor servo0.attach (5); servo1.attach(6); servo2.attach(9); pinMode (5, OUTPUT); pinMode (6, OUTPUT); pinMode (9, OUTPUT); ypr[0]; ypr[1]; ypr[2]; #define heading = (ypr[0]); } void loop(void) { /* Get a new sensor event */ mySensor.updateEuler(); //Update the Euler data into the structure of the object mySensor.updateCalibStatus(); //Update the Calibration Status Serial.print("Time: "); // Serial.print(lastStreamTime); //Serial.print("ms "); Serial.print(" H: "); Serial.print(mySensor.readEulerHeading()); //Heading data Serial.print("deg "); Serial.print(" R: "); Serial.print(mySensor.readEulerRoll()); //Roll data Serial.print("deg"); Serial.print(" P: "); Serial.print(mySensor.readEulerPitch()); //Pitch data Serial.print("deg "); Serial.print(" A: "); Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) Serial.print(" M: "); Serial.print(mySensor.readMagCalibStatus()); //Magnetometer Calibration Status (0 - 3) Serial.print(" G: "); Serial.print(mySensor.readGyroCalibStatus()); //Gyroscope Calibration Status (0 - 3) Serial.print(" S: "); Serial.print(mySensor.readSystemCalibStatus()); //System Calibration Status (0 - 3) Serial.println(); // Get Yaw, Pitch and Roll values from the sensor {*5} ypr[0] = (mySensor.readEulerHeading()); //Heading data ypr[1] = (mySensor.readEulerRoll()); //Roll data ypr[2] = (mySensor.readEulerPitch()); //Pitch data } if (ypr[0] - compassCorrection) >= 0); { ypr[0] = (ypr[0] - compassCorrection); } else { ypr[0] = (ypr[0] - compassCorrection + 360); } Serial.print(ypr[0]); Serial.println(ypr[0]; // Calculate corresponding servo position } if (ypr[0] > 90 && ypr[0] < 270) { if (ypr[0], <= 180) { servoPos = 180; } else { servoPos = 10; } } else { if (ypr[0] <= 90) { servoPos = map(ypr[0], 0, 90, 85, 10); } else { servoPos = map(ypr[0], 360, 270, 85, 180); } { servo0.write(servoPos); delay(10); }
Hello all, I am having trouble with a hardware change from a H5883 to a 9 axis Arduino motion shield.There is a notation error in the code, but I have looked so long it could be bracketed in neon I don't know if I would see it. Any help is appreciated. Thanks, Quince
#include <Servo.h> #include <Wire.h> #include <I2Cdev.h> #include "Arduino_NineAxesMotion.h" /* Assign a unique ID to this sensor at the same time */ NineAxesMotion mySensor; //Object that for the sensor unsigned long lastStreamTime = 0; //To store the last streamed time stamp const int streamPeriod = 20; Servo servo0; Servo servo1; Servo servo2; int servoValues[3]; int servoPos = 0; // int compassCorrection = 0; // set to 0 (not used) float ypr[3];// [yaw, pitch, roll] yaw/pitch/roll containerint heading= mySensor.readEulerHeading void setup(void) { //Peripheral Initialization Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. //Sensor Initialization mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired mySensor.setUpdateMode(AUTO); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions //Setting to MANUAL requires fewer reads to the sensor servo0.attach (5); servo1.attach(6); servo2.attach(9); pinMode (5, OUTPUT); pinMode (6, OUTPUT); pinMode (9, OUTPUT); ypr[0]; ypr[1]; ypr[2]; #define heading = (ypr[0]); } void loop(void) { /* Get a new sensor event */ mySensor.updateEuler(); //Update the Euler data into the structure of the object mySensor.updateCalibStatus(); //Update the Calibration Status Serial.print("Time: "); // Serial.print(lastStreamTime); //Serial.print("ms "); Serial.print(" H: "); Serial.print(mySensor.readEulerHeading()); //Heading data Serial.print("deg "); Serial.print(" R: "); Serial.print(mySensor.readEulerRoll()); //Roll data Serial.print("deg"); Serial.print(" P: "); Serial.print(mySensor.readEulerPitch()); //Pitch data Serial.print("deg "); Serial.print(" A: "); Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) Serial.print(" M: "); Serial.print(mySensor.readMagCalibStatus()); //Magnetometer Calibration Status (0 - 3) Serial.print(" G: "); Serial.print(mySensor.readGyroCalibStatus()); //Gyroscope Calibration Status (0 - 3) Serial.print(" S: "); Serial.print(mySensor.readSystemCalibStatus()); //System Calibration Status (0 - 3) Serial.println(); // Get Yaw, Pitch and Roll values from the sensor {*5} ypr[0] = (mySensor.readEulerHeading()); //Heading data ypr[1] = (mySensor.readEulerRoll()); //Roll data ypr[2] = (mySensor.readEulerPitch()); //Pitch data } if (ypr[0] - compassCorrection) >= 0); { ypr[0] = (ypr[0] - compassCorrection); } else { ypr[0] = (ypr[0] - compassCorrection + 360); } Serial.print(ypr[0]); Serial.println(ypr[0]; // Calculate corresponding servo position } if (ypr[0] > 90 && ypr[0] < 270) { if (ypr[0], <= 180) { servoPos = 180; } else { servoPos = 10; } } else { if (ypr[0] <= 90) { servoPos = map(ypr[0], 0, 90, 85, 10); } else { servoPos = map(ypr[0], 360, 270, 85, 180); } { servo0.write(servoPos); delay(10); }
Hi @quince, Look at line
float ypr[3];// [yaw, pitch, roll] yaw/pitch/roll containerint heading= mySensor.readEulerHeading
Is the part containerint heading= mySensor.readEulerHeading suppose to be commented?
regards,
LouisR
LouisR
Just for S&G, I pasted your code into the compiler. But I don't have the libraries your code needs and I don't want to download them just to help out with an error that you could easily just copy and paste into a post. You might actually get an answer that way.
Another suggestion would be to use proper indentions for every sub section and line up the matching curly braces in the same columns. That is an old professional coder's best advice - NEATNESS COUNTS!
Another option - If you place the cursor of the Arduino editor on a curly brace it will "box" the matching mate. If you put the cursor on the opening curly brace after your loop method (line 44), you'll see the mate is on line 82! All code after that is flapping in the wind and not part of any function.
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide
@inst-tech @quince I see the following errors (start corrections at highest line #'s so as to not modify following line #'s
Line 118 s/b }
Line 99 if (ypr[0], <= 180) remove the ,
Line 96 appears to be simply extra. Remove it
Lines 92 and 93, one is extra and 93 is missing )
Line 83 if (ypr[0] - compassCorrection) >= 0); is missing ( after if and has extra ; at end
if ((ypr[0] - compassCorrection) >= 0) // <<< correct
Line 82 is the end of the sketch. Remove that line?
Besides line 18 being suspicious, the #define at 41 relates to it and is a one of. The lines 38, 39, and 40 make no sense.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Ron, been working on changing and combining code. Blind at this point. I will give your suggestions a try and cross my fingers. Thanks, Quince
@quince See my complete post at Here I made all those changes and it does compile. I did nothing re 18 and 38 to 41 as they compile clean but are suspicious looking.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
I am sorry for not posting the error message. Quince
Arduino: 1.8.16 (Windows 7), Board: "Arduino Uno" In file included from C:\Users\James\Documents\Arduino\compass_mod_6-6__1\compass_mod_6-6__1.ino:7:0: C:\Users\James\Documents\Arduino\libraries\Arduino_NineAxesMotion-master\src/Arduino_NineAxesMotion.h:766:8: warning: extra tokens at end of #endif directive [-Wendif-labels] #endif __NAXISMOTION_H__ ^~~~~~~~~~~~~~~~~ compass_mod_6-6__1:86:1: error: expected unqualified-id before 'if' if (ypr[0] - compassCorrection) >= 0); ^~ compass_mod_6-6__1:87:1: error: expected unqualified-id before '{' token { ^ compass_mod_6-6__1:90:1: error: expected unqualified-id before 'else' else ^~~~ compass_mod_6-6__1:95:1: error: 'Serial' does not name a type Serial.println(ypr[0]; ^~~~~~ compass_mod_6-6__1:98:1: error: expected declaration before '}' token } ^ exit status 1 expected unqualified-id before 'if' This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
@zander Ron, Did you post the code with changes made? I see the changes when I press here and am still working on it. If you have the code compiled Please send it. Thanks, Quince
@quince Ok, here is the modified code except for 18 and 38 to 41, I don't know what you were doing there, it compiles clean but is suspicious. I have attached a zip file of the clean code.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@quince Notice how the compiler gave you a HINT about modifying your preferences to get better compiler diagnostics! ALWAYS obey the compiler gods! This is what you posted above under 'I am sorry for not posting the error message.'
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@quince Note the following from arduino. I personally never use #define.
Here is the arduino ref pg Arduino Reference manual page
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.