Hello all, I need enlightenment again. I am working on modifying a program the uses the eventually library for Arduino. I have seen this message where commands do not work,but I don't know why. This setup compiles on a different program, perfectly. My guess is that I have made another in a long line of notation errors. Thanks, Quince
Arduino: 1.8.16 (Windows 7), Board: "Arduino Uno" sketch_jun21c error: 'Serial' does not name a type Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor ^~~~~~ sketch_jun21c error: 'Wire' does not name a type Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. ^~~~ sketch_jun21c error: 'mySensor' does not name a type mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library ^~~~~~~~ sketch_jun21c error: 'mySensor' does not name a type mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired ^~~~~~~~ sketch_jun21c error: 'mySensor' does not name a type mySensor.setUpdateMode(AUTO); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions ^~~~~~~~ sketch_jun21c error: 'servo0' does not name a type servo0.attach (5); ^~~~~~ sketch_jun21c error: 'servo1' does not name a type servo1.attach(6); ^~~~~~ sketch_jun21c error: 'servo2' does not name a type servo2.attach(9); ^~~~~~ sketch_jun21c error: expected constructor, destructor, or type conversion before '(' token pinMode (5, OUTPUT); ^ sketch_jun21c error: expected constructor, destructor, or type conversion before '(' token pinMode (6, OUTPUT); ^ sketch_jun21c error: expected constructor, destructor, or type conversion before '(' token pinMode (9, OUTPUT); ^ sketch_jun21c error: 'ypr' does not name a type ypr[0]; ^~~ sketch_jun21c error: 'ypr' does not name a type ypr[1]; ^~~ sketch_jun21c error: 'ypr' does not name a type ypr[2]; ^~~ sketch_jun21c error: expected declaration before '}' token } ^ exit status 1 'Serial' does not name a type This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
Will not complie
#include <Eventually.h> EvtManager mgr; #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) { // 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 } //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]; int heading = (ypr[0]); } //USE_EVENTUALLY_LOOP(mgr) {
Will compile
#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]; int 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 heading is greater than 90 and less that270 if (ypr[0] > 90 && ypr[0] < 270) { // ir heading is less than or equal to 180 if (ypr[0] <= 180) { //servo position 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); } } delay(10); }
Hi Quince,
The first thing I can see is the line
//Peripheral Initialization
and the following 17 or so lines in your 'will not compile" listing are not inside a function .. and hence this code is floating in the middle of nowhere.
The same lines in the "Will compile" are inside function "setup" .. and hence have a 'home'.
In your "Will not compile", the function setup 's final closing "}" bracket is just before the comment line I quoted.
----
You may be wondering how the first 15 or so lines of "Will Compile" are happily outside of a function ... the reason is they are are all declaring something .. i.e. telling the compiler about variables and so on, but they are not part of the program 'doing something' code ...
Think of a cooking recipe ... It may list stuff like ingredients .. but the instructions to mix, whisk, bake etc are normally in a list of 'how to do it.
If the recipe interleaved the list of ingredients with the 'how to do it' instructions, it would be very confusing. Similarly the compiler expects the 'doing' code to be wrapped in a one of the functions ... but it doesn't mind you defining variables, etc outside of a function.
---
And the lines ypr[0]; to ypr[2]; will compile, but do nothing useful.
Best wishes, Dave
In the Arduino IDE as well as many editors... placing the cursor on a curly brace will highlight the matching brace. Placing on the one after setup() or loop() will show you the ending one. If code is outside these ending braces... it will ruin your whole day. 😉
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, Access Point 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
INQ, Thanks i'll take a look. Quince
@quince Maybe if you tell us how many times have you read your personal dog eared copy of K&R we might have an idea of your knowledge. If you have to ask what K&R is then good luck.
It is considered poor judgement to traverse a chasm in 2 leaps.
Thank you all I have the answer, Quince